Hi all, Implemented yes(1), sync(1) and printenv(1). Source is attached, haven't had time to write the manpage yet.
Cheers, stateless
/* See LICENSE file for copyright and license details. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <err.h> int main(int argc, char *argv[]) { int i; char *p; if (argc > 1) { do { for (i = 1; i < argc; i++) { p = argv[i]; while (*p && *p != '\n') if (putchar(*p++) == EOF) err(1, "putchar"); if (putchar(' ') == EOF) err(1, "putchar"); } if (putchar('\n') == EOF) err(1, "putchar"); } while (1); } else { do { if (puts("y") == EOF) err(1, "puts"); } while (1); } /* Not reached */ return EXIT_SUCCESS; }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> extern char **environ; static void usage(void) { fprintf(stderr, "usage: printenv [variable]\n"); exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { int i; char **ep; int ch; size_t len; char *p; while ((ch = getopt(argc, argv, "")) != -1) { switch (ch) { case '?': default: usage(); } } argc -= optind; argv += optind; if (!argc) { for (ep = environ; *ep; ep++) printf("%s\n", *ep); return EXIT_SUCCESS; } else { for (i = 0; argv[i]; i++) { len = strlen(argv[i]); for (ep = environ; *ep; ep++) { if (!memcmp(*ep, argv[i], len)) { p = *ep + len; printf("%s\n", *p ? p + 1 : p); } } } } return EXIT_SUCCESS; }
/* See LICENSE file for copyright and license details. */ #include <stdlib.h> #include <unistd.h> extern void sync(void); int main(void) { sync(); return EXIT_SUCCESS; }