diff options
author | Rich Felker <dalias@aerifal.cx> | 2013-12-13 02:25:09 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2013-12-13 02:25:09 -0500 |
commit | 2b7cf6dbb9d56c5fac8f673e7c9d06c81d312af5 (patch) | |
tree | dc8df5dcdb658cc1b08f89f0e228dd9609eb0fa3 /src/misc | |
parent | a7dbcf5c8ca7edb7a46eb276031ad1df4131135b (diff) | |
download | musl-2b7cf6dbb9d56c5fac8f673e7c9d06c81d312af5.tar.gz musl-2b7cf6dbb9d56c5fac8f673e7c9d06c81d312af5.tar.xz musl-2b7cf6dbb9d56c5fac8f673e7c9d06c81d312af5.zip |
optimize get_current_dir_name to reduce stack bloat
our getcwd already (as an extension) supports allocation of a buffer when the buffer argument is a null pointer, so there's no need to duplicate the allocation logic in this wrapper function. duplicating it is actually harmful in that it doubles the stack usage from PATH_MAX to 2*PATH_MAX.
Diffstat (limited to 'src/misc')
-rw-r--r-- | src/misc/get_current_dir_name.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/src/misc/get_current_dir_name.c b/src/misc/get_current_dir_name.c index 8576df2c..782cddcd 100644 --- a/src/misc/get_current_dir_name.c +++ b/src/misc/get_current_dir_name.c @@ -7,11 +7,9 @@ char *get_current_dir_name(void) { struct stat a, b; - char buf[PATH_MAX]; char *res = getenv("PWD"); if (res && *res && !stat(res, &a) && !stat(".", &b) && (a.st_dev == b.st_dev) && (a.st_ino == b.st_ino)) return strdup(res); - if(!getcwd(buf, sizeof(buf))) return NULL; - return strdup(buf); + return getcwd(0, 0); } |