diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-01-03 05:33:50 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-01-03 05:33:50 +0000 |
commit | fa79b12122e966be5518c9d5de1aa22f1b431020 (patch) | |
tree | 391ba58678a319d10415743a5846f3bda39e773b /usr.bin/patch/inp.c | |
parent | 74747574a48ac4e2d4962b444d6fb969cb8644bd (diff) |
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"; |