diff --git a/src/env.c b/src/env.c new file mode 100644 index 0000000..cca6670 --- /dev/null +++ b/src/env.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include + +int main(const int argc, char **argv, const char **envp) { + int i; + for (i = 1; i < argc; i++) { + char *val = strchr(argv[i], '='); + if (!val) + break; + + val[0] = '\0'; + + if (setenv(argv[i], val + 1, 1)) { + fprintf(stderr, "env: %s\n", strerror(errno)); + return 1; + } + } + + /* Print env */ + if (i == argc) { + while (*envp) + puts(*envp++); + + return 0; + } + + execvp(argv[i], argv + i); + fprintf(stderr, "env: %s\n", strerror(errno)); + return 1; +} diff --git a/src/tty.c b/src/tty.c new file mode 100644 index 0000000..5b9a558 --- /dev/null +++ b/src/tty.c @@ -0,0 +1,13 @@ +#include +#include + +int main(void) { + char *tty = ttyname(STDIN_FILENO); + if (tty) + puts(tty); + + else + puts("not a tty"); + + return tty == NULL; +} diff --git a/src/whoami.c b/src/whoami.c new file mode 100644 index 0000000..ddff8a9 --- /dev/null +++ b/src/whoami.c @@ -0,0 +1,18 @@ +#include +#include +#include + +#include +#include +#include + +int main(void) { + struct passwd *pw = getpwuid(getuid()); + if (!pw) { + fprintf(stderr, "whoami: %s\n", strerror(errno)); + return 1; + } + + puts(pw->pw_name); + return 0; +}