about summary refs log tree commit diff
path: root/sysdeps/posix
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/posix')
-rw-r--r--sysdeps/posix/getcwd.c17
-rw-r--r--sysdeps/posix/ttyname.c9
2 files changed, 14 insertions, 12 deletions
diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c
index 4bebece975..af858a2643 100644
--- a/sysdeps/posix/getcwd.c
+++ b/sysdeps/posix/getcwd.c
@@ -292,16 +292,15 @@ __getcwd (buf, size)
       while ((d = readdir (dirstream)) != NULL)
 	{
 	  if (d->d_name[0] == '.' &&
-	      (d->d_namlen == 1 || (d->d_namlen == 2 && d->d_name[1] == '.')))
+	      (d->d_name[1] == '\0' ||
+	       (d->d_name[1] == '.' && d->d_name[2] == '\0')))
 	    continue;
 	  if (mount_point || d->d_ino == thisino)
 	    {
-	      char *name = __alloca (dotlist + dotsize - dotp +
-				     1 + d->d_namlen + 1);
+	      char name[dotlist + dotsize - dotp + 1 + _D_ALLOC_NAMLEN (d)];
 	      memcpy (name, dotp, dotlist + dotsize - dotp);
 	      name[dotlist + dotsize - dotp] = '/';
-	      memcpy (&name[dotlist + dotsize - dotp + 1],
-		      d->d_name, d->d_namlen + 1);
+	      strcpy (&name[dotlist + dotsize - dotp + 1], d->d_name);
 	      if (__lstat (name, &st) < 0)
 		{
 		  int save = errno;
@@ -322,7 +321,9 @@ __getcwd (buf, size)
 	}
       else
 	{
-	  if (pathp - path < d->d_namlen + 1)
+	  size_t namlen = _D_EXACT_NAMLEN (d);
+
+	  if (pathp - path < namlen)
 	    {
 	      if (buf != NULL)
 		{
@@ -344,8 +345,8 @@ __getcwd (buf, size)
 		  path = buf;
 		}
 	    }
-	  pathp -= d->d_namlen;
-	  (void) memcpy (pathp, d->d_name, d->d_namlen);
+	  pathp -= namlen;
+	  (void) memcpy (pathp, d->d_name, namlen);
 	  *--pathp = '/';
 	  (void) closedir (dirstream);
 	}
diff --git a/sysdeps/posix/ttyname.c b/sysdeps/posix/ttyname.c
index 50e3c79341..b0650b38b0 100644
--- a/sysdeps/posix/ttyname.c
+++ b/sysdeps/posix/ttyname.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -56,17 +56,18 @@ DEFUN(ttyname, (fd), int fd)
   while ((d = readdir (dirstream)) != NULL)
     if (d->d_fileno == myino)
       {
-	if (sizeof (dev) + d->d_namlen + 1 > namelen)
+	size_t dlen = _D_ALLOC_NAMLEN (d);
+	if (sizeof (dev) + dlen > namelen)
 	  {
 	    free (name);
-	    namelen = 2 * (sizeof (dev) + d->d_namlen + 1); /* Big enough.  */
+	    namelen = 2 * (sizeof (dev) + dlen); /* Big enough.  */
 	    name = malloc (namelen);
 	    if (! name)
 	      return NULL;
 	    (void) memcpy (name, dev, sizeof (dev) - 1);
 	    name[sizeof (dev) - 1] = '/';
 	  }
-	(void) memcpy (&name[sizeof (dev)], d->d_name, d->d_namlen + 1);
+	(void) memcpy (&name[sizeof (dev)], d->d_name, dlen);
 	if (stat (name, &st) == 0 && st.st_dev == mydev)
 	  {
 	    (void) closedir (dirstream);