summaryrefslogtreecommitdiff
path: root/usr.bin/touch
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/touch')
-rw-r--r--usr.bin/touch/touch.17
-rw-r--r--usr.bin/touch/touch.c67
2 files changed, 9 insertions, 65 deletions
diff --git a/usr.bin/touch/touch.1 b/usr.bin/touch/touch.1
index 7c63bd5ddef..82715c347c2 100644
--- a/usr.bin/touch/touch.1
+++ b/usr.bin/touch/touch.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: touch.1,v 1.9 2003/06/10 09:12:12 jmc Exp $
+.\" $OpenBSD: touch.1,v 1.10 2005/04/20 19:13:53 otto Exp $
.\" $NetBSD: touch.1,v 1.8 1995/08/31 22:10:05 jtc Exp $
.\"
.\" Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
.Nd change file access and modification times
.Sh SYNOPSIS
.Nm touch
-.Op Fl acfm
+.Op Fl acm
.Op Fl r Ar file
.Op Fl t Ar [[CC]YY]MMDDhhmm[.SS]
.Ar file Op Ar ...
@@ -65,9 +65,6 @@ The
.Nm
utility does not treat this as an error.
No error messages are displayed and the exit value is not affected.
-.It Fl f
-Attempt to force the update, even if the file permissions do not
-currently permit it.
.It Fl m
Change the modification time of the file.
The access time of the file is not changed unless the
diff --git a/usr.bin/touch/touch.c b/usr.bin/touch/touch.c
index 1ba5036ae9b..5eb67d669c8 100644
--- a/usr.bin/touch/touch.c
+++ b/usr.bin/touch/touch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: touch.c,v 1.10 2003/06/10 22:20:53 deraadt Exp $ */
+/* $OpenBSD: touch.c,v 1.11 2005/04/20 19:13:53 otto Exp $ */
/* $NetBSD: touch.c,v 1.11 1995/08/31 22:10:06 jtc Exp $ */
/*
@@ -40,7 +40,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)touch.c 8.2 (Berkeley) 4/28/95";
#endif
-static char rcsid[] = "$OpenBSD: touch.c,v 1.10 2003/06/10 22:20:53 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: touch.c,v 1.11 2005/04/20 19:13:53 otto Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -58,7 +58,6 @@ static char rcsid[] = "$OpenBSD: touch.c,v 1.10 2003/06/10 22:20:53 deraadt Exp
#include <tzfile.h>
#include <unistd.h>
-int rw(char *, struct stat *, int);
void stime_arg1(char *, struct timeval *);
void stime_arg2(char *, int, struct timeval *);
void stime_file(char *, struct timeval *);
@@ -69,12 +68,12 @@ main(int argc, char *argv[])
{
struct stat sb;
struct timeval tv[2];
- int aflag, cflag, fflag, mflag, ch, fd, len, rval, timeset;
+ int aflag, cflag, mflag, ch, fd, len, rval, timeset;
char *p;
setlocale(LC_ALL, "");
- aflag = cflag = fflag = mflag = timeset = 0;
+ aflag = cflag = mflag = timeset = 0;
if (gettimeofday(&tv[0], NULL))
err(1, "gettimeofday");
@@ -87,7 +86,6 @@ main(int argc, char *argv[])
cflag = 1;
break;
case 'f':
- fflag = 1;
break;
case 'm':
mflag = 1;
@@ -100,7 +98,6 @@ main(int argc, char *argv[])
timeset = 1;
stime_arg1(optarg, tv);
break;
- case '?':
default:
usage();
}
@@ -175,9 +172,8 @@ main(int argc, char *argv[])
if (!utimes(*argv, NULL))
continue;
- /* Try reading/writing. */
- if (rw(*argv, &sb, fflag))
- rval = 1;
+ rval = 1;
+ warn("%s", *argv);
}
exit(rval);
}
@@ -287,59 +283,10 @@ stime_file(char *fname, struct timeval *tvp)
TIMESPEC_TO_TIMEVAL(tvp + 1, &sb.st_mtimespec);
}
-int
-rw(char *fname, struct stat *sbp, int force)
-{
- int fd, needed_chmod, rval;
- u_char byte;
-
- /* Try regular files and directories. */
- if (!S_ISREG(sbp->st_mode) && !S_ISDIR(sbp->st_mode)) {
- warnx("%s: %s", fname, strerror(EFTYPE));
- return (1);
- }
-
- needed_chmod = rval = 0;
- if ((fd = open(fname, O_RDWR, 0)) == -1) {
- if (!force || chmod(fname, DEFFILEMODE))
- goto err;
- if ((fd = open(fname, O_RDWR, 0)) == -1)
- goto err;
- needed_chmod = 1;
- }
-
- if (sbp->st_size != 0) {
- if (read(fd, &byte, sizeof(byte)) != sizeof(byte))
- goto err;
- if (lseek(fd, (off_t)0, SEEK_SET) == -1)
- goto err;
- if (write(fd, &byte, sizeof(byte)) != sizeof(byte))
- goto err;
- } else {
- if (write(fd, &byte, sizeof(byte)) != sizeof(byte)) {
-err: rval = 1;
- warn("%s", fname);
- } else if (ftruncate(fd, (off_t)0)) {
- rval = 1;
- warn("%s: file modified", fname);
- }
- }
-
- if (close(fd) && rval != 1) {
- rval = 1;
- warn("%s", fname);
- }
- if (needed_chmod && chmod(fname, sbp->st_mode) && rval != 1) {
- rval = 1;
- warn("%s: permissions modified", fname);
- }
- return (rval);
-}
-
__dead void
usage(void)
{
(void)fprintf(stderr,
- "usage: touch [-acfm] [-r file] [-t time] file ...\n");
+ "usage: touch [-acm] [-r file] [-t time] file ...\n");
exit(1);
}