diff --git a/lib/device.c b/lib/device.c index 9d74d08..be22cea 100644 --- a/lib/device.c +++ b/lib/device.c @@ -1,6 +1,7 @@ #include "device.h" #include "track.h" #include +#include #include #include #include @@ -264,6 +265,14 @@ static int get_track_data(struct sync_device *d, struct sync_track *t) static int save_track(const struct sync_track *t, const char *path) { int i; + + int cwd = open(".", O_RDONLY); + if (!cwd) + return -1; + + if (!chdir("build/sync")) + return -1; + FILE *fp = fopen(path, "wb"); if (!fp) return -1; @@ -277,6 +286,9 @@ static int save_track(const struct sync_track *t, const char *path) } fclose(fp); + + if (!fchdir(cwd)) + return -1; return 0; }