bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gnulib] sync gnulib from coreutils (yesno, makepath fixes)


From: Paul Eggert
Subject: [bug-gnulib] sync gnulib from coreutils (yesno, makepath fixes)
Date: Sat, 14 May 2005 21:47:18 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

I installed the following:

2005-05-14  Paul Eggert  <address@hidden>

        Sync from coreutils.
        * lib/gethrxtime.c, lib/gethrxtime.h, lib/getpass.h, lib/mountlist.h,
        lib/path-concat.c, lib/regex.h, lib/strtoll.c, lib/unlocked-io.h,
        lib/xtime.h: White space changes only.
        * lib/makepath.c (make_path): Port to hosts where leading "//"
        is special.
        * lib/yesno.c: Include getline.h, not ctype.h.
        (yesno): Don't remove leading white space; POSIX doesn't allow it.
        Use getline to remove arbitrary restriction on response length.
        * modules/yesno (Depends-on): Add getline.

Index: lib/gethrxtime.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gethrxtime.c,v
retrieving revision 1.2
diff -p -u -r1.2 gethrxtime.c
--- lib/gethrxtime.c    14 May 2005 06:03:58 -0000      1.2
+++ lib/gethrxtime.c    15 May 2005 04:42:16 -0000
@@ -58,7 +58,7 @@ gethrxtime (void)
   }
 # endif
 
-#if HAVE_MICROUPTIME
+# if HAVE_MICROUPTIME
   {
     struct timeval tv;
     microuptime (&tv);
Index: lib/gethrxtime.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gethrxtime.h,v
retrieving revision 1.2
diff -p -u -r1.2 gethrxtime.h
--- lib/gethrxtime.h    14 May 2005 06:03:58 -0000      1.2
+++ lib/gethrxtime.h    15 May 2005 04:42:16 -0000
@@ -19,19 +19,19 @@
 /* Written by Paul Eggert.  */
 
 #ifndef GETHRXTIME_H_
-#define GETHRXTIME_H_ 1
+# define GETHRXTIME_H_ 1
 
-#include "xtime.h"
+# include "xtime.h"
 
 /* Get the current time, as a count of the number of nanoseconds since
    an arbitrary epoch (e.g., the system boot time).  This clock can't
    be set, is always increasing, and is nearly linear.  */
 
-#if HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME
-# include <time.h>
+# if HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME
+#  include <time.h>
 static inline xtime_t gethrxtime (void) { return gethrtime (); }
-#else
+# else
 xtime_t gethrxtime (void);
-#endif
+# endif
 
 #endif
Index: lib/getpass.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getpass.h,v
retrieving revision 1.2
diff -p -u -r1.2 getpass.h
--- lib/getpass.h       14 May 2005 06:03:58 -0000      1.2
+++ lib/getpass.h       15 May 2005 04:42:16 -0000
@@ -17,15 +17,15 @@
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 #ifndef GETPASS_H
-#define GETPASS_H
+# define GETPASS_H
 
 /* Get getpass declaration, if available.  */
-#include <unistd.h>
+# include <unistd.h>
 
-#if defined HAVE_DECL_GETPASS && !HAVE_DECL_GETPASS
+# if defined HAVE_DECL_GETPASS && !HAVE_DECL_GETPASS
 /* Read a password of arbitrary length from /dev/tty or stdin.  */
 char *getpass (const char *prompt);
 
-#endif
+# endif
 
 #endif /* GETPASS_H */
Index: lib/makepath.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/makepath.c,v
retrieving revision 1.60
diff -p -u -r1.60 makepath.c
--- lib/makepath.c      14 May 2005 06:03:58 -0000      1.60
+++ lib/makepath.c      15 May 2005 04:42:16 -0000
@@ -1,7 +1,7 @@
 /* makepath.c -- Ensure that a directory path exists.
 
-   Copyright (C) 1990, 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free
-   Software Foundation, Inc.
+   Copyright (C) 1990, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005
+   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
@@ -207,8 +207,14 @@ make_path (const char *argpath,
       /* If we've saved the cwd and DIRPATH is an absolute pathname,
         we must chdir to `/' in order to enable the chdir optimization.
          So if chdir ("/") fails, turn off the optimization.  */
-      if (do_chdir && *dirpath == '/' && chdir ("/") < 0)
-       do_chdir = false;
+      if (do_chdir && dirpath[0] == '/')
+       {
+         /* POSIX says "//" might be special, so chdir to "//" if the
+            file name starts with exactly two slashes.  */
+         char const *root = "//" + (dirpath[1] != '/' || dirpath[2] == '/');
+         if (chdir (root) != 0)
+           do_chdir = false;
+       }
 
       slash = dirpath;
 
Index: lib/mountlist.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/mountlist.h,v
retrieving revision 1.14
diff -p -u -r1.14 mountlist.h
--- lib/mountlist.h     14 May 2005 06:03:58 -0000      1.14
+++ lib/mountlist.h     15 May 2005 04:42:16 -0000
@@ -18,10 +18,10 @@
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 #ifndef MOUNTLIST_H_
-#define MOUNTLIST_H_
+# define MOUNTLIST_H_
 
-#include <stdbool.h>
-#include <sys/types.h>
+# include <stdbool.h>
+# include <sys/types.h>
 
 /* A mount table entry. */
 struct mount_entry
Index: lib/path-concat.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/path-concat.c,v
retrieving revision 1.21
diff -p -u -r1.21 path-concat.c
--- lib/path-concat.c   14 May 2005 06:03:58 -0000      1.21
+++ lib/path-concat.c   15 May 2005 04:42:16 -0000
@@ -89,8 +89,8 @@ path_concat (char const *dir, char const
 }
 
 #ifdef TEST_PATH_CONCAT
-#include <stdlib.h>
-#include <stdio.h>
+# include <stdlib.h>
+# include <stdio.h>
 int
 main ()
 {
Index: lib/regex.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/regex.h,v
retrieving revision 1.23
diff -p -u -r1.23 regex.h
--- lib/regex.h 14 May 2005 06:03:58 -0000      1.23
+++ lib/regex.h 15 May 2005 04:42:16 -0000
@@ -193,7 +193,7 @@ extern reg_syntax_t re_syntax_options;
    & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS           \
        | RE_CONTEXT_INVALID_OPS ))
 
