blob: 3c829e3c95dc7f8d45f3b652414aacb0eeecfd51 [file] [log] [blame]
Jari Aaltob72432f1999-02-19 17:11:39 +00001/* 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
Jari Aalto31859422009-01-12 13:36:28 +00006/*
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
Jari Aaltob72432f1999-02-19 17:11:39 +000024#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"
Jari Aalto31859422009-01-12 13:36:28 +000035#include "common.h"
Jari Aaltob72432f1999-02-19 17:11:39 +000036
37#ifndef errno
Ricardo Cerqueiraa02fbff2013-07-25 22:35:34 +010038#include <errno.h>
Jari Aaltob72432f1999-02-19 17:11:39 +000039#endif
40
41unlink_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
59char *unlink_doc[] = {
60 "Remove a directory entry.",
Jari Aalto31859422009-01-12 13:36:28 +000061 "",
62 "Forcibly remove a directory entry, even if it's a directory.",
Jari Aaltob72432f1999-02-19 17:11:39 +000063 (char *)NULL
64};
65
66struct 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};