aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorEitan Adler <eadler@FreeBSD.org>2013-04-23 13:03:14 +0000
committerEitan Adler <eadler@FreeBSD.org>2013-04-23 13:03:14 +0000
commit4145c5f17e1e48ce18a07512cb8a3ac630d287b3 (patch)
treebd9d1cd268ca2285b411cedd7046c04832aef63c /usr.bin
parente99f8bc02e3d588995a4d2b881f856424949e80a (diff)
downloadsrc-4145c5f17e1e48ce18a07512cb8a3ac630d287b3.tar.gz
src-4145c5f17e1e48ce18a07512cb8a3ac630d287b3.zip
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
Notes
Notes: svn path=/head/; revision=249805
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/touch/touch.c42
1 files changed, 22 insertions, 20 deletions
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 <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 *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] "