summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1992-12-10 19:34:55 +0000
committerJim Meyering <jim@meyering.net>1992-12-10 19:34:55 +0000
commit38575ad4621f4c73c70ce1c607d031736021f3b0 (patch)
treef1c5a678885df6f96ea4f55dc6de4e39929dea13 /src
parent08c5ed9a7e032ad266e3d03a04f2200dbcc0fa8a (diff)
downloadcoreutils-38575ad4621f4c73c70ce1c607d031736021f3b0.tar.xz
Merge with pre-release 1.3.6.
Diffstat (limited to 'src')
-rw-r--r--src/csplit.c4
-rw-r--r--src/od.c16
-rw-r--r--src/sort.c31
-rw-r--r--src/tail.c27
-rw-r--r--src/tr.c6
5 files changed, 55 insertions, 29 deletions
diff --git a/src/csplit.c b/src/csplit.c
index 7b2165e5f..8d27ce03f 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -25,10 +25,6 @@
#include "regex.h"
#include "system.h"
-#if !defined(USG) && !defined(STDC_HEADERS)
-char *memchr ();
-#endif
-
#ifdef STDC_HEADERS
#include <stdlib.h>
#else
diff --git a/src/od.c b/src/od.c
index ae2c3da3b..0e9161b26 100644
--- a/src/od.c
+++ b/src/od.c
@@ -1,4 +1,4 @@
-/* od -- dump in octal (and other formats) the contents of files
+/* od -- dump files in octal and other formats
Copyright (C) 1992 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -1624,13 +1624,13 @@ main (argc, argv)
specs. GNU od accepts any combination of old- and
new-style options. Format specification options accumulate. */
-#define CASE_OLD_ARG(old_char,new_string) \
- case old_char: \
- { \
- int tmp; \
- tmp = decode_format_string (new_string); \
- assert (tmp == 0); \
- } \
+#define CASE_OLD_ARG(old_char,new_string) \
+ case old_char: \
+ { \
+ int tmp; \
+ tmp = decode_format_string (new_string); \
+ assert (tmp == 0); \
+ } \
break
CASE_OLD_ARG ('a', "a");
diff --git a/src/sort.c b/src/sort.c
index e514284b8..f4f65782f 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -107,7 +107,7 @@ static int linelength = 30;
#define LINEALLOC 262144
/* Prefix for temporary file names. */
-static char *prefix;
+static char *temp_file_prefix;
/* Flag to reverse the order of all comparisons. */
static int reverse;
@@ -292,15 +292,15 @@ static char *
tempname ()
{
static int seq;
- int len = strlen (prefix);
+ int len = strlen (temp_file_prefix);
char *name = xmalloc (len + 16);
struct tempnode *node =
(struct tempnode *) xmalloc (sizeof (struct tempnode));
- if (len && prefix[len - 1] != '/')
- sprintf (name, "%s/sort%5.5d%5.5d", prefix, getpid (), ++seq);
+ if (len && temp_file_prefix[len - 1] != '/')
+ sprintf (name, "%s/sort%5.5d%5.5d", temp_file_prefix, getpid (), ++seq);
else
- sprintf (name, "%ssort%5.5d%5.5d", prefix, getpid (), ++seq);
+ sprintf (name, "%ssort%5.5d%5.5d", temp_file_prefix, getpid (), ++seq);
node->name = name;
node->next = temphead.next;
temphead.next = node;
@@ -1427,9 +1427,9 @@ main (argc, argv)
have_read_stdin = 0;
inittables ();
- prefix = getenv ("TMPDIR");
- if (prefix == NULL)
- prefix = "/tmp";
+ temp_file_prefix = getenv ("TMPDIR");
+ if (temp_file_prefix == NULL)
+ temp_file_prefix = "/tmp";
#ifdef _POSIX_VERSION
newact.sa_handler = sighandler;
@@ -1625,6 +1625,17 @@ main (argc, argv)
else
error (2, 0, "option `-t' requires an argument");
break;
+ case 'T':
+ if (s[1])
+ temp_file_prefix = ++s;
+ else if (i < argc - 1)
+ {
+ temp_file_prefix = argv[++i];
+ goto outer;
+ }
+ else
+ error (2, 0, "option `-T' requires an argument");
+ break;
case 'u':
unique = 1;
break;
@@ -1725,8 +1736,8 @@ static void
usage ()
{
fprintf (stderr, "\
-Usage: %s [-cmus] [-t separator] [-o output-file] [-bdfiMnr] [+POS1 [-POS2]]\n\
- [-k POS1[,POS2]] [file...]\n",
+Usage: %s [-cmus] [-t separator] [-o output-file] [-T tempdir] [-bdfiMnr]\n\
+ [+POS1 [-POS2]] [-k POS1[,POS2]] [file...]\n",
program_name);
exit (2);
}
diff --git a/src/tail.c b/src/tail.c
index a94ac9c63..be0978fe4 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -43,7 +43,7 @@
Original version by Paul Rubin <phr@ocf.berkeley.edu>.
Extensions by David MacKenzie <djm@gnu.ai.mit.edu>.
- tail -f for multiple files by Ian Lance Taylor <ian@cygnus.com>. */
+ tail -f for multiple files by Ian Lance Taylor <ian@airs.com>. */
#include <stdio.h>
#include <getopt.h>
@@ -907,9 +907,22 @@ tail_forever (names, nfiles)
pids = (int *) xmalloc (nfiles * sizeof (int));
- /* fork once for each file. If this is too ugly for you, don't use
- tail -f on multiple files. Maybe we could use select as an
- alternative, though it's less portable. Is it worth the bother? */
+ /* fork once for each file. This approach uses one process and
+ one file descriptor for each file we tail.
+ More resource-efficient approaches would be:
+
+ 1. Keep an off_t array of the last-seen sizes of the files,
+ and fstat them each in turn, watching for growth.
+ This would be more portable, but still use the same number of
+ file descriptors, and would probably use more CPU.
+ For pipes, perhaps a separate process would have to be forked to
+ read from the pipe and write to a temporary file.
+
+ 2. Keep an off_t array, but only keep recently changed files open
+ and use stat for the others, opening them only if they change.
+ This would save file descriptors, to allow tail -f on a large number
+ of files. It's probably not worth the trouble for most uses, though,
+ and GNU won't have arbitrary limits on things like file descriptors. */
signal (SIGUSR1, sigusr1);
@@ -929,11 +942,11 @@ tail_forever (names, nfiles)
close (pipe_descs[0]);
/* Each child reads continually from a file and writes to
- the pipe. Each write to a pipe is the index of the file
+ the pipe. Each write to the pipe is the index of the file
being read, followed by the number of bytes read from the
- file, followed by the actual bytes. Each child is
+ file, followed by the actual data. Each child is
careful to write no more than PIPE_BUF bytes to the pipe,
- so that the data from the various children does not get
+ so that the data from the various children do not get
intermixed. */
/* The file index for this child is always the same. */
diff --git a/src/tr.c b/src/tr.c
index d0a170dfe..873a23520 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -1802,5 +1802,11 @@ deleting and squeezing repeats");
}
}
+ if (fclose (stdout) == EOF)
+ error (2, errno, "write error");
+
+ if (close (0) != 0)
+ error (2, errno, "standard input");
+
exit (0);
}