diff options
author | 1999-01-03 05:33:48 +0000 | |
---|---|---|
committer | 1999-01-03 05:33:48 +0000 | |
commit | 8b6f9cfe06b21c47fdd4ba710555cf87af18db99 (patch) | |
tree | a9a91ae313cce6dbd11f8ae326b818ee435c7173 /usr.bin/patch/inp.c | |
parent | back out last change, other parts of patch rely on basename() returning a ptr to a part of name, not a new string (diff) | |
download | wireguard-openbsd-8b6f9cfe06b21c47fdd4ba710555cf87af18db99.tar.xz wireguard-openbsd-8b6f9cfe06b21c47fdd4ba710555cf87af18db99.zip |
Use libc basename(3) and dirname(3) instead of defining our own. Also clean up some nasty assumptions that basename() returns a pointer that lies within its argument
Diffstat (limited to 'usr.bin/patch/inp.c')
-rw-r--r-- | usr.bin/patch/inp.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c index bab3562943a..f27866571d2 100644 --- a/usr.bin/patch/inp.c +++ b/usr.bin/patch/inp.c @@ -1,7 +1,7 @@ -/* $OpenBSD: inp.c,v 1.7 1998/11/25 00:30:25 espie Exp $ */ +/* $OpenBSD: inp.c,v 1.8 1999/01/03 05:33:48 millert Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: inp.c,v 1.7 1998/11/25 00:30:25 espie Exp $"; +static char rcsid[] = "$OpenBSD: inp.c,v 1.8 1999/01/03 05:33:48 millert Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -78,6 +78,9 @@ char *filename; Reg2 LINENUM iline; char lbuf[MAXLINELEN]; + if (!filename || *filename == '\0') + return FALSE; + statfailed = stat(filename, &filestat); if (statfailed && ok_to_create_file) { if (verbose) @@ -102,26 +105,23 @@ char *filename; || ((filestat.st_mode & 0022) == 0 && filestat.st_uid != myuid)) { struct stat cstat; char *cs = Nullch; - char *filebase; - int pathlen; + char *filebase, *filedir; filebase = basename(filename); - pathlen = filebase - filename; + filedir = dirname(filename); - /* Put any leading path into `s'. - Leave room in lbuf for the diff command. */ + /* Leave room in lbuf for the diff command. */ s = lbuf + 20; - strncpy(s, filename, pathlen); -#define try(f, a1, a2) (Snprintf(s + pathlen, sizeof lbuf - (s + pathlen - lbuf), f, a1, a2), stat(s, &cstat) == 0) - if ( try("RCS/%s%s", filebase, RCSSUFFIX) - || try("RCS/%s" , filebase, 0) - || try( "%s%s", filebase, RCSSUFFIX)) { +#define try(f, a1, a2, a3) (Snprintf(s, sizeof lbuf - 20, f, a1, a2, a3), stat(s, &cstat) == 0) + if ( try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX) + || try("%s/RCS/%s%s", filedir, filebase, "") + || try( "%s/%s%s", filedir, filebase, RCSSUFFIX)) { Snprintf(buf, sizeof buf, CHECKOUT, filename); Snprintf(lbuf, sizeof lbuf, RCSDIFF, filename); cs = "RCS"; - } else if ( try("SCCS/%s%s", SCCSPREFIX, filebase) - || try( "%s%s", SCCSPREFIX, filebase)) { + } else if ( try("%s/SCCS/%s%s", filedir, SCCSPREFIX, filebase) + || try( "%s/%s%s", filedir, SCCSPREFIX, filebase)) { Snprintf(buf, sizeof buf, GET, s); Snprintf(lbuf, sizeof lbuf, SCCSDIFF, s, filename); cs = "SCCS"; |