summaryrefslogtreecommitdiff
path: root/src/shred.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-12-21 11:39:02 +0000
committerJim Meyering <jim@meyering.net>2001-12-21 11:39:02 +0000
commit9b9c6a85657685474a731419f117be9ed3f1ed2a (patch)
tree1a92dd627ebe8cef990ae0a5ee7ba5f72462cd76 /src/shred.c
parent51a3adcefa75f46e93391f8fd79fc9cf35c6df67 (diff)
downloadcoreutils-9b9c6a85657685474a731419f117be9ed3f1ed2a.tar.xz
[!HAVE_CONFIG_H]: Remove block of code that duplicated
code in lib/ for compiling this program without config.h.
Diffstat (limited to 'src/shred.c')
-rw-r--r--src/shred.c326
1 files changed, 8 insertions, 318 deletions
diff --git a/src/shred.c b/src/shred.c
index 856f625e4..be4d385f5 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -102,326 +102,16 @@
#include <signal.h>
#include <sys/types.h>
-#if HAVE_CONFIG_H
-/* Default fileutils build */
-# include "system.h"
-# include "xstrtol.h"
-# include "closeout.h"
-# include "error.h"
-# include "human.h"
-# include "quotearg.h" /* For quotearg_colon */
-# include "quote.h" /* For quotearg_colon */
-# include "xalloc.h"
+#include "system.h"
+#include "xstrtol.h"
+#include "closeout.h"
+#include "error.h"
+#include "human.h"
+#include "quotearg.h" /* For quotearg_colon */
+#include "quote.h" /* For quotearg_colon */
+#include "xalloc.h"
char *xstrdup PARAMS ((char const *));
-#else /* !HAVE_CONFIG_H */
-/*
- * Standalone build - this file compiles by itself without autoconf and
- * the like. No i18n, and I still have to write a stub for getopt_long,
- * but it's a lot less intertwingled than the usual GNU utilities.
- */
-
-# include <ctype.h> /* For isprint */
-# include <string.h> /* For memcpy, strerror */
-# include <limits.h> /* For ULONG_MAX etc. */
-# include <stdlib.h> /* For strtoul, EXIT_FAILURE */
-# include <errno.h>
-# include <fcntl.h> /* For O_RDONLY etc. */
-# include <unistd.h> /* For getpid, etc. */
-# include <sys/time.h> /* For struct timeval */
-# include <sys/stat.h> /* For struct stat */
-
-# define PACKAGE "standalone"
-# define VERSION "2.0" /* Kind of arbitrary... */
-
-# if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5 || __STRICT_ANSI__
-# define attribute(x)
-# else
-# define attribute __attribute__
-# if __GNUC__ == 2 && __GNUC_MINOR__ < 7
- /* The __-protected forms were introduced in GCC 2.6.4 */
-# define __format__ format
-# define __printf__ printf
-# endif
-# endif
-
-/* Reasonable default assumptions for time-getting */
-# ifndef HAVE_GETTIMEOFDAY
-# define HAVE_GETTIMEOFDAY 1 /* Most systems have it these days */
-# endif
-
-# ifdef CLOCK_REALTIME
-# ifndef HAVE_CLOCK_GETTIME
-# define HAVE_CLOCK_GETTIME 1
-# endif
-# endif
-
-# ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
-# endif
-
-# define RETSIGTYPE int
-
-# ifndef S_IWUSR
-# ifdef S_IWRITE
-# define S_IWUSR S_IWRITE
-# else
-# define S_IWUSR 0200
-# endif
-# endif
-
-/* POSIX doesn't require st_blksize, and 65536 is a reasonable
- upper bound for existing filesystem practice. */
-# define ST_BLKSIZE(Stat) 65536
-
-# define uintmax_t unsigned long
-
-/* Variant human-readable function that ignores last two args */
-# define human_readable(v, b, f, t) (sprintf (b, "%lu", (unsigned long) v), b)
-# define LONGEST_HUMAN_READABLE (sizeof (uintmax_t) * CHAR_BIT / 3)
-
-/* Variant convert-to-uintmax_t function that accepts metric suffixes */
-enum strtol_error
- {
- LONGINT_OK, LONGINT_INVALID, LONGINT_INVALID_SUFFIX_CHAR, LONGINT_OVERFLOW
- };
-static uintmax_t
-xstrtoumax (char const *ptr, char const **end, int base, uintmax_t *res,
- char const *valid_suffixes)
-{
- char *end_ptr;
- char const *p;
- static char const metric_suffixes[] = "kMGTPEZY";
- int decimal_flag;
- uintmax_t n;
- char c;
-
- errno = 0;
- *res = n = strtoul (ptr, &end_ptr, base);
- if (end)
- *end = end_ptr;
- if (errno)
- return LONGINT_OVERFLOW;
- c = *end_ptr;
- if (ptr == end_ptr)
- {
- if (valid_suffixes && c && strchr (valid_suffixes, c))
- n = 1;
- else
- return LONGINT_INVALID;
- }
- if (!c)
- return LONGINT_OK;
- /* Now deal with metric-style suffixes */
- if (valid_suffixes && !strchr (valid_suffixes, c))
- return LONGINT_INVALID_SUFFIX_CHAR;
-
- decimal_flag = 0;
- switch (c)
- {
- case 'b':
- if (n > ULONG_MAX/512)
- return LONGINT_OVERFLOW;
- n *= 512;
- break;
-
- case 'B':
- if (n > ULONG_MAX/102412)
- return LONGINT_OVERFLOW;
- n *= 1024;
- break;
-
- case 'c':
- break;
-
- case 'K':
- c = 'k';
- goto def;
-
- case 'm':
- c = 'M';
- /*FALLTHROUGH*/
-def:default:
- p = strchr (metric_suffixes, c);
- if (!p)
- return LONGINT_INVALID_SUFFIX_CHAR;
- /*
- * If valid_suffixes contains '0', then B (decimal) and iB (binary)
- * are allowed as "supersuffixes". Binary is the default.
- */
- if (strchr (valid_suffixes, '0'))
- {
- /* 'D' is obsolescent */
- if (end_ptr[1] == 'B' || end_ptr[1] == 'D')
- {
- decimal_flag = 1;
- end_ptr++;
- }
- else if (end_ptr[1] == 'i' && end_ptr[2] == 'B')
- end_ptr += 2;
- }
- /* Now do the scaling */
- p++;
- if (decimal_flag)
- do {
- if (n > ULONG_MAX/1000)
- return LONGINT_OVERFLOW;
- n *= 1000;
- } while (--p > metric_suffixes);
- else
- do {
- if (n > ULONG_MAX/1024)
- return LONGINT_OVERFLOW;
- n *= 1024;
- } while (--p > metric_suffixes);
- }
-
- /* Final wrapup */
- if (end)
- *end = end_ptr+1; /* Extra suffix is allowed if it's expected */
- else if (end_ptr[1])
- return LONGINT_INVALID_SUFFIX_CHAR;
- *res = n;
- return LONGINT_OK;
-}
-
-/* Dummy i18n stubs */
-# define _(x) x
-# define N_(x) x
-# define setlocale(x,y) (void) 0
-# define bindtextdomain(x,y) (void) 0
-# define textdomain(x) (void) 0
-
-/*
- * Print a message with `fprintf (stderr, FORMAT, ...)';
- * if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
- * If STATUS is nonzero, terminate the program with `exit (STATUS)'.
- */
-static void error (int status, int errnum, const char *format, ...)
- attribute ((__format__ (__printf__, 3, 4)));
-
-extern char const *program_name;
-static void
-error (int status, int errnum, const char *format, ...)
-{
- va_list ap;
-
- if (program_name)
- {
- fputs (program_name, stderr);
- fputs (": ", stderr);
- }
- va_start (ap, format);
- vfprintf (stderr, format, ap);
- va_end (ap);
- if (errnum)
- {
- fputs (": ", stderr);
- fputs (strerror (errnum), stderr);
- }
- putc ('\n', stderr);
-
- if (status)
- exit (status);
-}
-
-/*
- * GNU programs actually check for failure closing standard output.
- * This seems unnecessary, until your shell script starts hitting
- * ENOSPC and doing bizarre things with zero-length files.
- */
-static void
-close_stdout (void)
-{
- if (ferror (stdout))
- error (EXIT_FAILURE, 0, _("write error"));
- if (fclose (stdout) != 0)
- error (EXIT_FAILURE, errno, _("write error"));
-}
-
-/*
- * Quote the argument (including colon characters) into the buffer.
- * Return the buffer size used (including trailing null byte.)
- * If this is larger than the bufsize, it is an estimate of the space
- * needed.
- */
-static size_t
-quotearg_colon_buf (char const *arg, char *buf, size_t bufsize)
-{
- /* Some systems don't have \a or \e, so this is ASCII-dependent */
- static char const escaped[] = "\7\b\33\f\n\r\t\v";
- static char const escapes[] = "abefnrtv";
- int c;
- size_t pos = 0;
- char const *p;
-
- while ((c = (unsigned char) *arg++) != 0)
- {
- if (isprint (c))
- {
- if (strchr ("\\:", c)) /* Anything else we should quote? */
- if (pos++ < bufsize) *buf++ = '\\';
- }
- else
- {
- if (pos++ < bufsize) *buf++ = '\\';
- p = strchr (escaped, c); /* c is never 0, so this is okay */
- if (p)
- {
- c = escapes[p-escaped];
- }
- else
- {
- if ('0' <= *arg && *arg <= '9')
- c += 256; /* Force 3-digit form if followed by a digit */
- if (c > 077)
- if (pos++ < bufsize) *buf++ = "0123"[c>>6 & 3];
- if (c > 07)
- if (pos++ < bufsize) *buf++ = "01234567"[c>>3 & 7];
- c = "01234567"[c & 7];
- }
- }
- if (pos++ < bufsize) *buf++ = c;
- }
- if (pos++ < bufsize) *buf++ = 0;
- return pos;
-}
-
-/* Quote metacharacters in a filename */
-char const *
-quotearg_colon (char const *arg)
-{
- static char *buf = 0;
- size_t bufsize = 0;
- size_t newsize;
-
- while ((newsize = quotearg_colon_buf (arg, buf, bufsize)) > bufsize)
- {
- buf = realloc (buf, newsize);
- if (!buf)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- bufsize = newsize;
- }
- return buf;
-}
-
-void *
-xmalloc (size_t n)
-{
- void *p = malloc (n);
- if (!p)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- return p;
-}
-
-char *
-xstrdup (char const *string)
-{
- return strcpy (xmalloc (strlen (string) + 1), string);
-}
-
-#endif /* ! HAVE_CONFIG_H */
-
#ifndef O_NOCTTY
# define O_NOCTTY 0 /* This is a very optional frill */
#endif