11 #include "gcc-compat.h"
16 * Call a function for each subdirectory of the current working directory.
18 * \param dirname The directory to traverse.
19 * \param func The function to call for each subdirecrtory.
20 * \param private_data Pointer to an arbitrary data structure.
22 * For each top-level directory under \a dirname, the supplied function \a func is
23 * called. The full path of the subdirectory and the \a private_data pointer
24 * are passed to \a func.
26 * \return This function returns immediately if \a func returned a negative
27 * value. In this case \a func must set error_txt and this negative value is
28 * returned to the caller. Otherwise the function returns when all
29 * subdirectories have been passed to \a func.
32 int for_each_subdir(int (*func)(const char *, void *), void *private_data)
36 DIR *dir = opendir(".");
39 return -ERRNO_TO_DSS_ERROR(errno);
40 while ((entry = readdir(dir))) {
44 if (!strcmp(entry->d_name, "."))
46 if (!strcmp(entry->d_name, ".."))
48 ret = lstat(entry->d_name, &s) == -1;
50 ret = -ERRNO_TO_DSS_ERROR(errno);
56 ret = func(entry->d_name, private_data);
66 * Wrapper for chdir(2).
68 * \param path The specified directory.
72 int dss_chdir(const char *path)
76 return -ERRNO_TO_DSS_ERROR(errno);
80 * Set a file descriptor to non-blocking mode.
82 * \param fd The file descriptor.
86 __must_check int mark_fd_nonblocking(int fd)
88 int flags = fcntl(fd, F_GETFL);
90 return -ERRNO_TO_DSS_ERROR(errno);
91 flags = fcntl(fd, F_SETFL, ((long)flags) | O_NONBLOCK);
93 return -ERRNO_TO_DSS_ERROR(errno);
98 * dss' wrapper for select(2).
100 * It calls select(2) (with no exceptfds) and starts over if select() was
101 * interrupted by a signal.
103 * \param n The highest-numbered descriptor in any of the two sets, plus 1.
104 * \param readfds fds that should be checked for readability.
105 * \param writefds fds that should be checked for writablility.
106 * \param timeout_tv upper bound on the amount of time elapsed before select()
109 * \return The return value of the underlying select() call on success, the
110 * negative system error code on errors.
112 * All arguments are passed verbatim to select(2).
113 * \sa select(2) select_tut(2).
115 int dss_select(int n, fd_set *readfds, fd_set *writefds,
116 struct timeval *timeout_tv)
120 ret = select(n, readfds, writefds, NULL, timeout_tv);
122 } while (ret < 0 && err == EINTR);
124 return -ERRNO_TO_DSS_ERROR(errno);