| 195 | } |
| 196 | |
| 197 | int |
| 198 | main (int argc, char **argv) |
| 199 | { |
| 200 | initialize_main (&argc, &argv); |
| 201 | set_program_name (argv[0]); |
| 202 | setlocale (LC_ALL, ""); |
| 203 | bindtextdomain (PACKAGE, LOCALEDIR); |
| 204 | textdomain (PACKAGE); |
| 205 | |
| 206 | atexit (close_stdout); |
| 207 | |
| 208 | int optc; |
| 209 | while ((optc = getopt_long (argc, argv, "pv", longopts, NULL)) != -1) |
| 210 | { |
| 211 | switch (optc) |
| 212 | { |
| 213 | case 'p': |
| 214 | remove_empty_parents = true; |
| 215 | break; |
| 216 | case IGNORE_FAIL_ON_NON_EMPTY_OPTION: |
| 217 | ignore_fail_on_non_empty = true; |
| 218 | break; |
| 219 | case 'v': |
| 220 | verbose = true; |
| 221 | break; |
| 222 | case_GETOPT_HELP_CHAR; |
| 223 | case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); |
| 224 | default: |
| 225 | usage (EXIT_FAILURE); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | if (optind == argc) |
| 230 | { |
| 231 | error (0, 0, _("missing operand")); |
| 232 | usage (EXIT_FAILURE); |
| 233 | } |
| 234 | |
| 235 | bool ok = true; |
| 236 | for (; optind < argc; ++optind) |
| 237 | { |
| 238 | char *dir = argv[optind]; |
| 239 | |
| 240 | /* Give a diagnostic for each attempted removal if --verbose. */ |
| 241 | if (verbose) |
| 242 | prog_fprintf (stdout, _("removing directory, %s"), quoteaf (dir)); |
| 243 | |
| 244 | if (rmdir (dir) != 0) |
| 245 | { |
| 246 | int rmdir_errno = errno; |
| 247 | if (ignorable_failure (rmdir_errno, dir)) |
| 248 | continue; |
| 249 | |
| 250 | /* Distinguish the case for a symlink with trailing slash. |
| 251 | On Linux, rmdir(2) confusingly does not follow the symlink, |
| 252 | thus giving the errno ENOTDIR, while on other systems the symlink |
| 253 | is followed. We don't provide consistent behavior here, |
| 254 | but at least we provide a more accurate error message. */ |
nothing calls this directly
no test coverage detected