Загрузить файлы в «src»

This commit is contained in:
8nlight 2023-10-05 14:16:08 +03:00
parent 15ed4ce642
commit 76eefab768
2 changed files with 47 additions and 0 deletions

3
src/false.c Normal file
View File

@ -0,0 +1,3 @@
int main(void) {
return 1;
}

44
src/printenv.c Normal file
View 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;
}