summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-06-22 06:14:28 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-06-22 06:14:28 +0000
commit53fa1be9b65f01469eafcc7c57499d73e35715a7 (patch)
tree52bc4fdd56c82dcd254136e04f4cb09402f978bd
parent49113b5fbf40e65bb5b154ce2a11b9ec0b19be35 (diff)
downloadpaxutils-53fa1be9b65f01469eafcc7c57499d73e35715a7.tar.gz
Improve support for time stamps and other wide integers.
* gnulib.modules: Add inttostr, quote, quotearg. * lib/system.h (TYPE_SIGNED, TYPE_MINIMUM, TYPE_MAXIMUM): Remove. (INT_STRLEN_BOUND): Remove. Include "intprops.h" instead. (UINTMAX_STRSIZE_BOUND): Define in terms of INT_BUFSIZE_BOUND, not INT_STRLEN_BOUND. [HAVE_UTIME_H]: Don't include utime.h. * paxlib/DISTFILES: Remove convert.c. * paxlib/convert.c: Remove. * paxlib/error.c: Include quote.h, quotearg.h. * paxlib/paxlib.h: Include inttostr.h. (STRINGIFY_BIGINT): Define in terms of umaxtostr. (stringify_uintmax_t_backwards): Remove decl. * tests/genfile.c: Include <utimens.h> instead of rolling our own. (exec_checkpoint): Use utimens instead of rolling our own. Don't pass extra args to error. (main): Wrap message inside _().
-rw-r--r--ChangeLog19
-rw-r--r--gnulib.modules3
-rw-r--r--lib/system.h27
-rw-r--r--m4/system.m410
-rw-r--r--paxlib/DISTFILES1
-rw-r--r--paxlib/convert.c33
-rw-r--r--paxlib/error.c4
-rw-r--r--paxlib/paxlib.h5
-rw-r--r--tests/genfile.c29
9 files changed, 49 insertions, 82 deletions
diff --git a/ChangeLog b/ChangeLog
index cc32db9..1faaa76 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
2005-06-21 Paul Eggert <eggert@cs.ucla.edu>
+ Improve support for time stamps and other wide integers.
+ * gnulib.modules: Add inttostr, quote, quotearg.
+ * lib/system.h (TYPE_SIGNED, TYPE_MINIMUM, TYPE_MAXIMUM): Remove.
+ (INT_STRLEN_BOUND): Remove.
+ Include "intprops.h" instead.
+ (UINTMAX_STRSIZE_BOUND): Define in terms of INT_BUFSIZE_BOUND,
+ not INT_STRLEN_BOUND.
+ [HAVE_UTIME_H]: Don't include utime.h.
+ * paxlib/DISTFILES: Remove convert.c.
+ * paxlib/convert.c: Remove.
+ * paxlib/error.c: Include quote.h, quotearg.h.
+ * paxlib/paxlib.h: Include inttostr.h.
+ (STRINGIFY_BIGINT): Define in terms of umaxtostr.
+ (stringify_uintmax_t_backwards): Remove decl.
+ * tests/genfile.c: Include <utimens.h> instead of rolling our own.
+ (exec_checkpoint): Use utimens instead of rolling our own.
+ Don't pass extra args to error.
+ (main): Wrap message inside _().
+
* tests/genfile.c: Port to Solaris 8.
Include <signal.h>, for 'signal'.
(SIGCHLD) [! defined SIGCHLD && defined SIGCLD]: Define.
diff --git a/gnulib.modules b/gnulib.modules
index 2e667eb..23c0ca2 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -5,6 +5,9 @@ dirname
full-write
getdate
getopt
+inttostr
+quote
+quotearg
safe-read
stdbool
strtol
diff --git a/lib/system.h b/lib/system.h
index 83afa11..f9e399e 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -1,7 +1,7 @@
/* System dependent definitions for GNU tar.
Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003,
- 2004 Free Software Foundation, Inc.
+ 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
@@ -453,24 +453,9 @@ char *getenv ();
# include <inttypes.h>
#endif
-/* These macros work even on ones'-complement hosts (!).
- The extra casts work around common compiler bugs. */
-#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
-#define TYPE_MINIMUM(t) (TYPE_SIGNED (t) \
- ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
- : (t) 0)
-#define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
-
-/* Bound on length of the string representing an integer value of type t.
- Subtract one for the sign bit if t is signed;
- 302 / 1000 is log10 (2) rounded up;
- add one for integer division truncation;
- add one more for a minus sign if t is signed. */
-#define INT_STRLEN_BOUND(t) \
- ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \
- + 1 + TYPE_SIGNED (t))
-
-#define UINTMAX_STRSIZE_BOUND (INT_STRLEN_BOUND (uintmax_t) + 1)
+#include <intprops.h>
+
+#define UINTMAX_STRSIZE_BOUND INT_BUFSIZE_BOUND (uintmax_t)
/* Prototypes for external functions. */
@@ -489,10 +474,6 @@ char *getenv ();
time_t time ();
#endif
-#ifdef HAVE_UTIME_H
-# include <utime.h>
-#endif
-
/* Library modules. */
#include <dirname.h>
diff --git a/m4/system.m4 b/m4/system.m4
index 5a742b6..bc225e6 100644
--- a/m4/system.m4
+++ b/m4/system.m4
@@ -1,9 +1,16 @@
+# Configuration for paxutils/lib/system.h.
+
+# Copyright (C) 2005 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
AC_DEFUN([PU_SYSTEM],[
AC_HEADER_STDC
AC_CHECK_HEADERS_ONCE([string.h memory.h fcntl.h unistd.h sys/wait.h sys/gentape.h \
sys/tape.h sys/device.h sys/param.h sys/buf.h sys/tprintf.h sys/mtio.h \
- sgtty.h sys/io/trioctl.h inttypes.h locale.h utime.h])
+ sgtty.h sys/io/trioctl.h inttypes.h locale.h])
AC_CHECK_HEADERS_ONCE([sys/time.h])
AC_HEADER_TIME
@@ -17,4 +24,3 @@ AC_DEFUN([PU_SYSTEM],[
AC_CHECK_FUNCS_ONCE(lstat mkfifo setlocale)
AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
])
-
diff --git a/paxlib/DISTFILES b/paxlib/DISTFILES
index 1fbdab0..bb4c9e9 100644
--- a/paxlib/DISTFILES
+++ b/paxlib/DISTFILES
@@ -1,4 +1,3 @@
-convert.c
error.c
exit.c
names.c
diff --git a/paxlib/convert.c b/paxlib/convert.c
deleted file mode 100644
index 6734c71..0000000
--- a/paxlib/convert.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Data conversion functions for GNU paxutils
-
- Copyright (C) 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
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-#include <system.h>
-
-/* Format O as a null-terminated decimal string into BUF _backwards_;
- return pointer to start of result. */
-char *
-stringify_uintmax_t_backwards (uintmax_t o, char *buf)
-{
- *--buf = '\0';
- do
- *--buf = '0' + (int) (o % 10);
- while ((o /= 10) != 0);
- return buf;
-}
-
diff --git a/paxlib/error.c b/paxlib/error.c
index b609b27..b2bf3d6 100644
--- a/paxlib/error.c
+++ b/paxlib/error.c
@@ -18,6 +18,8 @@
#include <system.h>
#include <paxlib.h>
+#include <quote.h>
+#include <quotearg.h>
/* Decode MODE from its binary form in a stat structure, and encode it
into a 9-byte string STRING, terminated with a NUL. */
@@ -355,5 +357,3 @@ chdir_fatal (char const *name)
{
call_arg_fatal ("chdir", name);
}
-
-
diff --git a/paxlib/paxlib.h b/paxlib/paxlib.h
index 03f15eb..c9b3036 100644
--- a/paxlib/paxlib.h
+++ b/paxlib/paxlib.h
@@ -22,6 +22,7 @@
#define _paxlib_h_
#include <hash.h>
+#include <inttostr.h>
/* Error reporting functions and definitions */
@@ -100,9 +101,7 @@ void write_error (char const *);
void pax_exit (void);
void fatal_exit (void) __attribute__ ((noreturn));
-#define STRINGIFY_BIGINT(i, b) \
- stringify_uintmax_t_backwards ((uintmax_t) (i), (b) + UINTMAX_STRSIZE_BOUND)
-char *stringify_uintmax_t_backwards (uintmax_t, char *);
+#define STRINGIFY_BIGINT(i, b) umaxtostr (i, b)
/* Name-related functions */
diff --git a/tests/genfile.c b/tests/genfile.c
index 21364d5..081ba59 100644
--- a/tests/genfile.c
+++ b/tests/genfile.c
@@ -28,6 +28,7 @@
#include <argmatch.h>
#include <argp.h>
#include <argcv.h>
+#include <utimens.h>
#ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
@@ -40,16 +41,6 @@
# define SIGCHLD SIGCLD
#endif
-#if HAVE_UTIME_H
-# include <utime.h>
-#else
-struct utimbuf
- {
- long actime;
- long modtime;
- };
-#endif
-
enum pattern
{
DEFAULT_PATTERN,
@@ -509,10 +500,14 @@ exec_checkpoint (struct action *p)
{
case OPT_TOUCH:
{
- struct utimbuf u;
+ struct timespec ts[2];
- u.actime = u.modtime = p->ts.tv_sec;
- utime (p->name, &u);
+ ts[0] = ts[1] = p->ts;
+ if (utimens (p->name, ts) != 0)
+ {
+ error (0, errno, _("cannot set time on `%s'"), p->name);
+ break;
+ }
}
break;
@@ -521,8 +516,7 @@ exec_checkpoint (struct action *p)
FILE *fp = fopen (p->name, "a");
if (!fp)
{
- error (0, errno, _("cannot open `%s'"),
- p->name, strerror (errno));
+ error (0, errno, _("cannot open `%s'"), p->name);
break;
}
@@ -536,8 +530,7 @@ exec_checkpoint (struct action *p)
int fd = open (p->name, O_RDWR);
if (fd == -1)
{
- error (0, errno, _("cannot open `%s'"),
- p->name, strerror (errno));
+ error (0, errno, _("cannot open `%s'"), p->name);
break;
}
ftruncate (fd, p->size);
@@ -709,7 +702,7 @@ main (int argc, char **argv)
{
case mode_stat:
if (argc == 0)
- error (EXIT_FAILURE, 0, "--stat requires file names");
+ error (EXIT_FAILURE, 0, _("--stat requires file names"));
while (argc--)
print_stat (*argv++);