/* GNU dump extensions to tar.
- Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001,
- 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+ Copyright 1988, 1992-1994, 1996-1997, 1999-2001, 2003-2009, 2013
+ 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 3, or (at your option) any later
- version.
+ This file is part of GNU tar.
- 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.
+ GNU tar 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 3 of the License, or
+ (at your option) any later version.
- 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. */
+ GNU tar 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, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include <hash.h>
}
/* Read from file FP a nul-terminated string and convert it to
- uintmax_t. Return the resulting value in PVAL. Assume C has
- already been read.
+ uintmax_t. Return an intmax_t representation of the resulting
+ value in PVAL. Assume C has already been read.
Throw a fatal error if the string cannot be converted or if the
converted value exceeds MAX_VAL.
Return the last character read or EOF on end of file. */
static int
-read_unsigned_num (int c, FILE *fp, uintmax_t max_val, uintmax_t *pval)
+read_unsigned_num (int c, FILE *fp, uintmax_t max_val, intmax_t *pval)
{
size_t i;
+ uintmax_t u;
char buf[UINTMAX_STRSIZE_BOUND], *ep;
for (i = 0; ISDIGIT (c); i++)
buf[i] = 0;
errno = 0;
- *pval = strtoumax (buf, &ep, 10);
- if (c || errno || max_val < *pval)
+ u = strtoumax (buf, &ep, 10);
+ if (c || errno || max_val < u)
FATAL_ERROR ((0, errno, _("Unexpected field value in snapshot file")));
+ *pval = represent_uintmax (u);
return c;
}
/* Read from file FP a nul-terminated string and convert it to
- uintmax_t. Return the resulting value in PVAL.
+ an integer in the range MIN_VAL..MAXVAL. Return the resulting
+ value, converted to intmax_t, in PVAL. MINVAL must be nonpositive.
Throw a fatal error if the string cannot be converted or if the
- converted value exceeds MAX_VAL.
+ converted value is out of range.
Return the last character read or EOF on end of file. */
static int
-read_num (FILE *fp, uintmax_t max_val, uintmax_t *pval)
+read_num (FILE *fp, intmax_t min_val, uintmax_t max_val, intmax_t *pval)
{
- return read_unsigned_num (getc (fp), fp, max_val, pval);
+ int c = getc (fp);
+ if (c == '-')
+ {
+ read_negative_num (fp, min_val, pval);
+ return 0;
+ }
+ return read_unsigned_num (c, fp, max_val, pval);
}
/* Read from FP two NUL-terminated strings representing a struct
static void
read_timespec (FILE *fp, struct timespec *pval)
{
- int c = getc (fp);
intmax_t i;
- uintmax_t u;
+ int c = read_num (fp, TYPE_MINIMUM (time_t), TYPE_MAXIMUM (time_t), &i);
+ pval->tv_sec = i;
- if (c == '-')
- {
- read_negative_num (fp, TYPE_MINIMUM (time_t), &i);
- c = 0;
- pval->tv_sec = i;
- }
- else
- {
- c = read_unsigned_num (c, fp, TYPE_MAXIMUM (time_t), &u);
- pval->tv_sec = u;
- }
-
- if (c || read_num (fp, BILLION - 1, &u))
+ if (c || read_num (fp, 0, BILLION - 1, &i))
FATAL_ERROR ((0, 0, "%s: %s",
quotearg_colon (listed_incremental_option),
_("Unexpected EOF in snapshot file")));
- pval->tv_nsec = u;
+ pval->tv_nsec = i;
}
/* Read incremental snapshot format 2 */
static void
read_incr_db_2 (void)
{
- uintmax_t u;
struct obstack stk;
obstack_init (&stk);
for (;;)
{
+ intmax_t i;
struct timespec mtime;
dev_t dev;
ino_t ino;
char *content;
size_t s;
- if (read_num (listed_incremental_stream, 1, &u))
+ if (read_num (listed_incremental_stream, 0, 1, &i))
return; /* Normal return */
- nfs = u;
+ nfs = i;
read_timespec (listed_incremental_stream, &mtime);
- if (read_num (listed_incremental_stream, TYPE_MAXIMUM (dev_t), &u))
+ if (read_num (listed_incremental_stream,
+ TYPE_MINIMUM (dev_t), TYPE_MAXIMUM (dev_t), &i))
break;
- dev = u;
+ dev = i;
- if (read_num (listed_incremental_stream, TYPE_MAXIMUM (ino_t), &u))
+ if (read_num (listed_incremental_stream,
+ TYPE_MINIMUM (ino_t), TYPE_MAXIMUM (ino_t), &i))
break;
- ino = u;
+ ino = i;
if (read_obstack (listed_incremental_stream, &stk, &s))
break;