/[path-sandbox]/trunk/libsbutil/sb_write.c
Gentoo

Contents of /trunk/libsbutil/sb_write.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 370 - (show annotations) (download) (as text)
Sun Nov 9 10:29:58 2008 UTC (6 years, 9 months ago) by vapier
File MIME type: text/x-csrc
File size: 723 byte(s)
consolidate all random system includes into headers.h
1 /*
2 * sb_write.c
3 *
4 * IO functions.
5 *
6 * Copyright 1999-2008 Gentoo Foundation
7 * Licensed under the GPL-2
8 */
9
10 #include "headers.h"
11 #include "sbutil.h"
12
13 /* General purpose function to _reliably_ write to a file
14 *
15 * If returned value is less than count, there was a fatal
16 * error and value tells how many bytes were actually written
17 */
18
19 size_t sb_write(int fd, const void *buf, size_t count)
20 {
21 ssize_t n;
22 size_t accum = 0;
23
24 do {
25 n = write(fd, buf + accum, count - accum);
26 if (n < 0) {
27 if (EINTR == errno) {
28 /* Reset errno to not trigger DBG_MSG */
29 errno = 0;
30 continue;
31 }
32
33 DBG_MSG("Failed to write to fd=%i!\n", fd);
34 break;
35 }
36
37 accum += n;
38 } while (accum < count);
39
40 return accum;
41 }

  ViewVC Help
Powered by ViewVC 1.1.20