Загрузить файлы в «src»
This commit is contained in:
parent
15ed4ce642
commit
76eefab768
3
src/false.c
Normal file
3
src/false.c
Normal file
@ -0,0 +1,3 @@
|
||||
int main(void) {
|
||||
return 1;
|
||||
}
|
44
src/printenv.c
Normal file
44
src/printenv.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
unsigned int nullline;
|
||||
|
||||
int printvars(const int len, const char **names) {
|
||||
int ret = 0;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
char *val = getenv(names[i]);
|
||||
if (!val) {
|
||||
ret = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s%c", val, (nullline == 1) ? 0 : '\n');
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(const int argc, const char **argv, const char **envp) {
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] != '-')
|
||||
break;
|
||||
|
||||
else if (!strcmp(argv[i], "-0"))
|
||||
nullline = 1;
|
||||
|
||||
else if (!strcmp(argv[i], "-h")) {
|
||||
printf("printenv [-n (end each output line with NUL, not newline)]\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == argc)
|
||||
while (*envp)
|
||||
printf("%s%c", *envp++, (nullline == 1) ? 0 : '\n');
|
||||
|
||||
else
|
||||
return printvars(argc - i, argv + i);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user