* login/getutent.c: Include stdlib.h instead of stddef.h.
(buffer): Change into pointer to utmp, add libc_freeres_ptr.
(__getutent): Allocate buffer the first time it is run.
* login/getutid.c: Include stdlib.h instead of stddef.h.
(buffer): Change into pointer to utmp, add libc_freeres_ptr.
(__getutid): Allocate buffer the first time it is run.
* login/getutline.c: Include stdlib.h instead of stddef.h.
(buffer): Change into pointer to utmp, add libc_freeres_ptr.
(__getutline): Allocate buffer the first time it is run.
* malloc/mtrace.c (malloc_trace_buffer): Change into char *.
(mtrace): Allocate malloc_trace_buffer.
* resolv/nsap_addr.c (inet_nsap_ntoa): Decrease size of tmpbuf.
* resolv/ns_print.c (ns_sprintrrf): Decrease size of t.
* string/strerror.c: Include libintl.h and errno.h.
(buf): New variable.
(strerror): Only allocate buffer if actually needed (unknown error).
* time/tzfile.c (transitions): Add libc_freeres_ptr.
(freeres): Remove.
-/* Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <stddef.h> /* For NULL. */
+#include <stdlib.h>
#include <utmp.h>
/* Local buffer to store the result. */
-static struct utmp buffer;
+libc_freeres_ptr (static struct utmp *buffer);
struct utmp *
{
struct utmp *result;
- if (__getutent_r (&buffer, &result) < 0)
+ if (buffer == NULL)
+ {
+ buffer = (struct utmp *) malloc (sizeof (struct utmp));
+ if (buffer == NULL)
+ return NULL;
+ }
+
+ if (__getutent_r (buffer, &result) < 0)
return NULL;
return result;
-/* Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <stddef.h> /* For NULL. */
+#include <stdlib.h>
#include <utmp.h>
/* Local buffer to store the result. */
-static struct utmp buffer;
-
+libc_freeres_ptr (static struct utmp *buffer);
struct utmp *
__getutid (const struct utmp *id)
{
struct utmp *result;
- if (__getutid_r (id, &buffer, &result) < 0)
+ if (buffer == NULL)
+ {
+ buffer = (struct utmp *) malloc (sizeof (struct utmp));
+ if (buffer == NULL)
+ return NULL;
+ }
+ if (__getutid_r (id, buffer, &result) < 0)
return NULL;
return result;
-/* Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <stddef.h> /* For NULL. */
+#include <stdlib.h>
#include <utmp.h>
/* Local buffer to store the result. */
-static struct utmp buffer;
+libc_freeres_ptr (static struct utmp *buffer);
struct utmp *
{
struct utmp *result;
- if (__getutline_r (line, &buffer, &result) < 0)
+ if (buffer == NULL)
+ {
+ buffer = (struct utmp *) malloc (sizeof (struct utmp));
+ if (buffer == NULL)
+ return NULL;
+ }
+ if (__getutline_r (line, buffer, &result) < 0)
return NULL;
return result;
break;
case ns_t_nsap: {
- char t[255*3];
+ /* 2*255 for hex digits, 128 for '.' and '\0', 2 for
+ 0x if inet_nsap_ntoa starts using it. */
+ char t[255*2 + 128 + 2];
(void) inet_nsap_ntoa(rdlen, rdata, t);
T(addstr(t, strlen(t), &buf, &buflen));
inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) {
int nib;
int i;
- static char tmpbuf[255*3];
+ static char tmpbuf[255*2 + 128];
char *start;
if (ascii)
-/* Copyright (C) 1991, 93, 94, 95, 96, 98 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 93, 94, 95, 96, 98, 2002 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
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <libintl.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
/* Return a string describing the errno code in ERRNUM.
The storage is good only until the next call to strerror.
Writing to the storage causes undefined behavior. */
+libc_freeres_ptr (static char *buf);
+
char *
strerror (errnum)
int errnum;
{
- static char buf[1024];
- return __strerror_r (errnum, buf, sizeof buf);
+ char *ret = __strerror_r (errnum, NULL, 0);
+ int saved_errno;
+
+ if (__builtin_expect (ret != NULL, 1))
+ return ret;
+ saved_errno = errno;
+ if (buf == NULL)
+ buf = malloc (1024);
+ __set_errno (saved_errno);
+ if (buf == NULL)
+ return _("Unknown error");
+ return __strerror_r (errnum, buf, 1024);
}
static void compute_tzname_max (size_t) internal_function;
static size_t num_transitions;
-static time_t *transitions;
+libc_freeres_ptr (static time_t *transitions);
static unsigned char *type_idxs;
static size_t num_types;
static struct ttinfo *types;
}
while (++p < &zone_names[chars]);
}
-\f
-/* This function is only called when we are checking for memory leaks. */
-static void
-freeres (void)
-{
- if (transitions != NULL)
- free ((void *) transitions);
-}
-
-/* Make sure all allocated data is freed before exiting. */
-text_set_element (__libc_subfreeres, freeres);