~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to include/writeall.h

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
static inline int write_all(int fd, const void *buf, size_t count)
9
9
{
10
 
        while(count) {
 
10
        while (count) {
11
11
                ssize_t tmp;
12
12
 
13
13
                errno = 0;
18
18
                                buf += tmp;
19
19
                } else if (errno != EINTR && errno != EAGAIN)
20
20
                        return -1;
 
21
                if (errno == EAGAIN)    /* Try later, *sigh* */
 
22
                        usleep(10000);
 
23
        }
 
24
        return 0;
 
25
}
 
26
 
 
27
static inline int fwrite_all(const void *ptr, size_t size,
 
28
                             size_t nmemb, FILE *stream)
 
29
{
 
30
        while (nmemb) {
 
31
                size_t tmp;
 
32
 
 
33
                errno = 0;
 
34
                tmp = fwrite(ptr, size, nmemb, stream);
 
35
                if (tmp > 0) {
 
36
                        nmemb -= tmp;
 
37
                        if (nmemb)
 
38
                                ptr += (tmp * size);
 
39
                } else if (errno != EINTR && errno != EAGAIN)
 
40
                        return -1;
 
41
                if (errno == EAGAIN)    /* Try later, *sigh* */
 
42
                        usleep(10000);
21
43
        }
22
44
        return 0;
23
45
}