annotate toys/posix/rmdir.c @ 1008:a55854bde872

su: cleanery * make help message more like others * s/TT\.(.)Argu/TT.\1/g * move environ to toys.h * simplify failure messages * clear password before quit * not check what execve returns * -lc
author Strake <strake888@gmail.com>
date Sat, 17 Aug 2013 02:54:58 -0500
parents 3d7526f6115b
children fc1bb49e58a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
1 /* rmdir.c - remove directory/path
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
598
75a69d5550a0 Cosmetic tweak to command preamble.
Rob Landley <rob@landley.net>
parents: 290
diff changeset
3 * Copyright 2008 Rob Landley <rob@landley.net>
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
598
75a69d5550a0 Cosmetic tweak to command preamble.
Rob Landley <rob@landley.net>
parents: 290
diff changeset
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/rmdir.html
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
6
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 USE_RMDIR(NEWTOY(rmdir, "<1p", TOYFLAG_BIN))
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 config RMDIR
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
10 bool "rmdir"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
11 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
12 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
13 usage: rmdir [-p] [dirname...]
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
14 Remove one or more directories.
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
15
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
16 -p Remove path.
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 */
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
18
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 #include "toys.h"
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
20
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 static void do_rmdir(char *name)
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 {
782
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
23 char *temp;
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
24
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
25 for (;;) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
26 if (rmdir(name)) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
27 perror_msg("%s",name);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
28 return;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
29 }
782
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
30
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
31 // Each -p cycle back up one slash, ignoring trailing and repeated /.
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
32
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
33 if (!toys.optflags) return;
782
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
34 do {
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
35 if (!(temp = strrchr(name, '/'))) return;
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
36 *temp = 0;
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
37 } while (!temp[1]);
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
38 }
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
39 }
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
40
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 void rmdir_main(void)
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
43 char **s;
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
44
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
45 for (s=toys.optargs; *s; s++) do_rmdir(*s);
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
46 }