• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdlib.h>
2 #include <limits.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <errno.h>
6 #include <unistd.h>
7 #include <string.h>
8 #include "syscall.h"
9 
realpath(const char * restrict filename,char * restrict resolved)10 char *realpath(const char *restrict filename, char *restrict resolved)
11 {
12 	int ret;
13 	char tmp[PATH_MAX];
14 
15 	if (!filename) {
16 		errno = EINVAL;
17 		return 0;
18 	}
19 
20 	ret = syscall(SYS_realpath, filename, tmp);
21 	if (ret < 0) return 0;
22 
23 	return resolved ? strcpy(resolved, tmp) : strdup(tmp);
24 }
25