about summary refs log tree commit diff
path: root/sysdeps/posix/ttyname.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-08-15 06:12:25 +0000
committerUlrich Drepper <drepper@redhat.com>2000-08-15 06:12:25 +0000
commitb8fd550293431d4df42b281fc868ef0ab80e822b (patch)
treec120161943ff2e764d28b4059e9c2f9d4e7063da /sysdeps/posix/ttyname.c
parenta6bd56c7538360e8eecbe1cafea655cf890fb7e9 (diff)
downloadglibc-b8fd550293431d4df42b281fc868ef0ab80e822b.tar.gz
glibc-b8fd550293431d4df42b281fc868ef0ab80e822b.tar.xz
glibc-b8fd550293431d4df42b281fc868ef0ab80e822b.zip
Update.
	* sysdeps/posix/ttyname.c: Make name variable from getttyname function
	global (with file scope).  Add __libc_subfreeres function to free the
	string.
	* sysdeps/unix/sysv/linux/ttyname.c: Likewise.  Also for buf variable
	in ttyname function.

	* sysdeps/generic/strtok.c: Remove initializer for olds variable.

	* crypt/md5-crypt.c: Let destructor deallocate static buffer.

	* iconvdata/sjis.c (from_ucs4_lat1): Handle U005C and U007E by
	mapping them to /x5c and /x7e respectively.
Diffstat (limited to 'sysdeps/posix/ttyname.c')
-rw-r--r--sysdeps/posix/ttyname.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/sysdeps/posix/ttyname.c b/sysdeps/posix/ttyname.c
index a865ded9f5..fe132a39eb 100644
--- a/sysdeps/posix/ttyname.c
+++ b/sysdeps/posix/ttyname.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 96, 97, 98 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 96, 97, 98, 2000 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
@@ -26,10 +26,13 @@
 #include <string.h>
 #include <stdlib.h>
 
-char *__ttyname = NULL;
+char *__ttyname;
 
-static char * getttyname __P ((int fd, dev_t mydev, ino_t myino,
-			       int save, int *dostat)) internal_function;
+static char *getttyname (int fd, dev_t mydev, ino_t myino,
+			 int save, int *dostat) internal_function;
+
+
+static char *getttyname_name;
 
 static char *
 internal_function
@@ -41,8 +44,7 @@ getttyname (fd, mydev, myino, save, dostat)
      int *dostat;
 {
   static const char dev[] = "/dev";
-  static char *name;
-  static size_t namelen = 0;
+  static size_t namelen;
   struct stat st;
   DIR *dirstream;
   struct dirent *d;
@@ -63,20 +65,21 @@ getttyname (fd, mydev, myino, save, dostat)
 	size_t dlen = _D_ALLOC_NAMLEN (d);
 	if (sizeof (dev) + dlen > namelen)
 	  {
-	    free (name);
+	    free (getttyname_name);
 	    namelen = 2 * (sizeof (dev) + dlen); /* Big enough.  */
-	    name = malloc (namelen);
-	    if (! name)
+	    getttyname_name = malloc (namelen);
+	    if (! getttyname_name)
 	      {
 		*dostat = -1;
 		/* Perhaps it helps to free the directory stream buffer.  */
 		(void) __closedir (dirstream);
 		return NULL;
 	      }
-	    *((char *) __mempcpy (name, dev, sizeof (dev) - 1)) = '/';
+	    *((char *) __mempcpy (getttyname_name, dev, sizeof (dev) - 1))
+	      = '/';
 	  }
-	(void) __mempcpy (&name[sizeof (dev)], d->d_name, dlen);
-	if (stat (name, &st) == 0
+	(void) __mempcpy (&getttyname_name[sizeof (dev)], d->d_name, dlen);
+	if (stat (getttyname_name, &st) == 0
 #ifdef _STATBUF_ST_RDEV
 	    && S_ISCHR (st.st_mode) && st.st_rdev == mydev
 #else
@@ -85,9 +88,9 @@ getttyname (fd, mydev, myino, save, dostat)
 	   )
 	  {
 	    (void) __closedir (dirstream);
-	    __ttyname = name;
+	    __ttyname = getttyname_name;
 	    __set_errno (save);
-	    return name;
+	    return getttyname_name;
 	  }
       }
 
@@ -131,3 +134,11 @@ ttyname (fd)
 
   return name;
 }
+
+
+static void
+free_mem (void)
+{
+  free (getttyname_name);
+}
+text_set_element (__libc_subfreeres, free_mem);