diff options
author | Waldemar Brodkorb <wbx@uclibc-ng.org> | 2016-01-03 19:20:40 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@uclibc-ng.org> | 2016-01-03 19:22:22 +0100 |
commit | a6975db114cce6484aa83f107d4496cd6045fd26 (patch) | |
tree | 15f21c6e8d8ce616c0fc6020161737df4cfe1ff6 /libc/misc/utmp/utent.c | |
parent | 391e3c8487386ed74b981cab45705cde963c6da3 (diff) |
libc: getpass,getutent: allocate buffer dynamically
Saves 0.6k bss with default buffer size(256).
text data bss dec hex filename
- 1172 8 408 1588 634 libc/misc/utmp/utent.os
- 429 0 256 685 2ad libc/unistd/getpass.os
+ 1208 8 28 1244 4dc libc/misc/utmp/utent.os
+ 471 0 4 475 1db libc/unistd/getpass.os
================================================================
+78 -632
Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com>
Diffstat (limited to 'libc/misc/utmp/utent.c')
-rw-r--r-- | libc/misc/utmp/utent.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 3671bb05c..16f4b115f 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -18,6 +18,7 @@ #include <fcntl.h> #include <paths.h> #include <errno.h> +#include <malloc.h> #include <string.h> #include "internal/utmp.h" #include <not-cancel.h> @@ -27,7 +28,7 @@ __UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER); /* Some global crap */ static int static_fd = -1; -static struct UT static_utmp; +static struct UT *static_utmp = NULL; static const char default_file[] = __DEFAULT_PATH_UTMP; static const char *current_file = default_file; @@ -72,9 +73,12 @@ static struct UT *__get_unlocked(void) return NULL; } - if (read_not_cancel(static_fd, &static_utmp, - sizeof(static_utmp)) == sizeof(static_utmp)) { - return &static_utmp; + if (static_utmp == NULL) + static_utmp = (struct UT *)__uc_malloc(sizeof(struct UT)); + + if (read_not_cancel(static_fd, static_utmp, + sizeof(struct UT)) == sizeof(struct UT)) { + return static_utmp; } return NULL; |