Skip to content

Commit 409a886

Browse files
committed
mamake: specifically error out on fopen(3) failure (re: f58153d)
This avoids strerror(3) output in the error message reflecting the unavoidable subsequent fclose(3) failure if fopen(3) fails.
1 parent b1f55d6 commit 409a886

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/cmd/INIT/mamake.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* coded for portability
2929
*/
3030

31-
#define RELEASE_DATE "2025-04-02"
31+
#define RELEASE_DATE "2025-04-24"
3232
static char id[] = "\n@(#)$Id: mamake (ksh 93u+m) " RELEASE_DATE " $\0\n";
3333

3434
#if _PACKAGE_ast
@@ -1043,8 +1043,10 @@ static void substitute(Buf_t *buf, char *s)
10431043
Buf_t *scr;
10441044
if (!argv)
10451045
{ /* write value to temp file, converting whitespace to newlines */
1046+
if (!(f = fopen(in, "w")))
1047+
error_out(strerror(errno), "could not open pipe command input for writing");
10461048
errno = 0;
1047-
if (f = fopen(in, "w")) do
1049+
do
10481050
{
10491051
while (isspace(*v))
10501052
v++;
@@ -1070,12 +1072,13 @@ static void substitute(Buf_t *buf, char *s)
10701072
*s = n;
10711073
drop(scr);
10721074
/* read output back, converting each newline but the last to a space */
1073-
if ((f = fopen(out, "r")))
1074-
while ((c = getc(f)) != EOF)
1075-
add(buf, (final_newline = (c == '\n')) ? ' ' : c);
1075+
if (!(f = fopen(out, "r")))
1076+
error_out(strerror(errno), "could not open pipe command output for reading");
1077+
while ((c = getc(f)) != EOF)
1078+
add(buf, (final_newline = (c == '\n')) ? ' ' : c);
10761079
if (final_newline)
10771080
unadd(buf);
1078-
if (!f || ferror(f) || fclose(f) == EOF)
1081+
if (ferror(f) || fclose(f) == EOF)
10791082
error_out(strerror(errno), "could not read pipe command output");
10801083
unlink(out);
10811084
if (!argv)

0 commit comments

Comments
 (0)