]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/all-io.h
2 * No copyright is claimed. This code is in the public domain; do with
5 * Written by Karel Zak <kzak@redhat.com>
6 * Petr Uzel <petr.uzel@suse.cz>
9 #ifndef UTIL_LINUX_ALL_IO_H
10 #define UTIL_LINUX_ALL_IO_H
18 static inline int write_all(int fd
, const void *buf
, size_t count
)
24 tmp
= write(fd
, buf
, count
);
28 buf
= (const void *) ((const char *) buf
+ tmp
);
29 } else if (errno
!= EINTR
&& errno
!= EAGAIN
)
31 if (errno
== EAGAIN
) /* Try later, *sigh* */
37 static inline int fwrite_all(const void *ptr
, size_t size
,
38 size_t nmemb
, FILE *stream
)
44 tmp
= fwrite(ptr
, size
, nmemb
, stream
);
48 ptr
= (const void *) ((const char *) ptr
+ (tmp
* size
));
49 } else if (errno
!= EINTR
&& errno
!= EAGAIN
)
51 if (errno
== EAGAIN
) /* Try later, *sigh* */
57 static inline ssize_t
read_all(int fd
, char *buf
, size_t count
)
63 memset(buf
, 0, count
);
65 ret
= read(fd
, buf
, count
);
67 if (ret
< 0 && (errno
== EAGAIN
|| errno
== EINTR
) && (tries
++ < 5)) {
81 #endif /* UTIL_LINUX_ALL_IO_H */