| 77 | } |
| 78 | |
| 79 | struct path_pushd *path_pushd(const tal_t *ctx, const char *dir) |
| 80 | { |
| 81 | struct path_pushd *old = tal(ctx, struct path_pushd); |
| 82 | |
| 83 | if (!old) |
| 84 | return NULL; |
| 85 | |
| 86 | if (unlikely(!dir) && taken(dir)) |
| 87 | return tal_free(old); |
| 88 | |
| 89 | if (!tal_add_destructor(old, pushd_destroy)) |
| 90 | old = tal_free(old); |
| 91 | else { |
| 92 | old->fd = open(".", O_RDONLY); |
| 93 | if (old->fd < 0) |
| 94 | old = tal_free(old); |
| 95 | else if (chdir(dir) != 0) |
| 96 | old = tal_free(old); |
| 97 | } |
| 98 | |
| 99 | if (taken(dir)) |
| 100 | tal_free(dir); |
| 101 | return old; |
| 102 | } |
| 103 | |
| 104 | bool path_popd(struct path_pushd *olddir) |
| 105 | { |
no test coverage detected