=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/file.c,v retrieving revision 1.87 retrieving revision 1.88 diff -u -r1.87 -r1.88 --- src/usr.bin/mg/file.c 2013/03/25 11:38:22 1.87 +++ src/usr.bin/mg/file.c 2013/10/22 07:41:23 1.88 @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.87 2013/03/25 11:38:22 florian Exp $ */ +/* $OpenBSD: file.c,v 1.88 2013/10/22 07:41:23 florian Exp $ */ /* This file is in the public domain. */ @@ -210,7 +210,7 @@ struct stat statbuf; int status, i, ro = FALSE; PF *ael; - char *dp; + char dp[NFILEN]; /* might be old */ if (bclear(curbp) != TRUE) @@ -255,7 +255,8 @@ if (errno != ENOENT) ro = TRUE; else if (errno == ENOENT) { - dp = dirname(fname); + (void)xdirname(dp, fname, sizeof(dp)); + (void)strlcat(dp, "/", sizeof(dp)); if (stat(dp, &statbuf) == -1 && errno == ENOENT) { /* no read-only; like emacs */ ewprintf("Use M-x make-directory RET RET to " @@ -669,19 +670,18 @@ { struct stat statbuf; int s; - char *dp; + char dp[NFILEN]; - dp = dirname(fn); - if (stat(fn, &statbuf) == -1 && errno == ENOENT) { errno = 0; if (access(dp, W_OK) && errno == EACCES) { - ewprintf("Directory %s%s write-protected", dp, - (dp[0] == '/' && dp[1] == '\0') ? "" : "/"); + (void)xdirname(dp, fn, sizeof(dp)); + (void)strlcat(dp, "/", sizeof(dp)); + + ewprintf("Directory %s write-protected", dp); return (FIOERR); } else if (errno == ENOENT) { - ewprintf("%s%s: no such directory", dp, - (dp[0] == '/' && dp[1] == '\0') ? "" : "/"); + ewprintf("%s: no such directory", dp); return (FIOERR); } }