Tizen 2.0 Release
[external/tizen-coreutils.git] / src / remove.h
1 /* Remove directory entries.
2
3    Copyright (C) 1998, 2000, 2002, 2003, 2004, 2005, 2006, 2007 Free
4    Software Foundation, Inc.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software Foundation,
18    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19
20 #ifndef REMOVE_H
21 # define REMOVE_H
22
23 # include "dev-ino.h"
24
25 enum rm_interactive
26 {
27   /* Start with any number larger than 1, so that any legacy tests
28      against values of 0 or 1 will fail.  */
29   RMI_ALWAYS = 3,
30   RMI_SOMETIMES,
31   RMI_NEVER
32 };
33
34 struct rm_options
35 {
36   /* If true, ignore nonexistent files.  */
37   bool ignore_missing_files;
38
39   /* If true, query the user about whether to remove each file.  */
40   enum rm_interactive interactive;
41
42   /* If true, do not traverse into (or remove) any directory that is
43      on a file system (i.e., that has a different device number) other
44      than that of the corresponding command line argument.  Note that
45      even without this option, rm will fail in the end, due to its
46      probable inability to remove the mount point.  But there, the
47      diagnostic comes too late -- after removing all contents.  */
48   bool one_file_system;
49
50   /* If true, recursively remove directories.  */
51   bool recursive;
52
53   /* Pointer to the device and inode numbers of `/', when --recursive
54      and preserving `/'.  Otherwise NULL.  */
55   struct dev_ino *root_dev_ino;
56
57   /* If nonzero, stdin is a tty.  */
58   bool stdin_tty;
59
60   /* If true, display the name of each file removed.  */
61   bool verbose;
62
63   /* If true, treat the failure by the rm function to restore the
64      current working directory as a fatal error.  I.e., if this field
65      is true and the rm function cannot restore cwd, it must exit with
66      a nonzero status.  Some applications require that the rm function
67      restore cwd (e.g., mv) and some others do not (e.g., rm,
68      in many cases).  */
69   bool require_restore_cwd;
70 };
71
72 enum RM_status
73 {
74   /* These must be listed in order of increasing seriousness. */
75   RM_OK = 2,
76   RM_USER_DECLINED,
77   RM_ERROR,
78   RM_NONEMPTY_DIR
79 };
80
81 # define VALID_STATUS(S) \
82   ((S) == RM_OK || (S) == RM_USER_DECLINED || (S) == RM_ERROR)
83
84 # define UPDATE_STATUS(S, New_value)                            \
85   do                                                            \
86     {                                                           \
87       if ((New_value) == RM_ERROR                               \
88           || ((New_value) == RM_USER_DECLINED && (S) == RM_OK)) \
89         (S) = (New_value);                                      \
90     }                                                           \
91   while (0)
92
93 enum RM_status rm (size_t n_files, char const *const *file,
94                    struct rm_options const *x);
95
96 #endif