summaryrefslogtreecommitdiff
path: root/src/touch.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-04-02 04:26:26 +0000
committerJim Meyering <jim@meyering.net>1993-04-02 04:26:26 +0000
commitee871dbed84a671bad1217b23ad3802ab023e26c (patch)
treee35f1c605334d3d40c2ea1cd67fada6cd41d9d62 /src/touch.c
parent0a6061f1f9178df1bfddaff7b25dbf5393833096 (diff)
downloadcoreutils-ee871dbed84a671bad1217b23ad3802ab023e26c.tar.xz
Add --help and --version options.
Diffstat (limited to 'src/touch.c')
-rw-r--r--src/touch.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/touch.c b/src/touch.c
index 65d76279f..7be500bdf 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -37,6 +37,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
#ifdef STDC_HEADERS
#include <time.h>
@@ -61,6 +62,9 @@ static int utime_now ();
#define CH_ATIME 1
#define CH_MTIME 2
+/* The name by which this program was run. */
+char *program_name;
+
/* Which timestamps to change. */
static int change_times;
@@ -90,8 +94,11 @@ static char *ref_file;
/* Info about the reference file. */
static struct stat ref_stats;
-/* The name by which this program was run. */
-char *program_name;
+/* If non-zero, display usage information and exit. */
+static int flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
static struct option const longopts[] =
{
@@ -99,6 +106,8 @@ static struct option const longopts[] =
{"no-create", no_argument, 0, 'c'},
{"date", required_argument, 0, 'd'},
{"file", required_argument, 0, 'r'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{0, 0, 0, 0}
};
@@ -183,6 +192,12 @@ main (argc, argv)
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (change_times == 0)
change_times = CH_ATIME | CH_MTIME;