| 291 | } |
| 292 | |
| 293 | void strbuf_add_absolute_path(struct strbuf *sb, const char *path) |
| 294 | { |
| 295 | if (!*path) |
| 296 | die("The empty string is not a valid path"); |
| 297 | if (!is_absolute_path(path)) { |
| 298 | struct stat cwd_stat, pwd_stat; |
| 299 | size_t orig_len = sb->len; |
| 300 | char *cwd = xgetcwd(); |
| 301 | char *pwd = getenv("PWD"); |
| 302 | if (pwd && strcmp(pwd, cwd) && |
| 303 | !stat(cwd, &cwd_stat) && |
| 304 | (cwd_stat.st_dev || cwd_stat.st_ino) && |
| 305 | !stat(pwd, &pwd_stat) && |
| 306 | pwd_stat.st_dev == cwd_stat.st_dev && |
| 307 | pwd_stat.st_ino == cwd_stat.st_ino) |
| 308 | strbuf_addstr(sb, pwd); |
| 309 | else |
| 310 | strbuf_addstr(sb, cwd); |
| 311 | if (sb->len > orig_len && !is_dir_sep(sb->buf[sb->len - 1])) |
| 312 | strbuf_addch(sb, '/'); |
| 313 | free(cwd); |
| 314 | } |
| 315 | strbuf_addstr(sb, path); |
| 316 | } |
| 317 | |
| 318 | void strbuf_add_real_path(struct strbuf *sb, const char *path) |
| 319 | { |
no test coverage detected