2002-09-19 Jeff Johnston <jjohnstn@redhat.com>

* libc/posix/opendir.c (opendir): Change code to check
        for HAVE_FCNTL before calling fcntl.
        * libc/search/hash.c (hash_open): Ditto.
        * libc/search/hash_page.c (open_tmp): Ditto.
        * libc/reent/Makefile.am: Add fcntlr.c.
        * libc/reent/Makefile.in: Regenerated.
        * libc/reent/fcntlr.c: New file.
        * libc/stdio/fdopen.c (_fdopen_r): Change to call _fcntl_r
        instead of _fcntl when HAVE_FCNTL flag is set.
        * libc/syscalls/sysfcntl.c (fcntl): Check for HAVE_FCNTL flag
        to see if _fcntl or _fcntl_r should be called.  If flag is not
        set, default to ENOSYS stub.
This commit is contained in:
Jeff Johnston 2002-09-19 21:28:52 +00:00
parent 0688e43db7
commit 50558bf3bd
9 changed files with 111 additions and 13 deletions

View File

@ -1,3 +1,18 @@
2002-09-19 Jeff Johnston <jjohnstn@redhat.com>
* libc/posix/opendir.c (opendir): Change code to check
for HAVE_FCNTL before calling fcntl.
* libc/search/hash.c (hash_open): Ditto.
* libc/search/hash_page.c (open_tmp): Ditto.
* libc/reent/Makefile.am: Add fcntlr.c.
* libc/reent/Makefile.in: Regenerated.
* libc/reent/fcntlr.c: New file.
* libc/stdio/fdopen.c (_fdopen_r): Change to call _fcntl_r
instead of _fcntl when HAVE_FCNTL flag is set.
* libc/syscalls/sysfcntl.c (fcntl): Check for HAVE_FCNTL flag
to see if _fcntl or _fcntl_r should be called. If flag is not
set, default to ENOSYS stub.
2002-09-16 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/wchar.h (mbstate_t): Change protective flag to

View File