-#define RE_SYNTAX_POSIX_AWK                                            \
+#define RE_SYNTAX_POSIX_AWK                                            \
   (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS             \
    | RE_INTERVALS          | RE_NO_GNU_OPS)
 
Index: lib/strtoll.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/strtoll.c,v
retrieving revision 1.6
diff -p -u -r1.6 strtoll.c
--- lib/strtoll.c       14 May 2005 06:03:58 -0000      1.6
+++ lib/strtoll.c       15 May 2005 04:42:16 -0000
@@ -16,7 +16,7 @@
    with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#define        QUAD    1
+#define QUAD   1
 
 #include <strtol.c>
 
Index: lib/unlocked-io.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/unlocked-io.h,v
retrieving revision 1.6
diff -p -u -r1.6 unlocked-io.h
--- lib/unlocked-io.h   14 May 2005 06:03:58 -0000      1.6
+++ lib/unlocked-io.h   15 May 2005 04:42:16 -0000
@@ -19,7 +19,7 @@
 /* Written by Jim Meyering.  */
 
 #ifndef UNLOCKED_IO_H
-#define UNLOCKED_IO_H 1
+# define UNLOCKED_IO_H 1
 
 /* These are wrappers for functions/macros from the GNU C library, and
    from other C libraries supporting POSIX's optional thread-safe functions.
@@ -32,106 +32,106 @@
    the *_unlocked functions directly.  On hosts that lack those
    functions, invoke the non-thread-safe versions instead.  */
 
-#include <stdio.h>
+# include <stdio.h>
 
