1994-01-26 18:20:04 +00:00
|
|
|
/* full-write.c -- an interface to write that retries after interrupts
|
1994-07-01 18:42:52 +00:00
|
|
|
Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
1993-12-29 06:13:37 +00:00
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
1996-07-14 12:35:45 +00:00
|
|
|
along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1993-12-29 06:13:37 +00:00
|
|
|
|
|
|
|
|
Copied largely from GNU C's cccp.c.
|
|
|
|
|
*/
|
|
|
|
|
|
1996-10-09 02:35:23 +00:00
|
|
|
#if HAVE_CONFIG_H
|
1996-07-14 12:35:45 +00:00
|
|
|
# include <config.h>
|
1993-12-29 06:13:37 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
1996-10-09 02:35:23 +00:00
|
|
|
#if HAVE_UNISTD_H
|
1996-07-14 12:35:45 +00:00
|
|
|
# include <unistd.h>
|
1993-12-29 06:13:37 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
1995-01-27 15:35:17 +00:00
|
|
|
#ifndef errno
|
1993-12-29 06:13:37 +00:00
|
|
|
extern int errno;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Write LEN bytes at PTR to descriptor DESC, retrying if interrupted.
|
1996-02-27 03:57:49 +00:00
|
|
|
Return LEN upon success, write's (negative) error code otherwise. */
|
1993-12-29 06:13:37 +00:00
|
|
|
|
|
|
|
|
int
|
1993-12-29 06:16:08 +00:00
|
|
|
full_write (desc, ptr, len)
|
1993-12-29 06:13:37 +00:00
|
|
|
int desc;
|
|
|
|
|
char *ptr;
|
1994-10-02 05:43:03 +00:00
|
|
|
size_t len;
|
1993-12-29 06:13:37 +00:00
|
|
|
{
|
1994-01-26 18:20:04 +00:00
|
|
|
int total_written;
|
|
|
|
|
|
|
|
|
|
total_written = 0;
|
1993-12-29 06:13:37 +00:00
|
|
|
while (len > 0)
|
|
|
|
|
{
|
|
|
|
|
int written = write (desc, ptr, len);
|
|
|
|
|
if (written < 0)
|
|
|
|
|
{
|
|
|
|
|
#ifdef EINTR
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
#endif
|
|
|
|
|
return written;
|
|
|
|
|
}
|
1994-01-26 18:20:04 +00:00
|
|
|
total_written += written;
|
1993-12-29 06:13:37 +00:00
|
|
|
ptr += written;
|
|
|
|
|
len -= written;
|
|
|
|
|
}
|
1994-01-26 18:20:04 +00:00
|
|
|
return total_written;
|
1993-12-29 06:13:37 +00:00
|
|
|
}
|