X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=blobdiff_plain;f=fd.c;h=7b23df223396959728b7064d4088c2d69233dd68;hp=db0433fd180e522160b6592fc1fd573f8e1c267a;hb=7903078ffd5e494479b4c7a1d9881233a4acf67f;hpb=c418d2188c9c2c542270023d6fc3bc6cf34f8d29 diff --git a/fd.c b/fd.c index db0433f..7b23df2 100644 --- a/fd.c +++ b/fd.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2006-2008 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ + #include #include #include @@ -35,11 +41,8 @@ int for_each_subdir(int (*func)(const char *, void *), void *private_data) int ret; DIR *dir = opendir("."); - if (!dir) { - ret = -ERRNO_TO_DSS_ERROR(errno); - make_err_msg("opendir(\".\") failed"); - return ret; - } + if (!dir) + return -ERRNO_TO_DSS_ERROR(errno); while ((entry = readdir(dir))) { mode_t m; struct stat s; @@ -51,7 +54,6 @@ int for_each_subdir(int (*func)(const char *, void *), void *private_data) ret = lstat(entry->d_name, &s) == -1; if (ret == -1) { ret = -ERRNO_TO_DSS_ERROR(errno); - make_err_msg("lstat(\"%s\") failed", entry->d_name); goto out; } m = s.st_mode; @@ -75,13 +77,9 @@ out: */ int dss_chdir(const char *path) { - int ret = chdir(path); - - if (ret >= 0) + if (chdir(path) >= 0) return 1; - ret = -ERRNO_TO_DSS_ERROR(errno); - make_err_msg("chdir to %s failed", path); - return ret; + return -ERRNO_TO_DSS_ERROR(errno); } /** @@ -102,3 +100,33 @@ __must_check int mark_fd_nonblocking(int fd) return 1; } +/** + * dss' wrapper for select(2). + * + * It calls select(2) (with no exceptfds) and starts over if select() was + * interrupted by a signal. + * + * \param n The highest-numbered descriptor in any of the two sets, plus 1. + * \param readfds fds that should be checked for readability. + * \param writefds fds that should be checked for writablility. + * \param timeout_tv upper bound on the amount of time elapsed before select() + * returns. + * + * \return The return value of the underlying select() call on success, the + * negative system error code on errors. + * + * All arguments are passed verbatim to select(2). + * \sa select(2) select_tut(2). + */ +int dss_select(int n, fd_set *readfds, fd_set *writefds, + struct timeval *timeout_tv) +{ + int ret, err; + do { + ret = select(n, readfds, writefds, NULL, timeout_tv); + err = errno; + } while (ret < 0 && err == EINTR); + if (ret < 0) + return -ERRNO_TO_DSS_ERROR(errno); + return ret; +}