Example: OpenSSH cvs-20051008

atomicio.c
35| size_t
36| atomicio(f, fd, _s, n)
37|         ssize_t (*f) (int, void *, size_t);
38|         int fd;
39|         void *_s;
40|         size_t n;
41| {
42|         char *s = _s;
43|         size_t pos = 0;
44|         ssize_t res;
45|
46|         while (n > pos) {
47|                 res = (f) (fd, s + pos, n - pos);
48|                 switch (res) {
49|                 case -1:
50|                         if (errno == EINTR || errno == EAGAIN)
51|                                 continue;
52|                         return 0;
53|                 case 0:
54|                         errno = EPIPE;
55|                         return pos;
56|                 default:
57|                         pos += (u_int)res;
58|                 }
59|         }
60|         return (pos);
61| }
