Patch-ID: bash41-003
[bash.git] / examples / loadables / unlink.c
blob07e3f3d45ad99a099f5a7925115c59c71d1a107b
1 /* unlink - remove a directory entry */
3 /* Should only be used to remove directories by a superuser prepared to let
4 fsck clean up the file system. */
6 /*
7 Copyright (C) 1999-2009 Free Software Foundation, Inc.
9 This file is part of GNU Bash.
10 Bash is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 Bash is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with Bash. If not, see <http://www.gnu.org/licenses/>.
24 #include <config.h>
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
30 #include <stdio.h>
31 #include <errno.h>
33 #include "builtins.h"
34 #include "shell.h"
35 #include "common.h"
37 #ifndef errno
38 extern int errno;
39 #endif
41 unlink_builtin (list)
42 WORD_LIST *list;
44 if (list == 0)
46 builtin_usage ();
47 return (EX_USAGE);
50 if (unlink (list->word->word) != 0)
52 builtin_error ("%s: cannot unlink: %s", list->word->word, strerror (errno));
53 return (EXECUTION_FAILURE);
56 return (EXECUTION_SUCCESS);
59 char *unlink_doc[] = {
60 "Remove a directory entry.",
61 "",
62 "Forcibly remove a directory entry, even if it's a directory.",
63 (char *)NULL
66 struct builtin unlink_struct = {
67 "unlink", /* builtin name */
68 unlink_builtin, /* function implementing the builtin */
69 BUILTIN_ENABLED, /* initial flags for builtin */
70 unlink_doc, /* array of long documentation strings. */
71 "unlink name", /* usage synopsis; becomes short_doc */
72 0 /* reserved for internal use */