X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=d3dacfcfb5300b0d55eb439273c277f2f7c0f0a5;hp=9b67dd8296fde6fab7ae3b862bf7ce63fc21e015;hb=6ec9b87c4ecf5144b5ea845a53a352dd9f2d173a;hpb=f0b159f2e7b4ac8a75997834d240459f5436d36e diff --git a/src/shared/util.c b/src/shared/util.c index 9b67dd829..d3dacfcfb 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1665,7 +1665,7 @@ int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) { errno = 0; - while (nbytes > 0) { + do { ssize_t k; k = write(fd, p, nbytes); @@ -1685,12 +1685,12 @@ int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) { return -errno; } - if (k == 0) /* Can't really happen */ + if (nbytes > 0 && k == 0) /* Can't really happen */ return -EIO; p += k; nbytes -= k; - } + } while (nbytes > 0); return 0; } @@ -5436,6 +5436,15 @@ int is_dir(const char* path, bool follow) { return !!S_ISDIR(st.st_mode); } +int is_device_node(const char *path) { + struct stat info; + + if (lstat(path, &info) < 0) + return -errno; + + return !!(S_ISBLK(info.st_mode) || S_ISCHR(info.st_mode)); +} + int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) { _cleanup_free_ char *s = NULL; size_t allocated = 0, sz = 0;