No specific user configuration
[platform/upstream/bash.git] / examples / loadables / unlink.c
1 /* unlink - remove a directory entry */
2
3 /* Should only be used to remove directories by a superuser prepared to let
4    fsck clean up the file system. */
5
6 /*
7    Copyright (C) 1999-2009 Free Software Foundation, Inc.
8
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.
14
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.
19
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/>.
22 */
23
24 #include <config.h>
25
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29
30 #include <stdio.h>
31 #include <errno.h>
32
33 #include "builtins.h"
34 #include "shell.h"
35 #include "common.h"
36
37 #ifndef errno
38 extern int errno;
39 #endif
40
41 unlink_builtin (list)
42      WORD_LIST *list;
43 {
44   if (list == 0)
45     {
46       builtin_usage ();
47       return (EX_USAGE);
48     }
49
50   if (unlink (list->word->word) != 0)
51     {
52       builtin_error ("%s: cannot unlink: %s", list->word->word, strerror (errno));
53       return (EXECUTION_FAILURE);
54     }
55
56   return (EXECUTION_SUCCESS);
57 }
58
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
64 };
65
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 */
73 };