@ -52,10 +52,14 @@ opendir(name)
{
register DIR *dirp;
register int fd;
int rc = 0;
if ((fd = open(name, 0)) == -1)
return NULL;
if (fcntl(fd, F_SETFD, 1) == -1 ||
#ifdef HAVE_FCNTL
rc = fcntl(fd, F_SETFD, 1);
#endif
if (rc == -1 ||
(dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
close (fd);
return NULL;

View File

@ -33,6 +33,7 @@ GENERAL_SOURCES = \
closer.c \
reent.c \
impure.c \
fcntlr.c \
fstatr.c \
getreent.c \
linkr.c \
@ -69,6 +70,7 @@ CHEWOUT_FILES = \
closer.def \
reent.def \
execr.def \
fcntlr.def \
fstatr.def \
linkr.def \
lseekr.def \

View File

@ -130,6 +130,7 @@ GENERAL_SOURCES = \
closer.c \
reent.c \
impure.c \
fcntlr.c \
fstatr.c \
getreent.c \
linkr.c \
@ -162,6 +163,7 @@ CHEWOUT_FILES = \
closer.def \
reent.def \
execr.def \
fcntlr.def \
fstatr.def \
linkr.def \
lseekr.def \
@ -192,17 +194,17 @@ DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LIBS = @LIBS@
@USE_LIBTOOL_FALSE@lib_a_OBJECTS = closer.$(OBJEXT) reent.$(OBJEXT) \
@USE_LIBTOOL_FALSE@impure.$(OBJEXT) fstatr.$(OBJEXT) getreent.$(OBJEXT) \
@USE_LIBTOOL_FALSE@linkr.$(OBJEXT) lseekr.$(OBJEXT) openr.$(OBJEXT) \
@USE_LIBTOOL_FALSE@readr.$(OBJEXT) signalr.$(OBJEXT) signgam.$(OBJEXT) \
@USE_LIBTOOL_FALSE@sbrkr.$(OBJEXT) statr.$(OBJEXT) timer.$(OBJEXT) \
@USE_LIBTOOL_FALSE@unlinkr.$(OBJEXT) writer.$(OBJEXT)
@USE_LIBTOOL_FALSE@impure.$(OBJEXT) fcntlr.$(OBJEXT) fstatr.$(OBJEXT) \
@USE_LIBTOOL_FALSE@getreent.$(OBJEXT) linkr.$(OBJEXT) lseekr.$(OBJEXT) \
@USE_LIBTOOL_FALSE@openr.$(OBJEXT) readr.$(OBJEXT) signalr.$(OBJEXT) \
@USE_LIBTOOL_FALSE@signgam.$(OBJEXT) sbrkr.$(OBJEXT) statr.$(OBJEXT) \
@USE_LIBTOOL_FALSE@timer.$(OBJEXT) unlinkr.$(OBJEXT) writer.$(OBJEXT)
LTLIBRARIES = $(noinst_LTLIBRARIES)
@USE_LIBTOOL_TRUE@libreent_la_OBJECTS = closer.lo reent.lo impure.lo \
@USE_LIBTOOL_TRUE@fstatr.lo getreent.lo linkr.lo lseekr.lo openr.lo \
@USE_LIBTOOL_TRUE@readr.lo signalr.lo signgam.lo sbrkr.lo statr.lo \
@USE_LIBTOOL_TRUE@timer.lo unlinkr.lo writer.lo
@USE_LIBTOOL_TRUE@fcntlr.lo fstatr.lo getreent.lo linkr.lo lseekr.lo \
@USE_LIBTOOL_TRUE@openr.lo readr.lo signalr.lo signgam.lo sbrkr.lo \
@USE_LIBTOOL_TRUE@statr.lo timer.lo unlinkr.lo writer.lo
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)

View File

@ -0,0 +1,65 @@
/* Reentrant versions of fcntl system call. This implementation just
calls the fcntl system call. */
#include <reent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <_syslist.h>
/* Some targets provides their own versions of these functions. Those
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
#ifdef _REENT_ONLY
#ifndef REENTRANT_SYSCALLS_PROVIDED
#define REENTRANT_SYSCALLS_PROVIDED
#endif
#endif
#ifndef REENTRANT_SYSCALLS_PROVIDED
/* We use the errno variable used by the system dependent layer. */
#undef errno
extern int errno;
/*
FUNCTION
<<_fcntl_r>>---Reentrant version of fcntl
INDEX
_fcntl_r
ANSI_SYNOPSIS
#include <reent.h>
int _fcntl_r(struct _reent *<[ptr]>,
int <[fd]>, int <[cmd]>, <[arg]>);
TRAD_SYNOPSIS
#include <reent.h>
int _fcntl_r(<[ptr]>, <[fd]>, <[cmd]>, <[arg]>)
struct _reent *<[ptr]>;
int <[fd]>;
int <[cmd]>;
int <[arg]>;
DESCRIPTION
This is a reentrant version of <<fcntl>>. It
takes a pointer to the global data block, which holds
<<errno>>.
*/
int
_fcntl_r (ptr, fd, cmd, arg)
struct _reent *ptr;
int fd;
int cmd;
int arg;
{
int ret;
errno = 0;
if ((ret = _fcntl (fd, cmd, arg)) == -1 && errno != 0)
ptr->_errno = errno;
return ret;
}
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */

View File

@ -143,7 +143,9 @@ __hash_open(file, flags, mode, info, dflags)
fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0)
new_table = 1;
#ifdef HAVE_FCNTL
(void)fcntl(hashp->fp, F_SETFD, 1);
#endif
}
if (new_table) {
if (!(hashp = init_hash(hashp, file, (HASHINFO *)info)))

View File

@ -869,7 +869,9 @@ open_temp(hashp)
(void)sigprocmask(SIG_BLOCK, &set, &oset);
if ((hashp->fp = mkstemp(namestr)) != -1) {
(void)unlink(namestr);
#ifdef HAVE_FCNTL
(void)fcntl(hashp->fp, F_SETFD, 1);
#endif
}
(void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL);
return (hashp->fp != -1 ? 0 : -1);

View File

@ -64,7 +64,7 @@ _DEFUN (_fdopen_r, (ptr, fd, mode),
/* make sure the mode the user wants is a subset of the actual mode */
#ifdef HAVE_FCNTL
if ((fdflags = _fcntl (fd, F_GETFL, 0)) < 0)
if ((fdflags = _fcntl_r (ptr, fd, F_GETFL, 0)) < 0)
return 0;
fdmode = fdflags & O_ACCMODE;
if (fdmode != O_RDWR && (fdmode != (oflags & O_ACCMODE)))

View File

@ -2,6 +2,7 @@
/* only called from stdio/fdopen.c, so arg can be int. */
#include <reent.h>
#include <errno.h>
int
fcntl (fd, flag, arg)
@ -9,9 +10,14 @@ fcntl (fd, flag, arg)
int flag;
int arg;
{
#ifdef REENTRANT_SYSCALLS_PROVIDED
#ifdef HAVE_FCNTL
# ifdef REENTRANT_SYSCALLS_PROVIDED
return _fcntl_r (_REENT, fd, flag, arg);
#else
# else
return _fcntl (fd, flag, arg);
#endif
# endif
#else /* !HAVE_FCNTL */
errno = ENOSYS;
return -1;
#endif /& !HAVE_FCNTL */
}