annotate toys/posix/rmdir.c @ 1776:7bf68329eb3b draft default tip

Repository switched to git at https://github.com/landley/toybox
author Rob Landley <rob@landley.net>
date Thu, 09 Apr 2015 02:28:32 -0500
parents fc1bb49e58a9
children
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...]
1333
fc1bb49e58a9 Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 782
diff changeset
14
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
15 Remove one or more directories.
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
16
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
17 -p Remove path.
290
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
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "toys.h"
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 static void do_rmdir(char *name)
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 {
782
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
24 char *temp;
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
25
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
26 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
27 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
28 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
29 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
30 }
782
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
31
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
32 // 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
33
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
34 if (!toys.optflags) return;
782
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
35 do {
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
36 if (!(temp = strrchr(name, '/'))) return;
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
37 *temp = 0;
3d7526f6115b Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
38 } 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
39 }
290
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
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 void rmdir_main(void)
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
43 {
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
44 char **s;
290
d37e2de3a9f3 Add rmdir and test for it.
Rob Landley <rob@landley.net>
parents:
diff changeset
45
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
46 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
47 }