// unlink.c, version 1.0.1 // OMKOV coreutils implementation of POSIX unlink // Copyright (C) 2020, Jakob Wakeling // MIT Licence #include "util/error.h" #include "util/optget.h" #include #include #define VERSION "1.0.1" static struct lop lops[] = { { "help", ARG_NUL, 256 }, { "version", ARG_NUL, 257 }, { NULL, 0, 0 } }; static void hlp(void); static void ver(void); int main(int ac, char *av[]) { A0 = av[0]; struct opt opt = OPTGET_INIT; opt.str = ""; opt.lops = lops; for (int o; (o = optget(&opt, av, 1)) != -1;) switch (o) { case 256: { hlp(); return 0; } case 257: { ver(); return 0; } default: { return 1; } } if (ac == 1) { error(1, "missing operand"); } if (unlink(av[1])) { error(1, "%s", serr()); } return 0; } /* Print help information */ static void hlp(void) { puts("unlink - remove a file using the unlink function\n"); puts("usage: unlink file\n"); puts("options:"); puts(" --help Display help information"); puts(" --version Display version information"); } /* Print version information */ static void ver(void) { puts("OMKOV coreutils unlink, version " VERSION); puts("Copyright (C) 2020, Jakob Wakeling"); puts("MIT Licence (https://opensource.org/licenses/MIT)"); }