[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
openat minor cleanups
From: |
Paul Eggert |
Subject: |
openat minor cleanups |
Date: |
Thu, 02 Dec 2004 23:03:42 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
I installed this minor cleanup for openat.
For the FIXME, Solaris 9 actually defines AT_FDCWD to be 0xffd19553
but I think this is a bug in Solaris, since this means AT_FDCWD is of
type 'unsigned int' on all Solaris platforms, but it should be of type
'int'. So I used the equivalent 32-bit 'int' value instead.
2004-12-02 Paul Eggert <address@hidden>
* lib/openat.c: Include "openat.h" before other include files.
Include "exitfail.h".
(openat): Remove #undef; no longer needed now that we include openat.h
first.
(rpl_openat): Add comment about mode_t promotion. Simplify
code a bit by moving initializations around. Use exit_failure
rather than EXIT_FAILURE.
* lib/openat.h: Add copyright and authorship notice.
(AT_FDCWD): Use the same value Solaris 9 uses, except of type
'int' not 'unsigned int'.
* m4/openat.m4: Add copyright notice.
(gl_FUNC_OPENAT): Require gl_USE_SYSTEM_EXTENSIONS, since Solaris
requires __EXTENSIONS__ to be defined when compiling pedantically,
if you want AT_FDCWD.
Index: lib/openat.c
===================================================================
RCS file: /fetish/cu/lib/openat.c,v
retrieving revision 1.3
diff -p -u -r1.3 openat.c
--- lib/openat.c 28 Nov 2004 22:41:57 -0000 1.3
+++ lib/openat.c 3 Dec 2004 06:43:15 -0000
@@ -19,10 +19,7 @@
#include <config.h>
-/* Disable the definition of openat to rpl_openat (from config.h) in this
- file. Otherwise, we'd get conflicting prototypes for rpl_openat on
- most systems. */
-#undef openat
+#include "openat.h"
#include <stdlib.h>
#include <stdarg.h>
@@ -30,9 +27,8 @@
#include <errno.h>
#include <fcntl.h>
-#include "openat.h"
-
#include "error.h"
+#include "exitfail.h"
#include "save-cwd.h"
#include "gettext.h"
@@ -46,42 +42,44 @@ int
rpl_openat (int fd, char const *filename, int flags, ...)
{
struct saved_cwd saved_cwd;
- int saved_errno = 0;
+ int saved_errno;
int new_fd;
- mode_t mode;
+ mode_t mode = 0;
if (flags & O_CREAT)
{
va_list arg;
va_start (arg, flags);
+
+ /* Assume that mode_t is passed compatibly with mode_t's type
+ after argument promotion. */
mode = va_arg (arg, mode_t);
+
va_end (arg);
}
- else
- {
- mode = 0;
- }
if (fd == AT_FDCWD || *filename == '/')
return open (filename, flags, mode);
if (save_cwd (&saved_cwd) != 0)
- error (EXIT_FAILURE, errno,
+ error (exit_failure, errno,
_("openat: unable to record current working directory"));
+
if (fchdir (fd) != 0)
{
+ saved_errno = errno;
free_cwd (&saved_cwd);
+ errno = saved_errno;
return -1;
}
new_fd = open (filename, flags, mode);
- if (new_fd < 0)
- saved_errno = errno;
+ saved_errno = errno;
if (restore_cwd (&saved_cwd) != 0)
- error (EXIT_FAILURE, errno,
+ error (exit_failure, errno,
_("openat: unable to restore working directory"));
- errno = saved_errno;
+ errno = saved_errno;
return new_fd;
}
Index: lib/openat.h
===================================================================
RCS file: /fetish/cu/lib/openat.h,v
retrieving revision 1.2
diff -p -u -r1.2 openat.h
--- lib/openat.h 28 Nov 2004 22:42:08 -0000 1.2
+++ lib/openat.h 3 Dec 2004 06:43:15 -0000
@@ -1,10 +1,28 @@
+/* provide a replacement openat function
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* written by Jim Meyering */
+
#if HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifndef AT_FDCWD
-/* FIXME: use the same value Solaris uses */
-# define AT_FDCWD -999
+# define AT_FDCWD (-3041965) /* same value as Solaris 9 */
# ifdef __OPENAT_PREFIX
# undef openat
Index: m4/openat.m4
===================================================================
RCS file: /fetish/cu/m4/openat.m4,v
retrieving revision 1.1
diff -p -u -r1.1 openat.m4
--- m4/openat.m4 28 Nov 2004 20:55:40 -0000 1.1
+++ m4/openat.m4 3 Dec 2004 07:00:16 -0000
@@ -1,10 +1,27 @@
-#serial 1
+#serial 2
+# See if we need to use our replacement for Solaris' openat function.
+
+# Copyright (C) 2004 Free Software Foundation, Inc.
+
+# 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.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Written by Jim Meyering.
-# See if we need to use our replacement for Solaris' openat function.
AC_DEFUN([gl_FUNC_OPENAT],
[
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
AC_REPLACE_FUNCS(openat)
case $ac_cv_func_openat in
yes) ;;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- openat minor cleanups,
Paul Eggert <=