changeset 148:8124cd69ac96

GNU file utilities
author Jim Meyering <jim@meyering.net>
date Wed, 26 Jan 1994 18:40:49 +0000
parents 5e381e0380f4
children b701d2d6b404
files lib/Makefile.in lib/filemode.c lib/full-write.c lib/safe-read.c
diffstat 4 files changed, 148 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -33,18 +33,18 @@
 
 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 @@
 # 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
 
--- 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 @@
      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 @@
 
 static char
 ftypelet (bits)
-     mode_t bits;
+     long bits;
 {
 #ifdef S_ISBLK
   if (S_ISBLK (bits))
new file mode 100644
--- /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;
+}
new file mode 100644
--- /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;
+}