=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/touch/touch.c,v retrieving revision 1.10 retrieving revision 1.11 diff -c -r1.10 -r1.11 *** src/usr.bin/touch/touch.c 2003/06/10 22:20:53 1.10 --- src/usr.bin/touch/touch.c 2005/04/20 19:13:53 1.11 *************** *** 1,4 **** ! /* $OpenBSD: touch.c,v 1.10 2003/06/10 22:20:53 deraadt Exp $ */ /* $NetBSD: touch.c,v 1.11 1995/08/31 22:10:06 jtc Exp $ */ /* --- 1,4 ---- ! /* $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,46 **** #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 $"; #endif /* not lint */ #include --- 40,46 ---- #if 0 static char sccsid[] = "@(#)touch.c 8.2 (Berkeley) 4/28/95"; #endif ! static char rcsid[] = "$OpenBSD: touch.c,v 1.11 2005/04/20 19:13:53 otto Exp $"; #endif /* not lint */ #include *************** *** 58,64 **** #include #include - 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 *); --- 58,63 ---- *************** *** 69,80 **** { struct stat sb; struct timeval tv[2]; ! int aflag, cflag, fflag, mflag, ch, fd, len, rval, timeset; char *p; setlocale(LC_ALL, ""); ! aflag = cflag = fflag = mflag = timeset = 0; if (gettimeofday(&tv[0], NULL)) err(1, "gettimeofday"); --- 68,79 ---- { struct stat sb; struct timeval tv[2]; ! int aflag, cflag, mflag, ch, fd, len, rval, timeset; char *p; setlocale(LC_ALL, ""); ! aflag = cflag = mflag = timeset = 0; if (gettimeofday(&tv[0], NULL)) err(1, "gettimeofday"); *************** *** 87,93 **** cflag = 1; break; case 'f': - fflag = 1; break; case 'm': mflag = 1; --- 86,91 ---- *************** *** 100,106 **** timeset = 1; stime_arg1(optarg, tv); break; - case '?': default: usage(); } --- 98,103 ---- *************** *** 175,183 **** if (!utimes(*argv, NULL)) continue; ! /* Try reading/writing. */ ! if (rw(*argv, &sb, fflag)) ! rval = 1; } exit(rval); } --- 172,179 ---- if (!utimes(*argv, NULL)) continue; ! rval = 1; ! warn("%s", *argv); } exit(rval); } *************** *** 287,345 **** 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"); exit(1); } --- 283,292 ---- TIMESPEC_TO_TIMEVAL(tvp + 1, &sb.st_mtimespec); } __dead void usage(void) { (void)fprintf(stderr, ! "usage: touch [-acm] [-r file] [-t time] file ...\n"); exit(1); }