~ubuntu-branches/ubuntu/intrepid/parted/intrepid

« back to all changes in this revision

Viewing changes to gnulib/lib/full-write.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-06-24 14:31:05 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080624143105-rd7yw67a9qnvh51i
Tags: 1.8.8.git.2008.03.24-7ubuntu1
* Resynchronise with Debian (LP: #237568). Remaining changes:
  - swap-uuid.dpatch: Create UUIDs on new swap partitions.
  - gptsync.dpatch: On Intel Mac systems, write a synced MBR rather than a
    protective MBR.
  - Add -fno-stack-protector on sparc.
  - sparc-new-label.dpatch: Fix sparc disk label generation. This is
    required for LDOM and parallel installations with Solaris 10.
  - loop-partitions.dpatch: Loop devices can only have one partition, so
    don't generate device names such as "/dev/loop0p1".
  - unpartitioned-disks.dpatch: Don't try to call BLKPG ioctls on
    unpartitionable disks (only implemented for loop devices at the
    moment), as they will always fail.
  - When building with gcc-4.3, add -Wno-array-bounds to CFLAGS.
  - Cell partition tables are misdetected as pc98, so disable pc98 support
    on powerpc.
  - array-bounds.dpatch: Backport patch from git to allow building with
    gcc-4.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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, 2005, 2006 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
#include <config.h>
 
21
 
 
22
/* Specification.  */
 
23
#ifdef FULL_READ
 
24
# include "full-read.h"
 
25
#else
 
26
# include "full-write.h"
 
27
#endif
 
28
 
 
29
#include <errno.h>
 
30
 
 
31
#ifdef FULL_READ
 
32
# include "safe-read.h"
 
33
# define safe_rw safe_read
 
34
# define full_rw full_read
 
35
# undef const
 
36
# define const /* empty */
 
37
#else
 
38
# include "safe-write.h"
 
39
# define safe_rw safe_write
 
40
# define full_rw full_write
 
41
#endif
 
42
 
 
43
#ifdef FULL_READ
 
44
/* Set errno to zero upon EOF.  */
 
45
# define ZERO_BYTE_TRANSFER_ERRNO 0
 
46
#else
 
47
/* Some buggy drivers return 0 when one tries to write beyond
 
48
   a device's end.  (Example: Linux 1.2.13 on /dev/fd0.)
 
49
   Set errno to ENOSPC so they get a sensible diagnostic.  */
 
50
# define ZERO_BYTE_TRANSFER_ERRNO ENOSPC
 
51
#endif
 
52
 
 
53
/* Write(read) COUNT bytes at BUF to(from) descriptor FD, retrying if
 
54
   interrupted or if a partial write(read) occurs.  Return the number
 
55
   of bytes transferred.
 
56
   When writing, set errno if fewer than COUNT bytes are written.
 
57
   When reading, if fewer than COUNT bytes are read, you must examine
 
58
   errno to distinguish failure from EOF (errno == 0).  */
 
59
size_t
 
60
full_rw (int fd, const void *buf, size_t count)
 
61
{
 
62
  size_t total = 0;
 
63
  const char *ptr = (const char *) buf;
 
64
 
 
65
  while (count > 0)
 
66
    {
 
67
      size_t n_rw = safe_rw (fd, ptr, count);
 
68
      if (n_rw == (size_t) -1)
 
69
        break;
 
70
      if (n_rw == 0)
 
71
        {
 
72
          errno = ZERO_BYTE_TRANSFER_ERRNO;
 
73
          break;
 
74
        }
 
75
      total += n_rw;
 
76
      ptr += n_rw;
 
77
      count -= n_rw;
 
78
    }
 
79
 
 
80
  return total;
 
81
}