summaryrefslogtreecommitdiff
path: root/sysdeps/posix
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/posix')
-rw-r--r--sysdeps/posix/getcwd.c15
-rw-r--r--sysdeps/posix/ttyname.c10
-rw-r--r--sysdeps/posix/ttyname_r.c4
3 files changed, 10 insertions, 19 deletions
diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c
index 4ea90a7320..a83b286380 100644
--- a/sysdeps/posix/getcwd.c
+++ b/sysdeps/posix/getcwd.c
@@ -187,10 +187,6 @@ extern char *alloca ();
#define __getcwd getcwd
#endif
-#if defined HAVE_READDIR_R && !defined _LIBC
-#define __readdir_r readdir_r
-#endif
-
/* Get the pathname of the current working directory, and put it in SIZE
bytes of BUF. Returns NULL if the directory couldn't be determined or
SIZE was too small. If successful, returns BUF. In GNU, if BUF is
@@ -254,9 +250,6 @@ __getcwd (buf, size)
{
register DIR *dirstream;
struct dirent *d;
-#if defined HAVE_READDIR_R || defined _LIBC
- struct dirent dirbuf;
-#endif
dev_t dotdev;
ino_t dotino;
char mount_point;
@@ -299,13 +292,7 @@ __getcwd (buf, size)
dirstream = __opendir (dotp);
if (dirstream == NULL)
goto lose;
- while (
-#if defined HAVE_READDIR_R || defined _LIBC
- __readdir_r (dirstream, &dirbuf, &d) >= 0
-#else
- (d = __readdir (dirstream)) != NULL
-#endif
- )
+ while ((d = __readdir (dirstream)) != NULL)
{
if (d->d_name[0] == '.' &&
(d->d_name[1] == '\0' ||
diff --git a/sysdeps/posix/ttyname.c b/sysdeps/posix/ttyname.c
index 043e91b084..ce384ebc0e 100644
--- a/sysdeps/posix/ttyname.c
+++ b/sysdeps/posix/ttyname.c
@@ -41,7 +41,7 @@ ttyname (fd)
dev_t mydev;
ino_t myino;
DIR *dirstream;
- struct dirent dirbuf, *d;
+ struct dirent *d;
int save = errno;
if (!__isatty (fd))
@@ -56,7 +56,7 @@ ttyname (fd)
if (dirstream == NULL)
return NULL;
- while (__readdir_r (dirstream, &dirbuf, &d) >= 0)
+ while ((d = readdir (dirstream)) != NULL)
if ((ino_t) d->d_fileno == myino)
{
size_t dlen = _D_ALLOC_NAMLEN (d);
@@ -66,7 +66,11 @@ ttyname (fd)
namelen = 2 * (sizeof (dev) + dlen); /* Big enough. */
name = malloc (namelen);
if (! name)
- return NULL;
+ {
+ /* Perhaps it helps to free the directory stream buffer. */
+ (void) closedir (dirstream);
+ return NULL;
+ }
(void) memcpy (name, dev, sizeof (dev) - 1);
name[sizeof (dev) - 1] = '/';
}
diff --git a/sysdeps/posix/ttyname_r.c b/sysdeps/posix/ttyname_r.c
index c7cf21aeee..d404245be5 100644
--- a/sysdeps/posix/ttyname_r.c
+++ b/sysdeps/posix/ttyname_r.c
@@ -43,7 +43,7 @@ __ttyname_r (fd, buf, buflen)
dev_t mydev;
ino_t myino;
DIR *dirstream;
- struct dirent dirbuf, *d;
+ struct dirent *d;
int save = errno;
/* Test for the absolute minimal size. This makes life easier inside
@@ -74,7 +74,7 @@ __ttyname_r (fd, buf, buflen)
buf[sizeof (dev) - 1] = '/';
buflen -= sizeof (dev);
- while (__readdir_r (dirstream, &dirbuf, &d) >= 0)
+ while ((d = readdir (dirstream)) != NULL)
if ((ino_t) d->d_fileno == myino)
{
char *cp;