scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit b1899a0c43e8d388164044bbf169ab2c6a91861e
parent 3f017b5cfe79b8ff60e1b9edfdce87231d4a8151
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 29 Oct 2024 21:52:12 +0100

make: Move putenv() to posix.c

The call to putenv() should not be in code supposed to be
portable, because this function is only available in posix
systems.

Diffstat:
Msrc/cmd/scc-make/make.h | 1+
Msrc/cmd/scc-make/parser.c | 10++--------
Msrc/cmd/scc-make/posix.c | 13+++++++++++++
3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/cmd/scc-make/make.h b/src/cmd/scc-make/make.h @@ -50,6 +50,7 @@ extern void setmacro(char *, char *, int); extern time_t stamp(char *); extern int launch(char *, int); extern int putenv(char *); +extern void exportvar(char *, char *); /* main.c */ extern int kflag, dflag, nflag, iflag, sflag; diff --git a/src/cmd/scc-make/parser.c b/src/cmd/scc-make/parser.c @@ -86,20 +86,14 @@ lookup(char *name) void setmacro(char *name, char *val, int export) { - int n; - char *buf; Macro *mp; mp = lookup(name); free(mp->value); mp->value = estrdup(val); - if (export && strcmp(name, "SHELL") != 0) { - n = snprintf(NULL, 0, "%s=%s", name, val); - buf = emalloc(n+1); - snprintf(buf, n+1, "%s=%s", name, val); - putenv(buf); - } + if (export && strcmp(name, "SHELL") != 0) + exportvar(name, val); } char * diff --git a/src/cmd/scc-make/posix.c b/src/cmd/scc-make/posix.c @@ -3,10 +3,23 @@ #include <unistd.h> #include <errno.h> +#include <stdio.h> #include <string.h> #include "make.h" +void +exportvar(char *var, char *value) +{ + int n; + char *buf; + + n = snprintf(NULL, 0, "%s=%s", var, value); + buf = emalloc(n+1); + snprintf(buf, n+1, "%s=%s", var, value); + putenv(buf); +} + time_t stamp(char *name) {