From d03f028e33777f2349caceda9e841fafd9cef715 Mon Sep 17 00:00:00 2001 From: cgd Date: Tue, 7 Mar 1995 15:28:32 +0000 Subject: [PATCH] clean up import, fix a few bugs, etc. --- usr.sbin/mtree/Makefile | 3 +-- usr.sbin/mtree/compare.c | 20 +++++++++++++------- usr.sbin/mtree/create.c | 16 ++++++++-------- usr.sbin/mtree/mtree.8 | 2 +- usr.sbin/mtree/mtree.c | 13 ++++++------- usr.sbin/mtree/mtree.h | 9 ++++----- usr.sbin/mtree/spec.c | 13 ++++++++----- usr.sbin/mtree/verify.c | 13 ++++++------- 8 files changed, 47 insertions(+), 42 deletions(-) diff --git a/usr.sbin/mtree/Makefile b/usr.sbin/mtree/Makefile index 6b3e06243e3d..fcb41b95850f 100644 --- a/usr.sbin/mtree/Makefile +++ b/usr.sbin/mtree/Makefile @@ -1,5 +1,4 @@ -# from: @(#)Makefile 5.6 (Berkeley) 2/19/92 -# $Id: Makefile,v 1.6 1994/12/22 11:36:40 cgd Exp $ +# @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= mtree #CFLAGS+=-DDEBUG diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c index 3db2c0a7de01..b2585727e71d 100644 --- a/usr.sbin/mtree/compare.c +++ b/usr.sbin/mtree/compare.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,8 +32,7 @@ */ #ifndef lint -/* from: static char sccsid[] = "@(#)compare.c 5.10 (Berkeley) 3/31/92"; */ -static char *rcsid = "$Id: compare.c,v 1.6 1994/03/27 09:09:42 cgd Exp $"; +static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include @@ -166,11 +165,18 @@ typeerr: LABEL; tab, s->st_size, p->fts_statp->st_size); tab = "\t"; } - if (s->flags & F_TIME && s->st_mtime != p->fts_statp->st_mtime) { + /* + * XXX + * Catches nano-second differences, but doesn't display them. + */ + if (s->flags & F_TIME && + s->st_mtimespec.ts_sec != p->fts_statp->st_mtimespec.ts_sec || + s->st_mtimespec.ts_nsec != p->fts_statp->st_mtimespec.ts_nsec) { LABEL; (void)printf("%smodification time (%.24s, ", - tab, ctime(&s->st_mtime)); - (void)printf("%.24s)\n", ctime(&p->fts_statp->st_mtime)); + tab, ctime(&s->st_mtimespec.ts_sec)); + (void)printf("%.24s)\n", + ctime(&p->fts_statp->st_mtimespec.ts_sec)); tab = "\t"; } if (s->flags & F_CKSUM) diff --git a/usr.sbin/mtree/create.c b/usr.sbin/mtree/create.c index ca666c844a48..9ce603e0001b 100644 --- a/usr.sbin/mtree/create.c +++ b/usr.sbin/mtree/create.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,8 +32,7 @@ */ #ifndef lint -/* from: static char sccsid[] = "@(#)create.c 5.19 (Berkeley) 3/2/92"; */ -static char *rcsid = "$Id: create.c,v 1.7 1994/03/27 09:09:49 cgd Exp $"; +static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include @@ -152,7 +151,9 @@ statf(p) if (keys & F_SIZE) output(&indent, "size=%qd", p->fts_statp->st_size); if (keys & F_TIME) - output(&indent, "time=%ld", p->fts_statp->st_mtime); + output(&indent, "time=%ld.%ld", + p->fts_statp->st_mtimespec.ts_sec, + p->fts_statp->st_mtimespec.ts_nsec); if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || crc(fd, &val, &len)) @@ -272,17 +273,16 @@ output(offset, fmt, va_alist) #endif { va_list ap; - int len; char buf[1024]; #if __STDC__ va_start(ap, fmt); #else va_start(ap); #endif - len = vsnprintf(buf, sizeof(buf), fmt, ap); + (void)vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); - if (*offset + len > MAXLINELEN - 3) { + if (*offset + strlen(buf) > MAXLINELEN - 3) { (void)printf(" \\\n%*s", INDENTNAMELEN, ""); *offset = INDENTNAMELEN; } diff --git a/usr.sbin/mtree/mtree.8 b/usr.sbin/mtree/mtree.8 index 3c50f71bd8f6..157917d24490 100644 --- a/usr.sbin/mtree/mtree.8 +++ b/usr.sbin/mtree/mtree.8 @@ -51,7 +51,7 @@ The utility compares the file hierarchy rooted in the current directory against a specification read from the standard input. Messages are written to the standard output for any files whose -characteristics do not match the specifications, or which are +characteristics do not match the specification, or which are missing from either the file hierarchy or the specification. .Pp The options are as follows: diff --git a/usr.sbin/mtree/mtree.c b/usr.sbin/mtree/mtree.c index 55f276e5af2e..17857c5543d3 100644 --- a/usr.sbin/mtree/mtree.c +++ b/usr.sbin/mtree/mtree.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1989, 1990, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,14 +32,13 @@ */ #ifndef lint -char copyright[] = -"@(#) Copyright (c) 1990 The Regents of the University of California.\n\ - All rights reserved.\n"; +static char copyright[] = +"@(#) Copyright (c) 1989, 1990, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -/* from: static char sccsid[] = "@(#)mtree.c 5.10 (Berkeley) 4/17/92"; */ -static char *rcsid = "$Id: mtree.c,v 1.3 1993/11/02 07:51:12 cgd Exp $"; +static char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include diff --git a/usr.sbin/mtree/mtree.h b/usr.sbin/mtree/mtree.h index ad0405d88010..55831275e7bd 100644 --- a/usr.sbin/mtree/mtree.h +++ b/usr.sbin/mtree/mtree.h @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,8 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)mtree.h 5.9 (Berkeley) 2/19/92 - * $Id: mtree.h,v 1.4 1994/04/25 18:21:23 cgd Exp $ + * @(#)mtree.h 8.1 (Berkeley) 6/6/93 */ #include @@ -46,7 +45,7 @@ typedef struct _node { struct _node *parent, *child; /* up, down */ struct _node *prev, *next; /* left, right */ off_t st_size; /* size */ - struct timespec st_mtimespec; /* last modification time */ + struct timespec st_mtimespec; /* last modification time */ u_long cksum; /* check sum */ char *slink; /* symbolic link reference */ uid_t st_uid; /* uid */ diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c index 1069d384dd87..ae660e049409 100644 --- a/usr.sbin/mtree/spec.c +++ b/usr.sbin/mtree/spec.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,8 +32,7 @@ */ #ifndef lint -/* from: static char sccsid[] = "@(#)spec.c 5.17 (Berkeley) 4/17/92"; */ -static char *rcsid = "$Id: spec.c,v 1.4 1994/03/27 09:09:54 cgd Exp $"; +static char sccsid[] = "@(#)spec.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include @@ -215,7 +214,11 @@ set(t, ip) err("%s", strerror(errno)); break; case F_TIME: - ip->st_mtime = strtoul(val, &ep, 10); + ip->st_mtimespec.ts_sec = strtoul(val, &ep, 10); + if (*ep != '.') + err("invalid time %s", val); + val = ep + 1; + ip->st_mtimespec.ts_nsec = strtoul(val, &ep, 10); if (*ep) err("invalid time %s", val); break; diff --git a/usr.sbin/mtree/verify.c b/usr.sbin/mtree/verify.c index 79dc930ada9f..27d9b90b123d 100644 --- a/usr.sbin/mtree/verify.c +++ b/usr.sbin/mtree/verify.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,16 +32,15 @@ */ #ifndef lint -/* from: static char sccsid[] = "@(#)verify.c 5.11 (Berkeley) 4/17/92"; */ -static char *rcsid = "$Id: verify.c,v 1.7 1993/11/02 08:44:00 cgd Exp $"; +static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include #include #include #include -#include #include +#include #include #include #include "mtree.h" @@ -108,8 +107,8 @@ vwalk() } for (ep = level; ep; ep = ep->next) - if (ep->flags & F_MAGIC && !fnmatch(ep->name, - p->fts_name, FNM_PATHNAME) || + if (ep->flags & F_MAGIC && + !fnmatch(ep->name, p->fts_name, FNM_PATHNAME) || !strcmp(ep->name, p->fts_name)) { ep->flags |= F_VISIT; if (compare(ep->name, ep, p))