3 static const char *get_pwd_cwd(void)
5 static char cwd
[PATH_MAX
+ 1];
7 struct stat cwd_stat
, pwd_stat
;
8 if (getcwd(cwd
, PATH_MAX
) == NULL
)
11 if (pwd
&& strcmp(pwd
, cwd
)) {
13 if (!stat(pwd
, &pwd_stat
) &&
14 pwd_stat
.st_dev
== cwd_stat
.st_dev
&&
15 pwd_stat
.st_ino
== cwd_stat
.st_ino
) {
16 strlcpy(cwd
, pwd
, PATH_MAX
);
22 const char *make_nonrelative_path(const char *path
)
24 static char buf
[PATH_MAX
+ 1];
26 if (is_absolute_path(path
)) {
27 if (strlcpy(buf
, path
, PATH_MAX
) >= PATH_MAX
)
28 die("Too long path: %.*s", 60, path
);
30 const char *cwd
= get_pwd_cwd();
32 die("Cannot determine the current working directory");
33 if (snprintf(buf
, PATH_MAX
, "%s/%s", cwd
, path
) >= PATH_MAX
)
34 die("Too long path: %.*s", 60, path
);