wc: Added wc
[mutos-utils.git] / rmdir.c
blob6e184367893536f4e204952164da6c7d126847ff
1 /*
2 Copyright © 2013 Alastair Stuart
4 This program is open source software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
15 #include <errno.h>
16 #include <stdbool.h>
17 #include <stdio.h>
18 #include <string.h>
20 #include <getopt.h>
21 #include <unistd.h>
23 #define VERSION "0.01"
25 void usage(char* program)
27 printf("Usage: %s [options] [file ...]\n", program);
28 printf("Deletes directories.\n"
29 "\n"
30 " --help Print this message.\n"
31 " --version Show version info.\n");
34 int main(int argc, char* argv[])
36 bool errors = false;
38 static struct option long_options[] = {
39 {"help", no_argument, NULL, 1},
40 {"version", no_argument, NULL, 2},
41 {NULL, 0, NULL, 0}
44 int c = 0;
45 while ((c = getopt_long(argc, argv, "",
46 long_options, NULL)) != -1)
48 switch (c)
50 case 1:
51 usage(argv[0]);
52 return 0;
53 case 2:
54 printf("rmdir (mutos) v"VERSION"\n");
55 return 0;
56 default:
57 fprintf(stderr,"Run '%s --help' for usage.\n",
58 argv[0]);
59 return 1;
63 for (int i = optind; i < argc; i++)
65 int rc = rmdir(argv[i]);
66 if (rc != 0) {
67 fprintf(stderr, "%s: %s: %s\n",
68 argv[0], strerror(errno), argv[i]);
69 errors = true;
73 if (errors) {
74 return 1;
77 return 0;