1998-03-18  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/opendir.c (__opendir): Don't block on FIFOs etc.
	Optimize memmory handling.
	* sysdeps/unix/closedir.c: Optmize memory handling.
This commit is contained in:
Ulrich Drepper 1998-03-18 09:01:59 +00:00
parent 4886901212
commit 9eecb5e8f3
4 changed files with 26 additions and 27 deletions

View File

@ -1,3 +1,9 @@
1998-03-18 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/unix/opendir.c (__opendir): Don't block on FIFOs etc.
Optimize memmory handling.
* sysdeps/unix/closedir.c: Optmize memory handling.
1998-03-17 Ulrich Drepper <drepper@cygnus.com> 1998-03-17 Ulrich Drepper <drepper@cygnus.com>
* posix/wordexp.c (parse_param): Fix off-by-on error in $@ * posix/wordexp.c (parse_param): Fix off-by-on error in $@

View File

@ -1377,7 +1377,7 @@ envsubst:
if (s == NULL) if (s == NULL)
return WRDE_NOSPACE; return WRDE_NOSPACE;
*word = memcpy (s, __libc_argv[p], len); *word = memcpy (s, __libc_argv[p], len);
*max_length = *word_length = len; *max_length = *word_length = len - 1;
} }
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1991, 1993, 1995, 1996 Free Software Foundation, Inc. /* Copyright (C) 1991, 1993, 1995, 1996, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or The GNU C Library is free software; you can redistribute it and/or
@ -39,7 +39,6 @@ __closedir (DIR *dirp)
__libc_lock_lock (dirp->lock); __libc_lock_lock (dirp->lock);
fd = dirp->fd; fd = dirp->fd;
free ((void *) dirp->data);
__libc_lock_fini (dirp->lock); __libc_lock_fini (dirp->lock);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc. /* Copyright (C) 1991, 92, 93, 94, 95, 96, 98 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or The GNU C Library is free software; you can redistribute it and/or
@ -36,6 +36,8 @@ __opendir (const char *name)
DIR *dirp; DIR *dirp;
struct stat statbuf; struct stat statbuf;
int fd; int fd;
size_t allocation;
int save_errno;
if (name[0] == '\0') if (name[0] == '\0')
{ {
@ -45,7 +47,7 @@ __opendir (const char *name)
return NULL; return NULL;
} }
fd = __open (name, O_RDONLY); fd = __open (name, O_RDONLY|O_NDELAY);
if (fd < 0) if (fd < 0)
return NULL; return NULL;
@ -56,39 +58,31 @@ __opendir (const char *name)
goto lose; goto lose;
if (! S_ISDIR (statbuf.st_mode)) if (! S_ISDIR (statbuf.st_mode))
{ {
__set_errno (ENOTDIR); save_errno = ENOTDIR;
goto lose; goto lose2;
}
dirp = (DIR *) calloc (1, sizeof (DIR)); /* Zero-fill. */
if (dirp == NULL)
lose:
{
int save = errno;
(void) __close (fd);
__set_errno (save);
return NULL;
} }
#ifdef _STATBUF_ST_BLKSIZE #ifdef _STATBUF_ST_BLKSIZE
if (statbuf.st_blksize < sizeof (struct dirent)) if (statbuf.st_blksize < sizeof (struct dirent))
dirp->allocation = sizeof (struct dirent); allocation = sizeof (struct dirent);
else else
dirp->allocation = statbuf.st_blksize; allocation = statbuf.st_blksize;
#else #else
dirp->allocation = (BUFSIZ < sizeof (struct dirent) ? allocation = (BUFSIZ < sizeof (struct dirent)
sizeof (struct dirent) : BUFSIZ); ? sizeof (struct dirent) : BUFSIZ);
#endif #endif
dirp->data = (char *) malloc (dirp->allocation);
if (dirp->data == NULL) dirp = (DIR *) calloc (1, sizeof (DIR) + allocation); /* Zero-fill. */
if (dirp == NULL)
lose:
{ {
int save = errno; save_errno = errno;
free (dirp); lose2:
(void) __close (fd); (void) __close (fd);
__set_errno (save); __set_errno (save_errno);
return NULL; return NULL;
} }
dirp->data = (char *) (dirp + 1);
dirp->fd = fd; dirp->fd = fd;
__libc_lock_init (dirp->lock); __libc_lock_init (dirp->lock);