Changing basename(3) and dirname(3) to the POSIX-mandated non-const
parameters produces this warnings when compiling sed(1):
/usr/src/usr.bin/sed/main.c:401:16: warning: passing 'const char *' to parameter
of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qua
lifiers]
Here's a fix to accommodate a basename(3) that takes a non-const
parameter and may in fact modify the string buffer. Based on FreeBSD
like the surrounding in-place editing code.
OK?
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/sed/main.c,v
retrieving revision 1.40
diff -u -p -r1.40 main.c
--- main.c 8 Dec 2018 23:11:24 -0000 1.40
+++ main.c 10 Oct 2020 15:16:12 -0000
@@ -343,6 +343,7 @@ mf_fgets(SPACE *sp, enum e_spflag spflag
{
struct stat sb;
size_t len;
+ char *dirbuf;
char *p;
int c, fd;
static int firstfile;
@@ -397,8 +398,11 @@ mf_fgets(SPACE *sp, enum e_spflag spflag
if (len > sizeof(oldfname))
error(FATAL, "%s: name too long",
fname);
}
+ if ((dirbuf = strdup(fname)) == NULL)
+ error(FATAL, "%s", strerror(errno));
len = snprintf(tmpfname, sizeof(tmpfname),
"%s/sedXXXXXXXXXX",
- dirname(fname));
+ dirname(dirbuf));
+ free(dirbuf);
if (len >= sizeof(tmpfname))
error(FATAL, "%s: name too long", fname);
if ((fd = mkstemp(tmpfname)) == -1)
--
Christian "naddy" Weisgerber [email protected]