summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorVincent Labrecque <vincent@cvs.openbsd.org>2002-02-19 12:58:43 +0000
committerVincent Labrecque <vincent@cvs.openbsd.org>2002-02-19 12:58:43 +0000
commit7abaeebdda03284afffe50dafb39ca1138b89ab5 (patch)
tree86bb29f77e5b48c7a3a79a710a597ed561eb08b9 /usr.bin/mg
parentdf9e76d89f4158da6f5adec159f3ad28a5a21bb5 (diff)
Make multiple buffers with the same basename work correctly.. (like GNU
emacs) and unbreak a stupid loop at the same time. ok art@
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/file.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index 19415e16a15..f83ba3d34d0 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.13 2002/02/14 14:24:21 deraadt Exp $ */
+/* $OpenBSD: file.c,v 1.14 2002/02/19 12:58:42 vincent Exp $ */
/*
* File commands.
@@ -91,24 +91,20 @@ poptofile(f, n)
* empty buffer to put it in.
*/
BUFFER *
-findbuffer(fname)
- char *fname;
+findbuffer(char *fname)
{
BUFFER *bp;
char bname[NBUFN];
- unsigned int count;
+ unsigned int count, remain, i;
for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
if (strcmp(bp->b_fname, fname) == 0)
return bp;
}
- /* new buffer name */
- for (count = 1; bfind(bname, FALSE) != NULL; count++)
- ;
- if (count == 1)
- snprintf(bname, sizeof bname, "%s", basename(fname));
- else
- snprintf(bname, sizeof bname, "%s<%d>", basename(fname), count);
+ i = strlcpy(bname, basename(fname), sizeof(bname));
+ remain = sizeof(bname) - i;
+ for (count = 2; bfind(bname, FALSE) != NULL; count++)
+ snprintf(&bname[i], remain, "<%d>", count);
return bfind(bname, TRUE);
}