summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-10-04 21:20:37 +0000
committerJim Meyering <jim@meyering.net>1993-10-04 21:20:37 +0000
commit3134fad324dee63431db43cf9fc82072cb004770 (patch)
treebed6afd9e143b51ee02ee2aa84a81a020daf3e15 /src
parentae0074289cd7d70cf8fb1d96f2625b2b9bb62b29 (diff)
downloadcoreutils-3134fad324dee63431db43cf9fc82072cb004770.tar.xz
merge with 1.8.1a
Diffstat (limited to 'src')
-rw-r--r--src/echo.c2
-rw-r--r--src/expr.c54
-rw-r--r--src/pathchk.c14
-rw-r--r--src/tee.c12
-rw-r--r--src/who.c24
5 files changed, 68 insertions, 38 deletions
diff --git a/src/echo.c b/src/echo.c
index b7ca351e0..ddf3b1783 100644
--- a/src/echo.c
+++ b/src/echo.c
@@ -179,6 +179,6 @@ just_echo:
}
}
if (display_return)
- printf ("\n");
+ putchar ('\n');
exit (0);
}
diff --git a/src/expr.c b/src/expr.c
index c4fbc2161..a9f376942 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -32,6 +32,7 @@
#include <ctype.h>
#include <sys/types.h>
#include <regex.h>
+#include <getopt.h>
#include "system.h"
#include "version.h"
@@ -98,6 +99,13 @@ static void tostring ();
static void trace ();
#endif
+static struct option const long_options[] =
+{
+ {"help", no_argument, 0, 'h'},
+ {"version", no_argument, 0, 'v'},
+ {0, 0, 0, 0}
+};
+
static void
usage ()
{
@@ -106,28 +114,50 @@ usage ()
exit (1);
}
-void
-main (argc, argv)
+/* Process long options that precede all other command line arguments. */
+
+static void
+parse_long_options (argc, argv)
int argc;
char **argv;
{
- VALUE *v;
-
- program_name = argv[0];
+ int c;
- if (argc > 1)
+ while ((c = getopt_long (argc, argv, "+", long_options, (int *) 0)) != EOF)
{
- if (strcmp (argv[1], "--version") == 0)
- {
+ switch (c)
+ {
+ case 'h':
+ usage ();
+
+ case 'v':
printf ("%s\n", version_string);
exit (0);
- }
- else if (strcmp (argv[1], "--help") == 0)
- {
+
+ default:
usage ();
- }
+ }
}
+ /* Restore optind in case it has advanced past a leading `--'. We can use a
+ simple assignment here because all brances of the above switch statement
+ exit. Otherwise, we'd have to be careful to decrement only when optind
+ is larger than 1 and the last argument processed was `--'. */
+
+ optind = 1;
+}
+
+void
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ VALUE *v;
+
+ program_name = argv[0];
+
+ parse_long_options (argc, argv);
+
if (argc == 1)
usage ();
args = argv + 1;
diff --git a/src/pathchk.c b/src/pathchk.c
index 6a0bf7965..7302e3859 100644
--- a/src/pathchk.c
+++ b/src/pathchk.c
@@ -32,7 +32,7 @@
pathname and its components against the POSIX.1
minimum limits for portability, _POSIX_NAME_MAX
and _POSIX_PATH_MAX in 2.9.2. Also check that
- the pathname contains no characters not in the
+ the pathname contains no character not in the
portable filename character set.
David MacKenzie <djm@gnu.ai.mit.edu>
@@ -87,7 +87,7 @@
#define NAME_MAX_FOR(p) NAME_MAX
#endif
-char *xstrdup();
+char *xstrdup ();
void error ();
static int validate_path ();
@@ -137,7 +137,7 @@ main (argc, argv)
/* Each element is nonzero if the corresponding ASCII character is
in the POSIX portable character set, and zero if it is not.
In addition, the entry for `/' is nonzero to simplify checking. */
-static char const portable_chars[] =
+static char const portable_chars[256] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0-15 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16-31 */
@@ -161,12 +161,12 @@ static char const portable_chars[] =
static int
portable_chars_only (path)
- char *path;
+ const char *path;
{
- char *p;
+ const char *p;
for (p = path; *p; ++p)
- if (portable_chars[(unsigned char)*p] == 0)
+ if (portable_chars[(const unsigned char) *p] == 0)
{
error (0, 0, "path `%s' contains nonportable character `%c'",
path, *p);
@@ -180,7 +180,7 @@ portable_chars_only (path)
static int
dir_ok (path)
- char *path;
+ const char *path;
{
struct stat stats;
diff --git a/src/tee.c b/src/tee.c
index b97821c8d..941507fec 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -77,23 +77,23 @@ Usage: %s [-ai] [--append] [--ignore-interrupts] [file...]\n",
}
if (ignore_interrupts)
-#ifdef _POSIX_VERSION
{
+#ifdef _POSIX_VERSION
struct sigaction sigact;
sigact.sa_handler = SIG_IGN;
sigemptyset (&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction (SIGINT, &sigact, NULL);
- }
#else /* !_POSIX_VERSION */
- signal (SIGINT, SIG_IGN);
+ signal (SIGINT, SIG_IGN);
#endif /* _POSIX_VERSION */
+ }
errs = tee (argc - optind, &argv[optind]);
- if (close (0) == -1)
+ if (close (0) != 0)
error (1, errno, "standard input");
- if (close (1) == -1)
+ if (close (1) != 0)
error (1, errno, "standard output");
exit (errs);
}
@@ -143,7 +143,7 @@ tee (nfiles, files)
}
for (i = 0; i < nfiles; i++)
- if (descriptors[i] != -1 && close (descriptors[i]) == -1)
+ if (descriptors[i] != -1 && close (descriptors[i]) != 0)
{
error (0, errno, "%s", files[i]);
ret = 1;
diff --git a/src/who.c b/src/who.c
index 381a51f50..1edec4e67 100644
--- a/src/who.c
+++ b/src/who.c
@@ -57,12 +57,12 @@
#define MESG_BIT 020 /* Group write bit. */
-char *idle_string ();
char *xmalloc ();
void error ();
+char *ttyname ();
-
-static char *ttyname ();
+static int read_utmp ();
+static char *idle_string ();
static struct utmp *search_entries ();
static void list_entries ();
static void print_entry ();
@@ -222,7 +222,7 @@ read_utmp (filename)
if (read (desc, utmp_contents, file_stats.st_size) < file_stats.st_size)
error (1, errno, "%s", filename);
- if (close (desc))
+ if (close (desc) != 0)
error (1, errno, "%s", filename);
return file_stats.st_size / sizeof (struct utmp);
@@ -253,12 +253,12 @@ print_entry (this)
}
printf ("%-*.*s",
- sizeof (this->ut_name), sizeof (this->ut_name),
+ (int) sizeof (this->ut_name), (int) sizeof (this->ut_name),
this->ut_name);
if (include_mesg)
printf (" %c ", mesg);
printf (" %-*.*s",
- sizeof (this->ut_line), sizeof (this->ut_line),
+ (int) sizeof (this->ut_line), (int) sizeof (this->ut_line),
this->ut_line);
printf (" %-12.12s", ctime (&this->ut_time) + 4);
if (include_idle)
@@ -270,7 +270,7 @@ print_entry (this)
}
#ifdef HAVE_UT_HOST
if (this->ut_host[0])
- printf (" (%-.*s)", sizeof (this->ut_host), this->ut_host);
+ printf (" (%-.*s)", (int) sizeof (this->ut_host), this->ut_host);
#endif
putchar ('\n');
@@ -307,10 +307,10 @@ print_heading ()
{
struct utmp *ut;
- printf ("%-*s ", sizeof (ut->ut_name), "USER");
+ printf ("%-*s ", (int) sizeof (ut->ut_name), "USER");
if (include_mesg)
printf ("MESG ");
- printf ("%-*s ", sizeof (ut->ut_line), "LINE");
+ printf ("%-*s ", (int) sizeof (ut->ut_line), "LINE");
printf ("LOGIN-TIME ");
if (include_idle)
printf ("IDLE ");
@@ -381,7 +381,7 @@ who_am_i (filename)
if (include_heading)
{
- printf ("%*s ", strlen (hostname), " ");
+ printf ("%*s ", (int) strlen (hostname), " ");
print_heading ();
}
@@ -418,8 +418,8 @@ idle_string (when)
if (seconds_idle < (24 * 60 * 60)) /* One day. */
{
sprintf (idle, "%02d:%02d",
- seconds_idle / (60 * 60),
- (seconds_idle % (60 * 60)) / 60);
+ (int) (seconds_idle / (60 * 60)),
+ (int) ((seconds_idle % (60 * 60)) / 60));
return idle;
}
return " old ";