From 4145c5f17e1e48ce18a07512cb8a3ac630d287b3 Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Tue, 23 Apr 2013 13:03:14 +0000 Subject: Cleanups to touch.c - use const where appropriate - use static where appropriate - use explicit checks checks for error conditions Reviewed by: sbruno Approved by: cperciva (mentor) Obtained by: DragonFlyBSD --- usr.bin/touch/touch.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/touch/touch.c b/usr.bin/touch/touch.c index d42d9af2c772..72d703d9258d 100644 --- a/usr.bin/touch/touch.c +++ b/usr.bin/touch/touch.c @@ -56,12 +56,12 @@ static const char sccsid[] = "@(#)touch.c 8.1 (Berkeley) 6/6/93"; #include #include -void stime_arg1(char *, struct timeval *); -void stime_arg2(char *, int, struct timeval *); -void stime_darg(char *, struct timeval *); -void stime_file(char *, struct timeval *); -int timeoffset(char *); -void usage(char *); +static void stime_arg1(const char *, struct timeval *); +static void stime_arg2(const char *, int, struct timeval *); +static void stime_darg(const char *, struct timeval *); +static void stime_file(const char *, struct timeval *); +static int timeoffset(const char *); +static void usage(char *); int main(int argc, char *argv[]) @@ -78,7 +78,7 @@ main(int argc, char *argv[]) Aflag = aflag = cflag = mflag = timeset = 0; stat_f = stat; utimes_f = utimes; - if (gettimeofday(&tv[0], NULL)) + if (gettimeofday(&tv[0], NULL) == -1) err(1, "gettimeofday"); while ((ch = getopt(argc, argv, "A:acd:fhmr:t:")) != -1) @@ -115,7 +115,6 @@ main(int argc, char *argv[]) timeset = 1; stime_arg1(optarg, tv); break; - case '?': default: usage(myname); } @@ -235,8 +234,8 @@ main(int argc, char *argv[]) #define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; -void -stime_arg1(char *arg, struct timeval *tvp) +static void +stime_arg1(const char *arg, struct timeval *tvp) { time_t now; struct tm *t; @@ -290,14 +289,17 @@ stime_arg1(char *arg, struct timeval *tvp) t->tm_isdst = -1; /* Figure out DST. */ tvp[0].tv_sec = tvp[1].tv_sec = mktime(t); if (tvp[0].tv_sec == -1) -terr: errx(1, - "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]"); + goto terr; tvp[0].tv_usec = tvp[1].tv_usec = 0; + return; + +terr: + errx(1, "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]"); } -void -stime_arg2(char *arg, int year, struct timeval *tvp) +static void +stime_arg2(const char *arg, int year, struct timeval *tvp) { time_t now; struct tm *t; @@ -326,8 +328,8 @@ stime_arg2(char *arg, int year, struct timeval *tvp) tvp[0].tv_usec = tvp[1].tv_usec = 0; } -void -stime_darg(char *arg, struct timeval *tvp) +static void +stime_darg(const char *arg, struct timeval *tvp) { struct tm t = { .tm_sec = 0 }; const char *fmt, *colon; @@ -372,7 +374,7 @@ bad: /* Calculate a time offset in seconds, given an arg of the format [-]HHMMSS. */ int -timeoffset(char *arg) +timeoffset(const char *arg) { int offset; int isneg; @@ -400,8 +402,8 @@ timeoffset(char *arg) return (offset); } -void -stime_file(char *fname, struct timeval *tvp) +static void +stime_file(const char *fname, struct timeval *tvp) { struct stat sb; @@ -411,7 +413,7 @@ stime_file(char *fname, struct timeval *tvp) TIMESPEC_TO_TIMEVAL(tvp + 1, &sb.st_mtim); } -void +static void usage(char *myname) { fprintf(stderr, "usage: %s [-A [-][[hh]mm]SS] [-achm] [-r file] " -- cgit v1.2.3