Imported from ../bash-2.05b.tar.gz.
[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 #include <config.h>
7
8 #ifdef HAVE_UNISTD_H
9 #include <unistd.h>
10 #endif
11
12 #include <stdio.h>
13 #include <errno.h>
14
15 #include "builtins.h"
16 #include "shell.h"
17
18 #ifndef errno
19 extern int errno;
20 #endif
21
22 unlink_builtin (list)
23      WORD_LIST *list;
24 {
25   if (list == 0)
26     {
27       builtin_usage ();
28       return (EX_USAGE);
29     }
30
31   if (unlink (list->word->word) != 0)
32     {
33       builtin_error ("%s: cannot unlink: %s", list->word->word, strerror (errno));
34       return (EXECUTION_FAILURE);
35     }
36
37   return (EXECUTION_SUCCESS);
38 }
39
40 char *unlink_doc[] = {
41         "Remove a directory entry.",
42         (char *)NULL
43 };
44
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 */
52 };