summaryrefslogtreecommitdiffstats
path: root/lib/full-write.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-01-24 22:47:25 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2007-01-24 22:47:25 +0000
commitfe856aa957978504137c1d425815d4ed8a22be40 (patch)
treea5bb46ce0e64b2056f75700eadbf27aba7c39418 /lib/full-write.c
parent210f39bc84cfbb21cd72dc054e43f13815ee0616 (diff)
downloadmonitoring-plugins-fe856aa957978504137c1d425815d4ed8a22be40.tar.gz
Sync with gnulib - lots of extraneous code removed in preference to GNU code
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1580 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/full-write.c')
-rw-r--r--lib/full-write.c83
1 files changed, 0 insertions, 83 deletions
diff --git a/lib/full-write.c b/lib/full-write.c
deleted file mode 100644
index 106f3c7e..00000000
--- a/lib/full-write.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* An interface to read and write that retries (if necessary) until complete.
2
3 Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24/* Specification. */
25#ifdef FULL_READ
26# include "full-read.h"
27#else
28# include "full-write.h"
29#endif
30
31#include <errno.h>
32
33#ifdef FULL_READ
34# include "safe-read.h"
35# define safe_rw safe_read
36# define full_rw full_read
37# undef const
38# define const /* empty */
39#else
40# include "safe-write.h"
41# define safe_rw safe_write
42# define full_rw full_write
43#endif
44
45#ifdef FULL_READ
46/* Set errno to zero upon EOF. */
47# define ZERO_BYTE_TRANSFER_ERRNO 0
48#else
49/* Some buggy drivers return 0 when one tries to write beyond
50 a device's end. (Example: Linux 1.2.13 on /dev/fd0.)
51 Set errno to ENOSPC so they get a sensible diagnostic. */
52# define ZERO_BYTE_TRANSFER_ERRNO ENOSPC
53#endif
54
55/* Write(read) COUNT bytes at BUF to(from) descriptor FD, retrying if
56 interrupted or if a partial write(read) occurs. Return the number
57 of bytes transferred.
58 When writing, set errno if fewer than COUNT bytes are written.
59 When reading, if fewer than COUNT bytes are read, you must examine
60 errno to distinguish failure from EOF (errno == 0). */
61size_t
62full_rw (int fd, const void *buf, size_t count)
63{
64 size_t total = 0;
65 const char *ptr = buf;
66
67 while (count > 0)
68 {
69 size_t n_rw = safe_rw (fd, ptr, count);
70 if (n_rw == (size_t) -1)
71 break;
72 if (n_rw == 0)
73 {
74 errno = ZERO_BYTE_TRANSFER_ERRNO;
75 break;
76 }
77 total += n_rw;
78 ptr += n_rw;
79 count -= n_rw;
80 }
81
82 return total;
83}