blob: 5d7bf8ca210f36ddc0c36114c50cbacb971acbbf [file] [log] [blame]
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001/* rmdir - remove directory */
2
3/* See Makefile for compilation details. */
4
Jari Aalto31859422009-01-12 13:36:28 +00005/*
6 Copyright (C) 1999-2009 Free Software Foundation, Inc.
7
8 This file is part of GNU Bash.
9 Bash is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Bash is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Bash. If not, see <http://www.gnu.org/licenses/>.
21*/
22
Jari Aaltoccc6cda1996-12-23 17:02:34 +000023#include "config.h"
24
25#include <stdio.h>
26#include <errno.h>
27#include "builtins.h"
28#include "shell.h"
Jari Aalto31859422009-01-12 13:36:28 +000029#include "common.h"
Jari Aaltoccc6cda1996-12-23 17:02:34 +000030
31#if !defined (errno)
Ricardo Cerqueiraa02fbff2013-07-25 22:35:34 +010032#include <errno.h>
Jari Aaltoccc6cda1996-12-23 17:02:34 +000033#endif
34
35rmdir_builtin (list)
36 WORD_LIST *list;
37{
38 int rval;
39 WORD_LIST *l;
40
41 if (no_options (list))
42 return (EX_USAGE);
43
44 for (rval = EXECUTION_SUCCESS, l = list; l; l = l->next)
45 if (rmdir (l->word->word) < 0)
46 {
47 builtin_error ("%s: %s", l->word->word, strerror (errno));
48 rval = EXECUTION_FAILURE;
49 }
50
51 return rval;
52}
53
54char *rmdir_doc[] = {
Jari Aalto31859422009-01-12 13:36:28 +000055 "Remove directory.",
56 "",
Jari Aaltoccc6cda1996-12-23 17:02:34 +000057 "rmdir removes the directory entry specified by each argument,",
58 "provided the directory is empty.",
59 (char *)NULL
60};
61
62/* The standard structure describing a builtin command. bash keeps an array
63 of these structures. */
64struct builtin rmdir_struct = {
65 "rmdir", /* builtin name */
66 rmdir_builtin, /* function implementing the builtin */
67 BUILTIN_ENABLED, /* initial flags for builtin */
68 rmdir_doc, /* array of long documentation strings. */
69 "rmdir directory ...", /* usage synopsis; becomes short_doc */
70 0 /* reserved for internal use */
71};