From 686e1a443a8b1ba83917c42879672abe732e955c Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 21 Oct 2010 21:08:57 +0000 Subject: [PATCH] file_cmds-212.tar.gz --- Makefile | 8 ++- chflags/Makefile | 2 +- chflags/chflags.1 | 42 +++++++++++---- chflags/chflags.c | 67 ++++++++++++----------- chmod/Makefile | 2 +- chmod/chmod_acl.c | 11 +++- chown/Makefile | 2 +- cksum/Makefile | 2 +- compress/Makefile | 2 +- cp/Makefile | 2 +- dd/Makefile | 2 +- dd/args.c | 8 +-- df/Makefile | 2 +- du/Makefile | 2 +- du/du.c | 2 +- install/Makefile | 2 +- ipcrm/Makefile | 2 +- ipcrm/ipcrm.c | 2 +- ipcs/Makefile | 2 +- ln/Makefile | 2 +- ls/Makefile | 6 +-- ls/extern.h | 1 - ls/humanize_number.c | 148 --------------------------------------------------- ls/ls.h | 8 --- ls/print.c | 6 +-- mkdir/Makefile | 2 +- mkfifo/Makefile | 2 +- mknod/Makefile | 2 +- mtree/Makefile | 2 +- mv/Makefile | 2 +- pathchk/Makefile | 2 +- pax/Makefile | 2 +- pax/options.c | 12 ++--- rm/Makefile | 2 +- rmdir/Makefile | 2 +- rmt/Makefile | 2 +- stat/Makefile | 2 +- touch/Makefile | 2 +- touch/touch.1 | 95 ++++++++++++++++++++++++++------- touch/touch.c | 147 ++++++++++++++++++++++++++++++++++++-------------- 40 files changed, 304 insertions(+), 309 deletions(-) delete mode 100644 ls/humanize_number.c diff --git a/Makefile b/Makefile index 0f1207b..3253a66 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,13 @@ Project = file_cmds SubProjects = chflags chmod chown cksum compress cp dd df du install \ - ipcrm ipcs ln ls mkdir mkfifo mknod mtree mv pathchk pax rm \ + ipcrm ipcs ln ls mkdir mkfifo mknod mv pathchk pax rm \ rmdir shar stat touch +Embedded = $(shell tconf --test TARGET_OS_EMBEDDED) +ifneq ($(Embedded),YES) + #libcrypto missing + SubProjects += mtree +endif + include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/chflags/Makefile b/chflags/Makefile index 00f6bf6..3fe0c37 100644 --- a/chflags/Makefile +++ b/chflags/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = chflags.c MANPAGES = chflags.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/chflags/chflags.1 b/chflags/chflags.1 index 45d65a4..5eb3dfc 100644 --- a/chflags/chflags.1 +++ b/chflags/chflags.1 @@ -30,9 +30,9 @@ .\" SUCH DAMAGE. .\" .\" @(#)chflags.1 8.4 (Berkeley) 5/2/95 -.\" $FreeBSD: src/bin/chflags/chflags.1,v 1.25 2005/06/14 08:25:54 ru Exp $ +.\" $FreeBSD: src/bin/chflags/chflags.1,v 1.30.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $ .\" -.Dd May 14, 2005 +.Dd March 3, 2006 .Dt CHFLAGS 1 .Os .Sh NAME @@ -40,6 +40,7 @@ .Nd change file flags .Sh SYNOPSIS .Nm +.Op Fl fhv .Oo .Fl R .Op Fl H | Fl L | Fl P @@ -56,11 +57,22 @@ operand. .Pp The options are as follows: .Bl -tag -width indent +.It Fl f +Do not display a diagnostic message if +.Nm +could not modify the flags for +.Va file , +nor modify the exit status to reflect such failures. .It Fl H If the .Fl R option is specified, symbolic links on the command line are followed. (Symbolic links encountered in the tree traversal are not followed.) +.It Fl h +If the +.Ar file +is a symbolic link, +change the file flags of the link itself rather than the file to which it points. .It Fl L If the .Fl R @@ -73,29 +85,37 @@ This is the default. .It Fl R Change the file flags for the file hierarchies rooted in the files instead of just the files themselves. +.It Fl v +Cause +.Nm +to be verbose, showing filenames as the flags are modified. +If the +.Fl v +option is specified more than once, the old and new flags of the file +will also be printed, in octal notation. .El .Pp The flags are specified as an octal number or a comma separated list of keywords. The following keywords are currently defined: .Pp -.Bl -tag -offset indent -width ".Ar opaque" -.It Ar arch , archived +.Bl -tag -offset indent -width ".Cm opaque" +.It Cm arch , archived set the archived flag (super-user only) -.It Ar opaque +.It Cm opaque set the opaque flag (owner or super-user only). [Directory is opaque when viewed through a union mount] -.It Ar nodump +.It Cm nodump set the nodump flag (owner or super-user only) -.It Ar sappnd , sappend +.It Cm sappnd , sappend set the system append-only flag (super-user only) -.It Ar schg , schange , simmutable +.It Cm schg , schange , simmutable set the system immutable flag (super-user only) -.It Ar uappnd , uappend +.It Cm uappnd , uappend set the user append-only flag (owner or super-user only) -.It Ar uchg , uchange , uimmutable +.It Cm uchg , uchange , uimmutable set the user immutable flag (owner or super-user only) -.It Ar hidden +.It Cm hidden set the hidden flag [Hide item from GUI] .El diff --git a/chflags/chflags.c b/chflags/chflags.c index 216b945..76c8027 100644 --- a/chflags/chflags.c +++ b/chflags/chflags.c @@ -40,7 +40,7 @@ static char sccsid[] = "@(#)chflags.c 8.5 (Berkeley) 4/1/94"; #endif #include -__FBSDID("$FreeBSD: src/bin/chflags/chflags.c,v 1.23 2005/05/14 23:23:10 dd Exp $"); +__FBSDID("$FreeBSD: src/bin/chflags/chflags.c,v 1.26.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $"); #include #include @@ -53,25 +53,22 @@ __FBSDID("$FreeBSD: src/bin/chflags/chflags.c,v 1.23 2005/05/14 23:23:10 dd Exp #include #include -void usage(void); +static void usage(void); int main(int argc, char *argv[]) { FTS *ftsp; FTSENT *p; - u_long clear, set; + u_long clear, newflags, set; long val; - int Hflag, Lflag, Rflag, hflag, ch, fts_options, oct, rval; + int Hflag, Lflag, Rflag, fflag, hflag, vflag; + int ch, fts_options, oct, rval; char *flags, *ep; int (*change_flags)(const char *, u_int); - Hflag = Lflag = Rflag = hflag = 0; -#ifdef __APPLE__ - while ((ch = getopt(argc, argv, "HLPR")) != -1) -#else /* !__APPLE__ */ - while ((ch = getopt(argc, argv, "HLPRh")) != -1) -#endif /* __APPLE__ */ + Hflag = Lflag = Rflag = fflag = hflag = vflag = 0; + while ((ch = getopt(argc, argv, "HLPRfhv")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -87,11 +84,15 @@ main(int argc, char *argv[]) case 'R': Rflag = 1; break; -#ifndef __APPLE__ + case 'f': + fflag = 1; + break; case 'h': hflag = 1; break; -#endif /* !__APPLE__ */ + case 'v': + vflag++; + break; case '?': default: usage(); @@ -114,14 +115,11 @@ main(int argc, char *argv[]) fts_options |= FTS_LOGICAL; } } else - fts_options = FTS_LOGICAL; + fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL; - /* XXX: Why don't chflags and lchflags have compatible prototypes? */ -#ifndef __APPLE__ if (hflag) - change_flags = (int (*)(const char *, u_int))lchflags; + change_flags = lchflags; else -#endif /* !__APPLE__ */ change_flags = chflags; flags = *argv; @@ -174,32 +172,33 @@ main(int argc, char *argv[]) default: break; } - if (oct) { - if (!(*change_flags)(p->fts_accpath, set)) - continue; - } else { - p->fts_statp->st_flags |= set; - p->fts_statp->st_flags &= clear; - if (!(*change_flags)(p->fts_accpath, - (u_long)p->fts_statp->st_flags)) - continue; + if (oct) + newflags = set; + else + newflags = (p->fts_statp->st_flags | set) & clear; + if (newflags == p->fts_statp->st_flags) + continue; + if ((*change_flags)(p->fts_accpath, (u_int)newflags) && !fflag) { + warn("%s", p->fts_path); + rval = 1; + } else if (vflag) { + (void)printf("%s", p->fts_path); + if (vflag > 1) + (void)printf(": 0%lo -> 0%lo", + (u_long)p->fts_statp->st_flags, + newflags); + (void)printf("\n"); } - warn("%s", p->fts_path); - rval = 1; } if (errno) err(1, "fts_read"); exit(rval); } -void +static void usage(void) { (void)fprintf(stderr, -#ifdef __APPLE__ - "usage: chflags [-R [-H | -L | -P]] flags file ...\n"); -#else /* !__APPLE__ */ - "usage: chflags [-h] [-R [-H | -L | -P]] flags file ...\n"); -#endif /* __APPLE__ */ + "usage: chflags [-fhv] [-R [-H | -L | -P]] flags file ...\n"); exit(1); } diff --git a/chmod/Makefile b/chmod/Makefile index 1109dc0..559dc75 100644 --- a/chmod/Makefile +++ b/chmod/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = chmod.c chmod_acl.c MANPAGES = chmod.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/chmod/chmod_acl.c b/chmod/chmod_acl.c index 16ed9f2..dd9f51e 100644 --- a/chmod/chmod_acl.c +++ b/chmod/chmod_acl.c @@ -362,9 +362,16 @@ compare_acl_entries(acl_entry_t a, acl_entry_t b) acl_permset_t aperms, bperms; acl_flagset_t aflags, bflags; int pcmp = 0, fcmp = 0; + void *aqual, *bqual; - if (0 != compare_acl_qualifiers(acl_get_qualifier(a), - acl_get_qualifier(b))) + aqual = acl_get_qualifier(a); + bqual = acl_get_qualifier(b); + + int compare = compare_acl_qualifiers(aqual, bqual); + acl_free(aqual); + acl_free(bqual); + + if (compare != 0) return MATCH_NONE; if (0 != acl_get_tag_type(a, &atag)) diff --git a/chown/Makefile b/chown/Makefile index a399809..fac4c1d 100644 --- a/chown/Makefile +++ b/chown/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/sbin CFILES = chown.c MANPAGES = chgrp.1 chown.8 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/cksum/Makefile b/cksum/Makefile index 8f3bb25..7f86cfe 100644 --- a/cksum/Makefile +++ b/cksum/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = cksum.c crc.c print.c sum1.c sum2.c crc32.c MANPAGES = cksum.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/compress/Makefile b/compress/Makefile index 3ed5f11..f334eb5 100644 --- a/compress/Makefile +++ b/compress/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = compress.c zopen.c MANPAGES = compress.1 uncompress.1 zopen.3 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/cp/Makefile b/cp/Makefile index 9a7b78d..3975d2a 100644 --- a/cp/Makefile +++ b/cp/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = cp.c utils.c MANPAGES = cp.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/dd/Makefile b/dd/Makefile index caf5162..d7a181e 100644 --- a/dd/Makefile +++ b/dd/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = args.c conv.c conv_tab.c dd.c misc.c position.c MANPAGES = dd.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/dd/args.c b/dd/args.c index e7e0627..646dffd 100644 --- a/dd/args.c +++ b/dd/args.c @@ -188,7 +188,7 @@ f_bs(char *arg) res = get_num(arg); if (res < 1 || res > SSIZE_MAX) - errx(1, "bs must be between 1 and %d", SSIZE_MAX); + errx(1, "bs must be between 1 and %ld", SSIZE_MAX); in.dbsz = out.dbsz = (size_t)res; } @@ -199,7 +199,7 @@ f_cbs(char *arg) res = get_num(arg); if (res < 1 || res > SSIZE_MAX) - errx(1, "cbs must be between 1 and %d", SSIZE_MAX); + errx(1, "cbs must be between 1 and %ld", SSIZE_MAX); cbsz = (size_t)res; } @@ -231,7 +231,7 @@ f_ibs(char *arg) if (!(ddflags & C_BS)) { res = get_num(arg); if (res < 1 || res > SSIZE_MAX) - errx(1, "ibs must be between 1 and %d", SSIZE_MAX); + errx(1, "ibs must be between 1 and %ld", SSIZE_MAX); in.dbsz = (size_t)res; } } @@ -251,7 +251,7 @@ f_obs(char *arg) if (!(ddflags & C_BS)) { res = get_num(arg); if (res < 1 || res > SSIZE_MAX) - errx(1, "obs must be between 1 and %d", SSIZE_MAX); + errx(1, "obs must be between 1 and %ld", SSIZE_MAX); out.dbsz = (size_t)res; } } diff --git a/df/Makefile b/df/Makefile index 106c8bf..760bd4b 100644 --- a/df/Makefile +++ b/df/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = df.c vfslist.c MANPAGES = df.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Werror -Wall \ -D__FBSDID=__RCSID \ "-I$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders" \ -D_DARWIN_USE_64_BIT_INODE diff --git a/du/Makefile b/du/Makefile index ca11e95..51bd2c5 100644 --- a/du/Makefile +++ b/du/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = du.c MANPAGES = du.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/du/du.c b/du/du.c index 966a986..66820a8 100644 --- a/du/du.c +++ b/du/du.c @@ -727,7 +727,7 @@ ignorep(FTSENT *ent) if (S_ISDIR(ent->fts_statp->st_mode) && !strcmp("fd", ent->fts_name)) { struct statfs sfsb; int rc = statfs(ent->fts_accpath, &sfsb); - if (rc >= 0 && !strcmp("fdesc", sfsb.f_fstypename)) { + if (rc >= 0 && !strcmp("devfs", sfsb.f_fstypename)) { /* Don't cd into /dev/fd/N since one of those is likely to be the cwd as of the start of du which causes all manner of unpleasant surprises */ diff --git a/install/Makefile b/install/Makefile index bd8a807..63bea44 100644 --- a/install/Makefile +++ b/install/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = xinstall.c MANPAGES = install.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID \ +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID \ -include TargetConditionals.h -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip diff --git a/ipcrm/Makefile b/ipcrm/Makefile index 5b64948..ee49747 100644 --- a/ipcrm/Makefile +++ b/ipcrm/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = ipcrm.c MANPAGES = ipcrm.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/ipcrm/ipcrm.c b/ipcrm/ipcrm.c index be2d3be..3b3cb8f 100644 --- a/ipcrm/ipcrm.c +++ b/ipcrm/ipcrm.c @@ -163,7 +163,7 @@ int main(argc, argv) if (result < 0) { errflg++; if (!signaled) - warn("%s key(%ld): ", IPC_TO_STRING(c), target_key); + warn("%s key(%d): ", IPC_TO_STRING(c), target_key); else warnx("%ss are not configured in the running kernel", IPC_TO_STRING(c)); diff --git a/ipcs/Makefile b/ipcs/Makefile index ae8c819..d56d25b 100644 --- a/ipcs/Makefile +++ b/ipcs/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = ipcs.c MANPAGES = ipcs.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Werror -Wall \ -D__FBSDID=__RCSID \ -iquote \ "$(SDKROOT)/System/Library/Frameworks/Kernel.framework/PrivateHeaders" \ diff --git a/ln/Makefile b/ln/Makefile index 42c5c46..d78e834 100644 --- a/ln/Makefile +++ b/ln/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = ln.c MANPAGES = ln.1 symlink.7 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/ls/Makefile b/ls/Makefile index 77669a2..0d83deb 100644 --- a/ls/Makefile +++ b/ls/Makefile @@ -1,16 +1,16 @@ Project = ls Install_Dir = /bin -CFILES = cmp.c ls.c print.c util.c humanize_number.c +CFILES = cmp.c ls.c print.c util.c MANPAGES = ls.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Werror -Wall \ -D__FBSDID=__RCSID \ "-I$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders" \ -DCOLORLS \ -D_DARWIN_USE_64_BIT_INODE \ -include TargetConditionals.h Extra_LD_Flags = -dead_strip \ - -lncurses + -lncurses -lutil include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/ls/extern.h b/ls/extern.h index 48d3a47..6c77558 100644 --- a/ls/extern.h +++ b/ls/extern.h @@ -44,7 +44,6 @@ int statcmp(const FTSENT *, const FTSENT *); int revstatcmp(const FTSENT *, const FTSENT *); int sizecmp (const FTSENT *, const FTSENT *); int revsizecmp (const FTSENT *, const FTSENT *); -int humanize_number(char *, size_t, int64_t, const char *, int, int); int birthcmp(const FTSENT *, const FTSENT *); int revbirthcmp(const FTSENT *, const FTSENT *); diff --git a/ls/humanize_number.c b/ls/humanize_number.c deleted file mode 100644 index f855a4b..0000000 --- a/ls/humanize_number.c +++ /dev/null @@ -1,148 +0,0 @@ -/* $NetBSD: humanize_number.c,v 1.8 2004/07/27 01:56:24 enami Exp $ */ - -/* - * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, - * NASA Ames Research Center, by Luke Mewburn and by Tomas Svensson. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ls.h" - -int -humanize_number(char *buf, size_t len, int64_t bytes, - const char *suffix, int scale, int flags) -{ - const char *prefixes, *sep; - int b, i, r, maxscale, s1, s2, sign; - int64_t divisor, max; - size_t baselen; - - assert(buf != NULL); - assert(suffix != NULL); - assert(scale >= 0); - - if (flags & HN_DIVISOR_1000) { - /* SI for decimal multiplies */ - divisor = 1000; - if (flags & HN_B) - prefixes = "B\0k\0M\0G\0T\0P\0E"; - else - prefixes = "\0\0k\0M\0G\0T\0P\0E"; - } else { - /* - * binary multiplies - * XXX IEC 60027-2 recommends Ki, Mi, Gi... - */ - divisor = 1024; - if (flags & HN_B) - prefixes = "B\0K\0M\0G\0T\0P\0E"; - else - prefixes = "\0\0K\0M\0G\0T\0P\0E"; - } - -#define SCALE2PREFIX(scale) (&prefixes[(scale) << 1]) - maxscale = 7; - - if (scale >= maxscale && - (scale & (HN_AUTOSCALE | HN_GETSCALE)) == 0) - return (-1); - - if (buf == NULL || suffix == NULL) - return (-1); - - if (len > 0) - buf[0] = '\0'; - if (bytes < 0) { - sign = -1; - bytes *= -100; - baselen = 3; /* sign, digit, prefix */ - } else { - sign = 1; - bytes *= 100; - baselen = 2; /* digit, prefix */ - } - if (flags & HN_NOSPACE) - sep = ""; - else { - sep = " "; - baselen++; - } - baselen += strlen(suffix); - - /* Check if enough room for `x y' + suffix + `\0' */ - if (len < baselen + 1) - return (-1); - - if (scale & (HN_AUTOSCALE | HN_GETSCALE)) { - /* See if there is additional columns can be used. */ - for (max = 100, i = len - baselen; i-- > 0;) - max *= 10; - - for (i = 0; bytes >= max && i < maxscale; i++) - bytes /= divisor; - - if (scale & HN_GETSCALE) - return (i); - } else - for (i = 0; i < scale && i < maxscale; i++) - bytes /= divisor; - - /* If a value <= 9.9 after rounding and ... */ - if (bytes < 995 && i > 0 && flags & HN_DECIMAL) { - /* baselen + \0 + .N */ - if (len < baselen + 1 + 2) - return (-1); - b = ((int)bytes + 5) / 10; - s1 = b / 10; - s2 = b % 10; - r = snprintf(buf, len, "%d%s%d%s%s%s", - sign * s1, localeconv()->decimal_point, s2, - sep, SCALE2PREFIX(i), suffix); - } else - r = snprintf(buf, len, "%lld%s%s%s", - /* LONGLONG */ - (long long)(sign * ((bytes + 50) / 100)), - sep, SCALE2PREFIX(i), suffix); - - return (r); -} diff --git a/ls/ls.h b/ls/ls.h index 137c793..246470b 100644 --- a/ls/ls.h +++ b/ls/ls.h @@ -40,14 +40,6 @@ #define NO_PRINT 1 -#define HN_DECIMAL 0x01 -#define HN_NOSPACE 0x02 -#define HN_B 0x04 -#define HN_DIVISOR_1000 0x08 - -#define HN_GETSCALE 0x10 -#define HN_AUTOSCALE 0x20 - extern long blocksize; /* block size units */ extern int f_accesstime; /* use time of last access */ diff --git a/ls/print.c b/ls/print.c index 31e06d6..2fdd31c 100644 --- a/ls/print.c +++ b/ls/print.c @@ -62,6 +62,7 @@ __RCSID("$FreeBSD: src/bin/ls/print.c,v 1.57 2002/08/29 14:29:09 keramida Exp $" #include #include #include +#include #include #include #include @@ -287,17 +288,16 @@ printacl(acl_t acl, int isdir) for (index = 0; acl_get_entry(acl, entry == NULL ? ACL_FIRST_ENTRY : ACL_NEXT_ENTRY, &entry) == 0; index++) { - if ((applicable = (uuid_t *) acl_get_qualifier(entry)) == NULL) - continue; if (acl_get_tag_type(entry, &tag) != 0) continue; if (acl_get_flagset_np(entry, &flags) != 0) continue; if (acl_get_permset(entry, &perms) != 0) continue; + if ((applicable = (uuid_t *) acl_get_qualifier(entry)) == NULL) + continue; name = uuid_to_name(applicable); acl_free(applicable); - switch(tag) { case ACL_EXTENDED_ALLOW: type = "allow"; diff --git a/mkdir/Makefile b/mkdir/Makefile index f5dcf8d..fc8caf1 100644 --- a/mkdir/Makefile +++ b/mkdir/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = mkdir.c MANPAGES = mkdir.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/mkfifo/Makefile b/mkfifo/Makefile index 11447dc..7c5cfda 100644 --- a/mkfifo/Makefile +++ b/mkfifo/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = mkfifo.c MANPAGES = mkfifo.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/mknod/Makefile b/mknod/Makefile index 4eb0d6d..8e17cfc 100644 --- a/mknod/Makefile +++ b/mknod/Makefile @@ -4,7 +4,7 @@ Install_Dir = /sbin CFILES = mknod.c MANPAGES = mknod.8 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/mtree/Makefile b/mtree/Makefile index 1139f00..c7abeb9 100644 --- a/mtree/Makefile +++ b/mtree/Makefile @@ -6,7 +6,7 @@ CFILES = compare.c create.c excludes.c misc.c mtree.c spec.c specspec.c \ ../cksum/crc.c MANPAGES = mtree.8 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Werror -Wall \ -D__FBSDID=__RCSID \ -DENABLE_MD5 \ -DENABLE_RMD160 \ diff --git a/mv/Makefile b/mv/Makefile index 9f8f930..25de548 100644 --- a/mv/Makefile +++ b/mv/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = mv.c MANPAGES = mv.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/pathchk/Makefile b/pathchk/Makefile index 511c2d5..ffe5ac3 100644 --- a/pathchk/Makefile +++ b/pathchk/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = pathchk.c MANPAGES = pathchk.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/pax/Makefile b/pax/Makefile index f2863cc..bd6132d 100644 --- a/pax/Makefile +++ b/pax/Makefile @@ -6,7 +6,7 @@ CFILES = ar_io.c ar_subs.c buf_subs.c cache.c cpio.c file_subs.c\ sel_subs.c tables.c tar.c tty_subs.c pax_format.c MANPAGES = pax.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/pax/options.c b/pax/options.c index 854d8dc..0b5b988 100644 --- a/pax/options.c +++ b/pax/options.c @@ -76,7 +76,7 @@ static int no_op(void); static void printflg(unsigned int); static int c_frmt(const void *, const void *); static off_t str_offt(char *); -static char *getline(FILE *fp); +static char *pax_getline(FILE *fp); static void pax_options(int, char **); void pax_usage(void); static void tar_options(int, char **); @@ -942,7 +942,7 @@ tar_options(int argc, char **argv) paxwarn(1, "Unable to open file '%s' for read", file); tar_usage(); } - while ((str = getline(fp)) != NULL) { + while ((str = pax_getline(fp)) != NULL) { if (pat_add(str, dir) < 0) tar_usage(); sawpat = 1; @@ -1021,7 +1021,7 @@ tar_options(int argc, char **argv) paxwarn(1, "Unable to open file '%s' for read", file); tar_usage(); } - while ((str = getline(fp)) != NULL) { + while ((str = pax_getline(fp)) != NULL) { if (ftree_add(str, 0) < 0) tar_usage(); } @@ -1244,7 +1244,7 @@ cpio_options(int argc, char **argv) paxwarn(1, "Unable to open file '%s' for read", optarg); cpio_usage(); } - while ((str = getline(fp)) != NULL) { + while ((str = pax_getline(fp)) != NULL) { pat_add(str, NULL); } fclose(fp); @@ -1344,7 +1344,7 @@ cpio_options(int argc, char **argv) * no read errors allowed on updates/append operation! */ maxflt = 0; - while ((str = getline(stdin)) != NULL) { + while ((str = pax_getline(stdin)) != NULL) { ftree_add(str, 0); } if (getline_error) { @@ -1651,7 +1651,7 @@ str_offt(char *val) } char * -getline(FILE *f) +pax_getline(FILE *f) { char *name, *temp; size_t len; diff --git a/rm/Makefile b/rm/Makefile index 5e8cf03..0bf8474 100644 --- a/rm/Makefile +++ b/rm/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = rm.c MANPAGES = rm.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/rmdir/Makefile b/rmdir/Makefile index d959064..063a2d2 100644 --- a/rmdir/Makefile +++ b/rmdir/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = rmdir.c MANPAGES = rmdir.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/rmt/Makefile b/rmt/Makefile index a0874d1..ac35b5c 100644 --- a/rmt/Makefile +++ b/rmt/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/sbin CFILES = rmt.c MANPAGES = rmt.8 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/stat/Makefile b/stat/Makefile index 3b4de1d..005eb79 100644 --- a/stat/Makefile +++ b/stat/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = stat.c MANPAGES = stat.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/touch/Makefile b/touch/Makefile index 780be63..2f34232 100644 --- a/touch/Makefile +++ b/touch/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = touch.c MANPAGES = touch.1 -Extra_CC_Flags = -Werror -Wall -mdynamic-no-pic -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE +Extra_CC_Flags = -Werror -Wall -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/touch/touch.1 b/touch/touch.1 index cf6d863..6e6678b 100644 --- a/touch/touch.1 +++ b/touch/touch.1 @@ -33,7 +33,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)touch.1 8.3 (Berkeley) 4/28/95 -.\" $FreeBSD: src/usr.bin/touch/touch.1,v 1.11 2001/09/24 17:42:37 obrien Exp $ +.\" $FreeBSD: src/usr.bin/touch/touch.1,v 1.16 2007/04/10 07:24:47 grog Exp $ .\" .Dd April 28, 1995 .Dt TOUCH 1 @@ -43,19 +43,65 @@ .Nd change file access and modification times .Sh SYNOPSIS .Nm -.Op Fl acfm +.Op Fl A Ar [-][[hh]mm]SS +.Op Fl acfhm .Op Fl r Ar file .Op Fl t Ar [[CC]YY]MMDDhhmm[.SS] .Ar .Sh DESCRIPTION The .Nm -utility sets the modification and access times of files to the -current time of day. -If the file doesn't exist, it is created with default permissions. +utility sets the modification and access times of files. +If any file does not exist, it is created with default permissions. +.Pp +By default, +.Nm +changes both modification and access times. The +.Fl a +and +.Fl m +flags may be used to select the access time or the modification time +individually. +Selecting both is equivalent to the default. +By default, the timestamps are set to the current time. +The +.Fl t +flag explicitly specifies a different time, and the +.Fl r +flag specifies to set the times those of the specified file. +The +.Fl A +flag adjusts the values by a specified amount. .Pp The following options are available: .Bl -tag -width Ds +.It Fl A +Adjust the access and modification time stamps for the file by the +specified value. +This flag is intended for use in modifying files with incorrectly set +time stamps. +.Pp +The argument is of the form +.Dq [-][[hh]mm]SS +where each pair of letters represents the following: +.Pp +.Bl -tag -width Ds -compact -offset indent +.It Ar - +Make the adjustment negative: the new time stamp is set to be before +the old one. +.It Ar hh +The number of hours, from 00 to 99. +.It Ar mm +The number of minutes, from 00 to 59. +.It Ar SS +The number of seconds, from 00 to 59. +.El +.Pp +The +.Fl A +flag implies the +.Fl c +flag: if any file specified does not exist, it will be silently ignored. .It Fl a Change the access time of the file. The modification time of the file is not changed unless the @@ -70,6 +116,14 @@ 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 h +If the file is a symbolic link, change the times of the link +itself rather than the file that the link points to. +Note that +.Fl h +implies +.Fl c +and thus will not create any new files. .It Fl m Change the modification time of the file. The access time of the file is not changed unless the @@ -79,8 +133,9 @@ flag is also specified. Use the access and modifications times from the specified file instead of the current time of day. .It Fl t -Change the access and modification times to the specified time. -The argument should be in the form +Change the access and modification times to the specified time instead +of the current time of day. +The argument is of the form .Dq [[CC]YY]MMDDhhmm[.SS] where each pair of letters represents the following: .Pp @@ -102,15 +157,15 @@ Otherwise, a .Dq CC value of 20 is used. .It Ar MM -The month of the year, from 1 to 12. +The month of the year, from 01 to 12. .It Ar DD -the day of the month, from 1 to 31. +the day of the month, from 01 to 31. .It Ar hh -The hour of the day, from 0 to 23. +The hour of the day, from 00 to 23. .It Ar mm -The minute of the hour, from 0 to 59. +The minute of the hour, from 00 to 59. .It Ar SS -The second of the minute, from 0 to 61. +The second of the minute, from 00 to 61. .El .Pp If the @@ -123,10 +178,8 @@ If the .Dq SS letter pair is not specified, the value defaults to 0. .El -.Sh DIAGNOSTICS +.Sh EXIT STATUS .Ex -std -.Sh SEE ALSO -.Xr utimes 2 .Sh COMPATIBILITY The obsolescent form of .Nm , @@ -153,14 +206,16 @@ If the .Dq YY letter pair is in the range 39 to 99, the year is set to 1939 to 1999, otherwise, the year is set in the 21st century. -.Sh HISTORY -A -.Nm -utility appeared in -.At v7 . +.Sh SEE ALSO +.Xr utimes 2 .Sh STANDARDS The .Nm utility is expected to be a superset of the .St -p1003.2 specification. +.Sh HISTORY +A +.Nm +utility appeared in +.At v7 . diff --git a/touch/touch.c b/touch/touch.c index ea40b26..c4c3a10 100644 --- a/touch/touch.c +++ b/touch/touch.c @@ -33,7 +33,7 @@ #include -__RCSID("$FreeBSD: src/usr.bin/touch/touch.c,v 1.20 2002/09/04 23:29:07 dwmalone Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/touch/touch.c,v 1.25 2010/03/28 13:16:08 ed Exp $"); #ifndef lint static const char copyright[] = @@ -52,6 +52,7 @@ static const char sccsid[] = "@(#)touch.c 8.1 (Berkeley) 6/6/93"; #include #include #include +#include #include #include #include @@ -62,7 +63,8 @@ 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 *); -void usage(void); +int timeoffset(char *); +void usage(char *); int main(int argc, char *argv[]) @@ -71,21 +73,22 @@ main(int argc, char *argv[]) struct timeval tv[2]; int (*stat_f)(const char *, struct stat *); int (*utimes_f)(const char *, const struct timeval *); - int aflag, cflag, fflag, mflag, ch, fd, len, rval, timeset; + int Aflag, aflag, cflag, fflag, mflag, ch, fd, len, rval, timeset; char *p; + char *myname; - aflag = cflag = fflag = mflag = timeset = 0; + myname = basename(argv[0]); + Aflag = aflag = cflag = fflag = mflag = timeset = 0; stat_f = stat; utimes_f = utimes; if (gettimeofday(&tv[0], NULL)) err(1, "gettimeofday"); -#ifndef __APPLE__ - while ((ch = getopt(argc, argv, "acfhmr:t:")) != -1) -#else - while ((ch = getopt(argc, argv, "acfmr:t:")) != -1) -#endif + while ((ch = getopt(argc, argv, "A:acfhmr:t:")) != -1) switch(ch) { + case 'A': + Aflag = timeoffset(optarg); + break; case 'a': aflag = 1; break; @@ -95,13 +98,11 @@ main(int argc, char *argv[]) case 'f': fflag = 1; break; -#ifndef __APPLE__ case 'h': cflag = 1; stat_f = lstat; utimes_f = lutimes; break; -#endif /* __APPLE__ */ case 'm': mflag = 1; break; @@ -115,38 +116,59 @@ main(int argc, char *argv[]) break; case '?': default: - usage(); + usage(myname); } argc -= optind; argv += optind; - /* Default is both -a and -m. */ if (aflag == 0 && mflag == 0) aflag = mflag = 1; - /* - * If no -r or -t flag, at least two operands, the first of which - * is an 8 or 10 digit number, use the obsolete time specification. - */ - if (!timeset && argc > 1) { - (void)strtol(argv[0], &p, 10); - len = p - argv[0]; - if (*p == '\0' && (len == 8 || len == 10)) { - timeset = 1; - stime_arg2(*argv++, len == 10, tv); + if (timeset) { + if (Aflag) { + /* + * We're setting the time to an offset from a specified + * time. God knows why, but it means that we can set + * that time once and for all here. + */ + if (aflag) + tv[0].tv_sec += Aflag; + if (mflag) + tv[1].tv_sec += Aflag; + Aflag = 0; /* done our job */ } - } - - /* Otherwise use the current time of day. */ - if (!timeset) + } else { + /* + * If no -r or -t flag, at least two operands, the first of + * which is an 8 or 10 digit number, use the obsolete time + * specification, otherwise use the current time. + */ + if (argc > 1) { + strtol(argv[0], &p, 10); + len = p - argv[0]; + if (*p == '\0' && (len == 8 || len == 10)) { + timeset = 1; + stime_arg2(*argv++, len == 10, tv); + } + } + /* Both times default to the same. */ tv[1] = tv[0]; + } if (*argv == NULL) - usage(); + usage(myname); + + if (Aflag) + cflag = 1; for (rval = 0; *argv; ++argv) { /* See if the file exists. */ if (stat_f(*argv, &sb) != 0) { + if (errno != ENOENT) { + rval = 1; + warn("%s", *argv); + continue; + } if (!cflag) { /* Create the file. */ fd = open(*argv, @@ -169,12 +191,27 @@ main(int argc, char *argv[]) if (!mflag) TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec); + /* + * We're adjusting the times based on the file times, not a + * specified time (that gets handled above). + */ + if (Aflag) { + if (aflag) { + TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec); + tv[0].tv_sec += Aflag; + } + if (mflag) { + TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec); + tv[1].tv_sec += Aflag; + } + } + /* Try utimes(2). */ if (!utimes_f(*argv, tv)) continue; /* If the user specified a time, nothing else we can do. */ - if (timeset) { + if (timeset || Aflag) { rval = 1; warn("%s", *argv); continue; @@ -190,12 +227,13 @@ main(int argc, char *argv[]) continue; /* Try reading/writing. */ - if (S_ISLNK(sb.st_mode) || S_ISDIR(sb.st_mode)) { - warn("%s", *argv); - rval = 1; - } else if (rw(*argv, &sb, fflag)) { - rval = 1; - } + if (!S_ISLNK(sb.st_mode) && !S_ISDIR(sb.st_mode)) { + if (rw(*argv, &sb, fflag)) + rval = 1; + } else { + rval = 1; + warn("%s", *argv); + } } exit(rval); } @@ -293,6 +331,36 @@ stime_arg2(char *arg, int year, struct timeval *tvp) tvp[0].tv_usec = tvp[1].tv_usec = 0; } +/* Calculate a time offset in seconds, given an arg of the format [-]HHMMSS. */ +int +timeoffset(char *arg) +{ + int offset; + int isneg; + + offset = 0; + isneg = *arg == '-'; + if (isneg) + arg++; + switch (strlen(arg)) { + default: /* invalid */ + errx(1, "Invalid offset spec, must be [-][[HH]MM]SS"); + + case 6: /* HHMMSS */ + offset = ATOI2(arg); + /* FALLTHROUGH */ + case 4: /* MMSS */ + offset = offset * 60 + ATOI2(arg); + /* FALLTHROUGH */ + case 2: /* SS */ + offset = offset * 60 + ATOI2(arg); + } + if (isneg) + return (-offset); + else + return (offset); +} + void stime_file(char *fname, struct timeval *tvp) { @@ -354,12 +422,9 @@ err: rval = 1; } void -usage(void) +usage(char *myname) { -#ifndef __APPLE__ - (void)fprintf(stderr, "usage: touch [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...\n"); -#else - (void)fprintf(stderr, "usage: touch [-acfm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...\n"); -#endif + fprintf(stderr, "usage:\n" "%s [-A [-][[hh]mm]SS] [-acfhm] [-r file] " + "[-t [[CC]YY]MMDDhhmm[.SS]] file ...\n", myname); exit(1); } -- 2.7.4