-#if HAVE_DECL_CLEARERR_UNLOCKED
-# undef clearerr
-# define clearerr(x) clearerr_unlocked (x)
-#else
-# define clearerr_unlocked(x) clearerr (x)
-#endif
-
-#if HAVE_DECL_FEOF_UNLOCKED
-# undef feof
-# define feof(x) feof_unlocked (x)
-#else
-# define feof_unlocked(x) feof (x)
-#endif
-
-#if HAVE_DECL_FERROR_UNLOCKED
-# undef ferror
-# define ferror(x) ferror_unlocked (x)
-#else
-# define ferror_unlocked(x) ferror (x)
-#endif
-
-#if HAVE_DECL_FFLUSH_UNLOCKED
-# undef fflush
-# define fflush(x) fflush_unlocked (x)
-#else
-# define fflush_unlocked(x) fflush (x)
-#endif
-
-#if HAVE_DECL_FGETS_UNLOCKED
-# undef fgets
-# define fgets(x,y,z) fgets_unlocked (x,y,z)
-#else
-# define fgets_unlocked(x,y,z) fgets (x,y,z)
-#endif
-
-#if HAVE_DECL_FPUTC_UNLOCKED
-# undef fputc
-# define fputc(x,y) fputc_unlocked (x,y)
-#else
-# define fputc_unlocked(x,y) fputc (x,y)
-#endif
-
-#if HAVE_DECL_FPUTS_UNLOCKED
-# undef fputs
-# define fputs(x,y) fputs_unlocked (x,y)
-#else
-# define fputs_unlocked(x,y) fputs (x,y)
-#endif
-
-#if HAVE_DECL_FREAD_UNLOCKED
-# undef fread
-# define fread(w,x,y,z) fread_unlocked (w,x,y,z)
-#else
-# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
-#endif
-
-#if HAVE_DECL_FWRITE_UNLOCKED
-# undef fwrite
-# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
-#else
-# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
-#endif
-
-#if HAVE_DECL_GETC_UNLOCKED
-# undef getc
-# define getc(x) getc_unlocked (x)
-#else
-# define getc_unlocked(x) getc (x)
-#endif
-
-#if HAVE_DECL_GETCHAR_UNLOCKED
-# undef getchar
-# define getchar() getchar_unlocked ()
-#else
-# define getchar_unlocked() getchar ()
-#endif
-
-#if HAVE_DECL_PUTC_UNLOCKED
-# undef putc
-# define putc(x,y) putc_unlocked (x,y)
-#else
-# define putc_unlocked(x,y) putc (x,y)
-#endif
-
-#if HAVE_DECL_PUTCHAR_UNLOCKED
-# undef putchar
-# define putchar(x) putchar_unlocked (x)
-#else
-# define putchar_unlocked(x) putchar (x)
-#endif
+# if HAVE_DECL_CLEARERR_UNLOCKED
+#  undef clearerr
+#  define clearerr(x) clearerr_unlocked (x)
+# else
+#  define clearerr_unlocked(x) clearerr (x)
+# endif
+
+# if HAVE_DECL_FEOF_UNLOCKED
+#  undef feof
+#  define feof(x) feof_unlocked (x)
+# else
+#  define feof_unlocked(x) feof (x)
+# endif
+
+# if HAVE_DECL_FERROR_UNLOCKED
+#  undef ferror
+#  define ferror(x) ferror_unlocked (x)
+# else
+#  define ferror_unlocked(x) ferror (x)
+# endif
+
+# if HAVE_DECL_FFLUSH_UNLOCKED
+#  undef fflush
+#  define fflush(x) fflush_unlocked (x)
+# else
+#  define fflush_unlocked(x) fflush (x)
+# endif
+
+# if HAVE_DECL_FGETS_UNLOCKED
+#  undef fgets
+#  define fgets(x,y,z) fgets_unlocked (x,y,z)
+# else
+#  define fgets_unlocked(x,y,z) fgets (x,y,z)
+# endif
+
+# if HAVE_DECL_FPUTC_UNLOCKED
+#  undef fputc
+#  define fputc(x,y) fputc_unlocked (x,y)
+# else
+#  define fputc_unlocked(x,y) fputc (x,y)
+# endif
+
+# if HAVE_DECL_FPUTS_UNLOCKED
+#  undef fputs
+#  define fputs(x,y) fputs_unlocked (x,y)
+# else
+#  define fputs_unlocked(x,y) fputs (x,y)
+# endif
+
+# if HAVE_DECL_FREAD_UNLOCKED
+#  undef fread
+#  define fread(w,x,y,z) fread_unlocked (w,x,y,z)
+# else
+#  define fread_unlocked(w,x,y,z) fread (w,x,y,z)
+# endif
+
+# if HAVE_DECL_FWRITE_UNLOCKED
+#  undef fwrite
+#  define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
+# else
+#  define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
+# endif
+
+# if HAVE_DECL_GETC_UNLOCKED
+#  undef getc
+#  define getc(x) getc_unlocked (x)
+# else
+#  define getc_unlocked(x) getc (x)
+# endif
+
+# if HAVE_DECL_GETCHAR_UNLOCKED
+#  undef getchar
+#  define getchar() getchar_unlocked ()
+# else
+#  define getchar_unlocked() getchar ()
+# endif
+
+# if HAVE_DECL_PUTC_UNLOCKED
+#  undef putc
+#  define putc(x,y) putc_unlocked (x,y)
+# else
+#  define putc_unlocked(x,y) putc (x,y)
+# endif
+
+# if HAVE_DECL_PUTCHAR_UNLOCKED
+#  undef putchar
+#  define putchar(x) putchar_unlocked (x)
+# else
+#  define putchar_unlocked(x) putchar (x)
+# endif
 
