summaryrefslogtreecommitdiff
path: root/lib/savewd.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/savewd.h')
-rw-r--r--lib/savewd.h56
1 files changed, 30 insertions, 26 deletions
diff --git a/lib/savewd.h b/lib/savewd.h
index 880b8f1..7b454b6 100644
--- a/lib/savewd.h
+++ b/lib/savewd.h
@@ -1,11 +1,11 @@
/* Save and restore the working directory, possibly using a subprocess.
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2009-2016 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert. */
@@ -24,6 +23,14 @@
#include <stdbool.h>
#include <sys/types.h>
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef SAVEWD_INLINE
+# define SAVEWD_INLINE _GL_INLINE
+#endif
+
/* A saved working directory. The member names and constants defined
by this structure are private to the savewd module. */
struct savewd
@@ -32,29 +39,29 @@ struct savewd
enum
{
/* This object has been created but does not yet represent
- the working directory. */
+ the working directory. */
INITIAL_STATE,
/* val.fd is the original working directory's file descriptor.
- It is still the working directory. */
+ It is still the working directory. */
FD_STATE,
/* Like FD_STATE, but the working directory has changed, so
- restoring it will require a fchdir. */
+ restoring it will require a fchdir. */
FD_POST_CHDIR_STATE,
/* Fork and let the subprocess do the work. val.child is 0 in a
- child, negative in a childless parent, and the child process
- ID in a parent with a child. */
+ child, negative in a childless parent, and the child process
+ ID in a parent with a child. */
FORKING_STATE,
/* A serious problem argues against further efforts. val.errnum
- contains the error number (e.g., EIO). */
+ contains the error number (e.g., EIO). */
ERROR_STATE,
/* savewd_finish has been called, so the application no longer
- cares whether the working directory is saved, and there is no
- more work to do. */
+ cares whether the working directory is saved, and there is no
+ more work to do. */
FINAL_STATE
} state;
@@ -68,27 +75,22 @@ struct savewd
};
/* Initialize a saved working directory object. */
-static inline void
+SAVEWD_INLINE void
savewd_init (struct savewd *wd)
{
wd->state = INITIAL_STATE;
}
-/* Options for savewd_chdir. */
+/* Options for savewd_chdir. Can be ORed together. */
enum
{
/* Do not follow symbolic links, if supported. */
SAVEWD_CHDIR_NOFOLLOW = 1,
- /* The directory should be readable, so fail if it happens to be
- discovered that the directory is not readable. (Unreadable
- directories are not necessarily diagnosed, though.) */
- SAVEWD_CHDIR_READABLE = 2,
-
/* Do not chdir if the directory is readable; simply succeed
without invoking chdir if the directory was opened. */
- SAVEWD_CHDIR_SKIP_READABLE = 4
+ SAVEWD_CHDIR_SKIP_READABLE = 2
};
/* Change the directory, and if successful, record into *WD the fact
@@ -107,7 +109,7 @@ enum
Return -2 if a subprocess was spun off to do the real work, -1
(setting errno) if unsuccessful, 0 if successful. */
int savewd_chdir (struct savewd *wd, char const *dir, int options,
- int open_result[2]);
+ int open_result[2]);
/* Restore the working directory from *WD. STATUS indicates the exit
status corresponding to the work done since the last save; this is
@@ -118,7 +120,7 @@ int savewd_chdir (struct savewd *wd, char const *dir, int options,
int savewd_restore (struct savewd *wd, int status);
/* Return WD's error number, or 0 if WD is not in an error state. */
-static inline int
+SAVEWD_INLINE int _GL_ATTRIBUTE_PURE
savewd_errno (struct savewd const *wd)
{
return (wd->state == ERROR_STATE ? wd->val.errnum : 0);
@@ -143,7 +145,9 @@ void savewd_finish (struct savewd *wd);
Return the maximum exit status that any call to ACT returned, or
EXIT_SUCCESS (i.e., 0) if no calls were made. */
int savewd_process_files (int n_files, char **file,
- int (*act) (char *, struct savewd *, void *),
- void *options);
+ int (*act) (char *, struct savewd *, void *),
+ void *options);
+
+_GL_INLINE_HEADER_END
#endif