Fix compilation on Linux

Symptom with GCC 11:
> gcc-11 -std=c99 -Wextra -pedantic -Wall -O2 -DUSE_PAM -DDOAS_CONF=\"/etc/doas.conf\"  -D_GNU_SOURCE -include compat/compat.h -Icompat  -c -o env.o env.c
> env.c: In function ‘createenv’:
> env.c:139:37: error: conflicting types for ‘environ’; have ‘const char **’
>   139 |                 extern const char **environ;
>       |                                     ^~~~~~~

Symptom with Clang 17:
> clang-17 -std=c99 -Wextra -pedantic -Wall -O2 -DUSE_PAM -DDOAS_CONF=\"/etc/doas.conf\"  -D_GNU_SOURCE -include compat/compat.h -Icompat  -c -o env.o env.c
> env.c:139:23: error: redeclaration of 'environ' with a different type: 'const char **' vs 'char **'
>                 extern const char **environ;
>                                     ^

Related:
https://sourceforge.net/p/predef/wiki/OperatingSystems/#linux-kernel
This commit is contained in:
Sebastian Pipping 2023-03-16 21:50:19 +01:00
parent d9f415c740
commit b884d88626
2 changed files with 3 additions and 3 deletions

4
doas.c
View file

@ -420,7 +420,7 @@ main(int argc, char **argv)
pam_handle_t *pamh = NULL;
int pam_err;
/* #ifndef linux */
/* #ifndef __linux__ */
int temp_stdin;
/* openpam_ttyconv checks if stdin is a terminal and
@ -497,7 +497,7 @@ main(int argc, char **argv)
}
pam_end(pamh, pam_err);
#ifndef linux
#ifndef __linux__
/* Re-establish stdin */
if (dup2(temp_stdin, STDIN_FILENO) == -1)
err(1, "dup2");

2
env.c
View file

@ -135,7 +135,7 @@ createenv(struct rule *rule, struct passwd *original, struct passwd *target)
addnode(env, "USER", target->pw_name);
if (rule->options & KEEPENV) {
#ifndef linux
#ifndef __linux__
extern const char **environ;
#endif