Logo
Explore Help
Sign In
fluencelabs/musl
1
0
Fork 0
You've already forked musl
mirror of https://github.com/fluencelabs/musl synced 2025-06-01 00:51:41 +00:00
Code Issues Projects Releases Wiki Activity
musl/src/unistd/getcwd.c

14 lines
293 B
C
Raw Normal View History

initial check-in, version 0.5.0
2011-02-12 00:22:29 -05:00
#include <unistd.h>
#include <errno.h>
support null buffer argument to getcwd, auto-allocating behavior this is a popular extension some programs depend on, and by using a temporary buffer and strdup rather than malloc prior to the syscall, i've avoided the dependency on free and thus minimized the bloat cost of supporting this feature.
2012-03-01 22:08:05 -05:00
#include <limits.h>
#include <string.h>
initial check-in, version 0.5.0
2011-02-12 00:22:29 -05:00
#include "syscall.h"
char *getcwd(char *buf, size_t size)
{
support null buffer argument to getcwd, auto-allocating behavior this is a popular extension some programs depend on, and by using a temporary buffer and strdup rather than malloc prior to the syscall, i've avoided the dependency on free and thus minimized the bloat cost of supporting this feature.
2012-03-01 22:08:05 -05:00
char tmp[PATH_MAX];
if (!buf) buf = tmp, size = PATH_MAX;
if (syscall(SYS_getcwd, buf, size) < 0) return 0;
return buf == tmp ? strdup(buf) : buf;
initial check-in, version 0.5.0
2011-02-12 00:22:29 -05:00
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.8 Page: 99ms Template: 4ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API