diff options
author | Vincent Labrecque <vincent@cvs.openbsd.org> | 2002-02-14 22:58:21 +0000 |
---|---|---|
committer | Vincent Labrecque <vincent@cvs.openbsd.org> | 2002-02-14 22:58:21 +0000 |
commit | e77bbdf71e5f8db05878c88e66a65173f7baa6a0 (patch) | |
tree | 34067ef9b8275b4dc4c4ffbc4f7571f0ecbf3bc6 | |
parent | 482b0bbc343bdf56092134379e2aeed8918e025b (diff) |
d_makename now takes a length parameter so we can remove the
strcpy call.
-rw-r--r-- | usr.bin/mg/def.h | 4 | ||||
-rw-r--r-- | usr.bin/mg/dired.c | 12 | ||||
-rw-r--r-- | usr.bin/mg/fileio.c | 31 |
3 files changed, 26 insertions, 21 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index df42a54db37..21378a2f94a 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.27 2002/02/14 13:41:44 deraadt Exp $ */ +/* $OpenBSD: def.h,v 1.28 2002/02/14 22:58:20 vincent Exp $ */ /* * This file is the general header file for all parts @@ -382,7 +382,7 @@ char *adjustname __P((char *)); char *startupfile __P((char *)); int copy __P((char *, char *)); BUFFER *dired_ __P((char *)); -int d_makename __P((LINE *, char *)); +int d_makename __P((LINE *, char *, int)); LIST *make_file_list __P((char *)); /* kbd.c X */ diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c index 2371b3b55ec..7bdedcc7482 100644 --- a/usr.bin/mg/dired.c +++ b/usr.bin/mg/dired.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dired.c,v 1.7 2001/05/24 03:05:21 mickey Exp $ */ +/* $OpenBSD: dired.c,v 1.8 2002/02/14 22:58:20 vincent Exp $ */ /* dired module for mg 2a */ /* by Robert A. Larson */ @@ -110,7 +110,7 @@ d_findfile(f, n) int s; char fname[NFILEN]; - if ((s = d_makename(curwp->w_dotp, fname)) == ABORT) + if ((s = d_makename(curwp->w_dotp, fname, sizeof fname)) == ABORT) return FALSE; if ((bp = (s ? dired_(fname) : findbuffer(fname))) == NULL) return FALSE; @@ -132,7 +132,7 @@ d_ffotherwindow(f, n) BUFFER *bp; MGWIN *wp; - if ((s = d_makename(curwp->w_dotp, fname)) == ABORT) + if ((s = d_makename(curwp->w_dotp, fname, sizeof fname)) == ABORT) return FALSE; if ((bp = (s ? dired_(fname) : findbuffer(fname))) == NULL) return FALSE; @@ -156,7 +156,7 @@ d_expunge(f, n) for (lp = lforw(curbp->b_linep); lp != curbp->b_linep; lp = nlp) { nlp = lforw(lp); if (llength(lp) && lgetc(lp, 0) == 'D') { - switch (d_makename(lp, fname)) { + switch (d_makename(lp, fname, sizeof fname)) { case ABORT: ewprintf("Bad line in dired buffer"); return FALSE; @@ -189,7 +189,7 @@ d_copy(f, n) char frname[NFILEN], toname[NFILEN]; int stat; - if (d_makename(curwp->w_dotp, frname) != FALSE) { + if (d_makename(curwp->w_dotp, frname, sizeof frname) != FALSE) { ewprintf("Not a file"); return FALSE; } @@ -207,7 +207,7 @@ d_rename(f, n) char frname[NFILEN], toname[NFILEN]; int stat; - if (d_makename(curwp->w_dotp, frname) != FALSE) { + if (d_makename(curwp->w_dotp, frname, sizeof frname) != FALSE) { ewprintf("Not a file"); return FALSE; } diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c index 090ccec0209..81ee0077331 100644 --- a/usr.bin/mg/fileio.c +++ b/usr.bin/mg/fileio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.c,v 1.22 2002/02/14 14:24:21 deraadt Exp $ */ +/* $OpenBSD: fileio.c,v 1.23 2002/02/14 22:58:20 vincent Exp $ */ /* * POSIX fileio.c @@ -11,7 +11,6 @@ static FILE *ffp; #include <sys/stat.h> #include <sys/dir.h> #include <string.h> -#include <errno.h> #include <fcntl.h> #include <unistd.h> @@ -466,19 +465,25 @@ dired_(dirname) return bp; } +#define NAME_FIELD 8 + int -d_makename(lp, fn) - LINE *lp; - char *fn; +d_makename(LINE *lp, char *fn, int len) { - char *cp; - - if (llength(lp) <= 56) - return ABORT; - (void) strcpy(fn, curbp->b_fname); - cp = fn + strlen(fn); - bcopy(&lp->l_text[56], cp, llength(lp) - 56); - cp[llength(lp) - 56] = '\0'; + int i; + char *p, *np; + + strlcpy(fn, curbp->b_fname, len); + p = lp->l_text; + for (i = 0; i < NAME_FIELD; i++) { + np = strpbrk(p, "\t "); + if (np == NULL) + return ABORT; + p = np + 1; + while (*p != '\0' && strchr("\t ", *p)) + p++; + } + strlcat(fn, p, len); return lgetc(lp, 2) == 'd'; } #endif /* NO_DIRED */ |