-#undef flockfile
-#define flockfile(x) ((void) 0)
+# undef flockfile
+# define flockfile(x) ((void) 0)
 
-#undef ftrylockfile
-#define ftrylockfile(x) 0
+# undef ftrylockfile
+# define ftrylockfile(x) 0
 
-#undef funlockfile
-#define funlockfile(x) ((void) 0)
+# undef funlockfile
+# define funlockfile(x) ((void) 0)
 
 #endif /* UNLOCKED_IO_H */
Index: lib/xtime.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xtime.h,v
retrieving revision 1.2
diff -p -u -r1.2 xtime.h
--- lib/xtime.h 14 May 2005 06:03:58 -0000      1.2
+++ lib/xtime.h 15 May 2005 04:42:16 -0000
@@ -19,24 +19,24 @@
 /* Written by Paul Eggert.  */
 
 #ifndef XTIME_H_
-#define XTIME_H_ 1
+# define XTIME_H_ 1
 
 /* xtime_t is a signed type used for time stamps.  It is an integer
    type that is a count of nanoseconds -- except for obsolescent hosts
    without sufficiently-wide integers, where it is a count of
    seconds.  */
-#if HAVE_LONG_LONG
+# if HAVE_LONG_LONG
 typedef long long int xtime_t;
-# define XTIME_PRECISION 1000000000LL
-#else
-# include <limits.h>
-typedef long int xtime_t;
-# if LONG_MAX >> 31 >> 31 == 0
-#  define XTIME_PRECISION 1L
+#  define XTIME_PRECISION 1000000000LL
 # else
-#  define XTIME_PRECISION 1000000000L
+#  include <limits.h>
+typedef long int xtime_t;
+#  if LONG_MAX >> 31 >> 31 == 0
+#   define XTIME_PRECISION 1L
+#  else
+#   define XTIME_PRECISION 1000000000L
+#  endif
 # endif
-#endif
 
 /* Return an extended time value that contains S seconds and NS
    nanoseconds, without any overflow checking.  */
Index: lib/yesno.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/yesno.c,v
retrieving revision 1.13
diff -p -u -r1.13 yesno.c
--- lib/yesno.c 14 May 2005 06:03:58 -0000      1.13
+++ lib/yesno.c 15 May 2005 04:42:16 -0000
@@ -1,5 +1,7 @@
 /* yesno.c -- read a yes/no response from stdin
-   Copyright (C) 1990, 1998, 2001, 2003, 2004 Free Software Foundation, Inc.
+
+   Copyright (C) 1990, 1998, 2001, 2003, 2004, 2005 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
@@ -21,36 +23,31 @@
 
 #include "yesno.h"
 
-#include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
 
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
+#include "getline.h"
 
-/* Read one line from standard input
-   and return nonzero if that line begins with y or Y,
-   otherwise return 0. */
+/* Return true if we read an affirmative line from standard input.  */
 
 extern int rpmatch (char const *response);
 
 bool
 yesno (void)
 {
-  /* We make some assumptions here:
-     a) leading white space in the response are not vital
-     b) the first 128 characters of the answer are enough (the rest can
-       be ignored)
-     I cannot think for a situation where this is not ok.  address@hidden  */
-  char buf[128];
-  int len = 0;
-  int c;
-
-  while ((c = getchar ()) != EOF && c != '\n')
-    if ((len > 0 && len < 127) || (len == 0 && !isspace (c)))
-      buf[len++] = c;
-  buf[len] = '\0';
+  char *response = NULL;
+  size_t response_size = 0;
+  ssize_t response_len = getline (&response, &response_size, stdin);
+  bool yes;
+
+  if (response_len <= 0)
+    yes = false;
+  else
+    {
+      response[response_len - 1] = '\0';
+      yes = (0 < rpmatch (response));
+    }
 
-  return rpmatch (buf) == 1;
+  free (response);
+  return yes;
 }
Index: modules/yesno
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/yesno,v
retrieving revision 1.9
diff -p -u -r1.9 yesno
--- modules/yesno       6 May 2005 17:22:45 -0000       1.9
+++ modules/yesno       15 May 2005 04:42:16 -0000
@@ -8,6 +8,7 @@ lib/yesno.h
 m4/yesno.m4
 
 Depends-on:
+getline
 rpmatch
 stdbool
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]