summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-01-26 18:40:49 +0000
committerJim Meyering <jim@meyering.net>1994-01-26 18:40:49 +0000
commitc56261a766f293c4d8e7cf962a72d4f926ed6d5f (patch)
treeb5d220d9f0ffa008eea0ca1fe2ab654088371198
parentc350c27c3d97d079eca9f69f459162ced842031b (diff)
downloadgnulib-c56261a766f293c4d8e7cf962a72d4f926ed6d5f.tar.gz
GNU file utilitiesFILEUTILS-3_9c
-rw-r--r--lib/Makefile.in10
-rw-r--r--lib/filemode.c8
-rw-r--r--lib/full-write.c71
-rw-r--r--lib/safe-read.c66
4 files changed, 148 insertions, 7 deletions
diff --git a/lib/Makefile.in b/lib/Makefile.in
index d80dee4f4e..c08ed462b3 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -33,18 +33,18 @@ libdir = $(exec_prefix)/lib
SOURCES = getdate.y posixtm.y \
argmatch.c backupfile.c basename.c dirname.c eaccess.c \
-error.c filemode.c fsusage.c getopt.c getopt1.c \
+error.c filemode.c fsusage.c full-write.c getopt.c getopt1.c \
getversion.c idcache.c isdir.c makepath.c \
-modechange.c mountlist.c savedir.c \
+modechange.c mountlist.c safe-read.c savedir.c \
stripslash.c xgetcwd.c xmalloc.c xstrdup.c userspec.c yesno.c \
fileblocks.c fnmatch.c ftruncate.c mkdir.c mktime.c rename.c stpcpy.c \
strdup.c strstr.c alloca.c
OBJECTS = getdate.o posixtm.o \
argmatch.o backupfile.o basename.o dirname.o eaccess.o \
-error.o filemode.o getopt.o getopt1.o \
+error.o filemode.o full-write.o getopt.o getopt1.o \
getversion.o idcache.o isdir.o makepath.o \
-modechange.o savedir.o \
+modechange.o safe-read.o savedir.o \
stripslash.o xgetcwd.o xmalloc.o xstrdup.o userspec.o yesno.o \
@LIBOBJS@ @ALLOCA@
@@ -90,7 +90,7 @@ libfu.a: $(OBJECTS)
# Since this directory contains two parsers, we have to be careful to avoid
# running two $(YACC)s during parallel makes. See below.
getdate.c: getdate.y
- @echo expect 9 shift/reduce conflicts
+ @echo expect 10 shift/reduce conflicts
$(YACC) $(srcdir)/getdate.y
mv y.tab.c getdate.c
diff --git a/lib/filemode.c b/lib/filemode.c
index 0ec4bf7fd9..8b99228077 100644
--- a/lib/filemode.c
+++ b/lib/filemode.c
@@ -32,10 +32,14 @@
#define S_IEXEC S_IXUSR
#endif
+#if 0 /* This is unreliable, since GCC 2.5 always has S_ISREG in its
+ fixed headers but it does not always have mode_t.
+ It seems safer not to try to use mode_t ever. */
#if !defined(S_ISREG) || defined(NO_MODE_T)
/* Doesn't have POSIX.1 stat stuff or doesn't have mode_t. */
#define mode_t unsigned short
#endif
+#endif
#ifdef STAT_MACROS_BROKEN
#ifdef S_ISBLK
@@ -156,7 +160,7 @@ mode_string (mode, str)
unsigned short mode;
char *str;
{
- str[0] = ftypelet (mode);
+ str[0] = ftypelet ((long) mode);
rwx ((mode & 0700) << 0, &str[1]);
rwx ((mode & 0070) << 3, &str[4]);
rwx ((mode & 0007) << 6, &str[7]);
@@ -177,7 +181,7 @@ mode_string (mode, str)
static char
ftypelet (bits)
- mode_t bits;
+ long bits;
{
#ifdef S_ISBLK
if (S_ISBLK (bits))
diff --git a/lib/full-write.c b/lib/full-write.c
new file mode 100644
index 0000000000..cce5f0f035
--- /dev/null
+++ b/lib/full-write.c
@@ -0,0 +1,71 @@
+/* full-write.c -- an interface to write that retries after interrupts
+ Copyright (C) 1993 Free Software Foundation, Inc.
+
+ 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
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ Copied largely from GNU C's cccp.c.
+ */
+
+#ifdef HAVE_CONFIG_H
+#if defined (CONFIG_BROKETS)
+/* We use <config.h> instead of "config.h" so that a compilation
+ using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
+ (which it would do because it found this file in $srcdir). */
+#include <config.h>
+#else
+#include "config.h"
+#endif
+#endif
+
+#include <sys/types.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <errno.h>
+#ifndef STDC_HEADERS
+extern int errno;
+#endif
+
+/* Write LEN bytes at PTR to descriptor DESC, retrying if interrupted.
+ Return LEN upon success, write's (negative) error code otherwise. */
+
+int
+full_write (desc, ptr, len)
+ int desc;
+ char *ptr;
+ int len;
+{
+ int total_written;
+
+ total_written = 0;
+ while (len > 0)
+ {
+ int written = write (desc, ptr, len);
+ if (written < 0)
+ {
+#ifdef EINTR
+ if (errno == EINTR)
+ continue;
+#endif
+ return written;
+ }
+ total_written += written;
+ ptr += written;
+ len -= written;
+ }
+ return total_written;
+}
diff --git a/lib/safe-read.c b/lib/safe-read.c
new file mode 100644
index 0000000000..2303ea111a
--- /dev/null
+++ b/lib/safe-read.c
@@ -0,0 +1,66 @@
+/* safe-read.c -- an interface to read that retries after interrupts
+ Copyright (C) 1993, 1994 Free Software Foundation, Inc.
+
+ 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
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+#ifdef HAVE_CONFIG_H
+#if defined (CONFIG_BROKETS)
+/* We use <config.h> instead of "config.h" so that a compilation
+ using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
+ (which it would do because it found this file in $srcdir). */
+#include <config.h>
+#else
+#include "config.h"
+#endif
+#endif
+
+#include <sys/types.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <errno.h>
+#ifndef STDC_HEADERS
+extern int errno;
+#endif
+
+/* Read LEN bytes at PTR from descriptor DESC, retrying if interrupted.
+ Return the actual number of bytes read, zero for EOF, or negative
+ for an error. */
+
+int
+safe_read (desc, ptr, len)
+ int desc;
+ char *ptr;
+ int len;
+{
+ int n_chars;
+
+ if (len <= 0)
+ return len;
+
+#ifdef EINTR
+ do
+ {
+ n_chars = read (desc, ptr, len);
+ }
+ while (n_chars < 0 && errno == EINTR);
+#else
+ n_chars = read (desc, ptr, len);
+#endif
+
+ return n_chars;
+}