Improve the check for departures from C89, and fix the departures
[platform/upstream/coreutils.git] / src / remove.h
1 /* Remove directory entries.
2
3    Copyright (C) 1998, 2000, 2002, 2003, 2004, 2005, 2006 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 struct rm_options
26 {
27   /* If true, ignore nonexistent files.  */
28   bool ignore_missing_files;
29
30   /* If true, query the user about whether to remove each file.  */
31   bool interactive;
32
33   /* If true, do not traverse into (or remove) any directory that is
34      on a file system (i.e., that has a different device number) other
35      than that of the corresponding command line argument.  Note that
36      even without this option, rm will fail in the end, due to its
37      probable inability to remove the mount point.  But there, the
38      diagnostic comes too late -- after removing all contents.  */
39   bool one_file_system;
40
41   /* If true, recursively remove directories.  */
42   bool recursive;
43
44   /* Pointer to the device and inode numbers of `/', when --recursive
45      and preserving `/'.  Otherwise NULL.  */
46   struct dev_ino *root_dev_ino;
47
48   /* If nonzero, stdin is a tty.  */
49   bool stdin_tty;
50
51   /* If true, display the name of each file removed.  */
52   bool verbose;
53
54   /* If true, treat the failure by the rm function to restore the
55      current working directory as a fatal error.  I.e., if this field
56      is true and the rm function cannot restore cwd, it must exit with
57      a nonzero status.  Some applications require that the rm function
58      restore cwd (e.g., mv) and some others do not (e.g., rm,
59      in many cases).  */
60   bool require_restore_cwd;
61 };
62
63 enum RM_status
64 {
65   /* These must be listed in order of increasing seriousness. */
66   RM_OK = 2,
67   RM_USER_DECLINED,
68   RM_ERROR,
69   RM_NONEMPTY_DIR
70 };
71
72 # define VALID_STATUS(S) \
73   ((S) == RM_OK || (S) == RM_USER_DECLINED || (S) == RM_ERROR)
74
75 # define UPDATE_STATUS(S, New_value)                            \
76   do                                                            \
77     {                                                           \
78       if ((New_value) == RM_ERROR                               \
79           || ((New_value) == RM_USER_DECLINED && (S) == RM_OK)) \
80         (S) = (New_value);                                      \
81     }                                                           \
82   while (0)
83
84 enum RM_status rm (size_t n_files, char const *const *file,
85                    struct rm_options const *x);
86
87 #endif