Patch-ID: bash32-032
[bash.git] / examples / loadables / unlink.c
blob8c81ad02d596fcefd107db253ccaef12b32314b8
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 #include <config.h>
8 #ifdef HAVE_UNISTD_H
9 #include <unistd.h>
10 #endif
12 #include <stdio.h>
13 #include <errno.h>
15 #include "builtins.h"
16 #include "shell.h"
18 #ifndef errno
19 extern int errno;
20 #endif
22 unlink_builtin (list)
23 WORD_LIST *list;
25 if (list == 0)
27 builtin_usage ();
28 return (EX_USAGE);
31 if (unlink (list->word->word) != 0)
33 builtin_error ("%s: cannot unlink: %s", list->word->word, strerror (errno));
34 return (EXECUTION_FAILURE);
37 return (EXECUTION_SUCCESS);
40 char *unlink_doc[] = {
41 "Remove a directory entry.",
42 (char *)NULL
45 struct builtin unlink_struct = {
46 "unlink", /* builtin name */
47 unlink_builtin, /* function implementing the builtin */
48 BUILTIN_ENABLED, /* initial flags for builtin */
49 unlink_doc, /* array of long documentation strings. */
50 "unlink name", /* usage synopsis; becomes short_doc */
51 0 /* reserved for internal use */