Author: eadler
Date: Tue Apr 23 13:03:14 2013
New Revision: 249805
URL: http://svnweb.freebsd.org/changeset/base/249805

Log:
  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

Modified:
  head/usr.bin/touch/touch.c

Modified: head/usr.bin/touch/touch.c
==============================================================================
--- head/usr.bin/touch/touch.c  Tue Apr 23 13:03:11 2013        (r249804)
+++ head/usr.bin/touch/touch.c  Tue Apr 23 13:03:14 2013        (r249805)
@@ -56,12 +56,12 @@ static const char sccsid[] = "@(#)touch.
 #include <time.h>
 #include <unistd.h>
 
-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 *tv
        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 t
        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 *
        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] "
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to