Mercurial > hg > toybox
annotate toys/posix/rmdir.c @ 1183:0752b2d58909 draft
Rename xmsprintf() to just xmprintf().
Partly because there's no supplied target string ala sprintf, and partly
because I can never remember what order the m and s go in.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 16 Jan 2014 09:26:50 -0600 |
parents | 3d7526f6115b |
children | fc1bb49e58a9 |
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 | 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 | 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 | 6 |
7 USE_RMDIR(NEWTOY(rmdir, "<1p", TOYFLAG_BIN)) | |
8 | |
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 | 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 | 17 */ |
18 | |
19 #include "toys.h" | |
20 | |
21 static void do_rmdir(char *name) | |
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 | 39 } |
40 | |
41 void rmdir_main(void) | |
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 | 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 | 46 } |