repo.or.cz
/
musl.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
move msghdr and cmsghdr out of bits/socket.h
[musl.git]
/
src
/
unistd
/
getcwd.c
blob
f407ffe07ed6008fa4af1ce020b60df0a26a7534
1
#include <unistd.h>
2
#include <errno.h>
3
#include <limits.h>
4
#include <string.h>
5
#include
"syscall.h"
6
7
char
*
getcwd
(
char
*
buf
,
size_t
size
)
8
{
9
char
tmp
[
buf
?
1
:
PATH_MAX
];
10
if
(!
buf
) {
11
buf
=
tmp
;
12
size
=
sizeof
tmp
;
13
}
else if
(!
size
) {
14
errno
=
EINVAL
;
15
return
0
;
16
}
17
long
ret
=
syscall
(
SYS_getcwd
,
buf
,
size
);
18
if
(
ret
<
0
)
19
return
0
;
20
if
(
ret
==
0
||
buf
[
0
] !=
'/'
) {
21
errno
=
ENOENT
;
22
return
0
;
23
}
24
return
buf
==
tmp
?
strdup
(
buf
) :
buf
;
25
}