From b8fd550293431d4df42b281fc868ef0ab80e822b Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 15 Aug 2000 06:12:25 +0000 Subject: 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. --- sysdeps/generic/strtok.c | 4 +-- sysdeps/posix/ttyname.c | 39 +++++++++++++++++++----------- sysdeps/unix/sysv/linux/ttyname.c | 51 +++++++++++++++++++++++++-------------- 3 files changed, 60 insertions(+), 34 deletions(-) (limited to 'sysdeps') diff --git a/sysdeps/generic/strtok.c b/sysdeps/generic/strtok.c index 6aeeb5a646..b6f952385c 100644 --- a/sysdeps/generic/strtok.c +++ b/sysdeps/generic/strtok.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1996, 1997, 1999 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1996, 1997, 1999, 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 @@ -19,7 +19,7 @@ #include -static char *olds = NULL; +static char *olds; #undef strtok 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 #include -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); diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c index 33587a34fc..0973925cca 100644 --- a/sysdeps/unix/sysv/linux/ttyname.c +++ b/sysdeps/unix/sysv/linux/ttyname.c @@ -30,15 +30,17 @@ char *__ttyname; -static char * getttyname (const char *dev, dev_t mydev, - ino_t myino, int save, int *dostat) +static char *getttyname (const char *dev, dev_t mydev, + ino_t myino, int save, int *dostat) internal_function; + +static char *getttyname_name; + static char * internal_function getttyname (const char *dev, dev_t mydev, ino_t myino, int save, int *dostat) { - static char *name; static size_t namelen; struct stat st; DIR *dirstream; @@ -61,20 +63,20 @@ getttyname (const char *dev, dev_t mydev, ino_t myino, int save, int *dostat) size_t dlen = _D_ALLOC_NAMLEN (d); if (devlen + dlen > namelen) { - free (name); + free (getttyname_name); namelen = 2 * (devlen + 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, devlen - 1)) = '/'; + *((char *) __mempcpy (getttyname_name, dev, devlen - 1)) = '/'; } - memcpy (&name[devlen], d->d_name, dlen); - if (__xstat (_STAT_VER, name, &st) == 0 + memcpy (&getttyname_name[devlen], d->d_name, dlen); + if (__xstat (_STAT_VER, getttyname_name, &st) == 0 #ifdef _STATBUF_ST_RDEV && S_ISCHR (st.st_mode) && st.st_rdev == mydev #else @@ -83,9 +85,9 @@ getttyname (const char *dev, dev_t mydev, ino_t myino, int save, int *dostat) ) { (void) __closedir (dirstream); - __ttyname = name; + __ttyname = getttyname_name; __set_errno (save); - return name; + return getttyname_name; } } @@ -94,12 +96,16 @@ getttyname (const char *dev, dev_t mydev, ino_t myino, int save, int *dostat) return NULL; } + +/* Static buffer in `ttyname'. */ +static char *ttyname_buf; + + /* Return the pathname of the terminal FD is open on, or NULL on errors. The returned storage is good only until the next call to this function. */ char * ttyname (int fd) { - static char *buf; static size_t buflen; char procname[30]; struct stat st, st1; @@ -117,24 +123,24 @@ ttyname (int fd) if (buflen == 0) { buflen = 4095; - buf = (char *) malloc (buflen + 1); - if (buf == NULL) + ttyname_buf = (char *) malloc (buflen + 1); + if (ttyname_buf == NULL) { buflen = 0; return NULL; } } - len = __readlink (procname, buf, buflen); + len = __readlink (procname, ttyname_buf, buflen); if (len != -1 /* This is for Linux 2.0. */ - && buf[0] != '[') + && ttyname_buf[0] != '[') { if (len >= buflen) return NULL; /* readlink need not terminate the string. */ - buf[len] = '\0'; - return buf; + ttyname_buf[len] = '\0'; + return ttyname_buf; } if (__fxstat (_STAT_VER, fd, &st) < 0) @@ -175,3 +181,12 @@ ttyname (int fd) return name; } + + +static void +free_mem (void) +{ + free (ttyname_buf); + free (getttyname_name); +} +text_set_element (__libc_subfreeres, free_mem); -- cgit 1.4.1