diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-03-18 11:12:34 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-03-18 11:12:34 +0000 |
commit | e32376aaed01ed44981386e348ac35b58da23495 (patch) | |
tree | 3626e95d9c5c905b74085288d6e83ff7bd8dfa78 /libc/misc/ttyent/getttyent.c | |
parent | 38cd8e780fc6375117e8bc7db2eca17764779bba (diff) |
Reduce memory used by static buffers and allocate that memory dynamicly
instead. Based on an initial patch from Tobias Anderberg, but reworked. I
asked Tobias to look into doing something more like what is done in busybox,
but that proved to be a pain.
One possible concern is that these buffers will probably show up as
memory leaks i.e. with valgrind. Perhaps we should add in an atexit
call to free this memory right after we allocate it?
Diffstat (limited to 'libc/misc/ttyent/getttyent.c')
-rw-r--r-- | libc/misc/ttyent/getttyent.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libc/misc/ttyent/getttyent.c b/libc/misc/ttyent/getttyent.c index 18b9109af..0b2c9a3cc 100644 --- a/libc/misc/ttyent/getttyent.c +++ b/libc/misc/ttyent/getttyent.c @@ -99,11 +99,19 @@ struct ttyent * getttyent(void) { register int c; register char *p; - static char line[BUFSIZ]; + static char *line = NULL; if (!tf && !setttyent()) return (NULL); + + if (!line) { + line = malloc(BUFSIZ); + if (!line) + abort(); + } + flockfile (tf); + for (;;) { if (!fgets_unlocked(p = line, sizeof(line), tf)) { funlockfile (tf); |