adjust_dev_path() struggles with relative paths

Calling "./f3write a" returns the following error:

f3write: Can't change root directory to a at adjust_dev_path(): No such file or directory

This patch avoids this bug.
This commit is contained in:
Michel Machado 2022-11-11 19:03:27 -05:00
parent 283f386448
commit 204555d5df

View File

@ -28,14 +28,13 @@ void adjust_dev_path(const char **dev_path)
if (chdir(*dev_path)) {
err(errno, "Can't change working directory to %s at %s()", *dev_path, __func__);
}
*dev_path = ".";
if (!chroot(*dev_path)) {
assert(!chdir("/"));
} else if (errno != EPERM) {
err(errno, "Can't change root directory to %s at %s()", *dev_path, __func__);
}
*dev_path = ".";
}
const char *adjust_unit(double *ptr_bytes)