librocket: make demo on export
This commit is contained in:
parent
4a9056bba8
commit
a24682f3d4
49
lib/device.c
49
lib/device.c
@ -5,6 +5,7 @@
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static int find_track(struct sync_device *d, const char *name)
|
||||
{
|
||||
@ -266,13 +267,6 @@ 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;
|
||||
@ -287,18 +281,55 @@ static int save_track(const struct sync_track *t, const char *path)
|
||||
|
||||
fclose(fp);
|
||||
|
||||
if (!fchdir(cwd))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sync_save_tracks(const struct sync_device *d)
|
||||
{
|
||||
int i;
|
||||
|
||||
int cwd = open(".", O_RDONLY);
|
||||
if (cwd == -1) {
|
||||
dprintf(2, "can't open current directory\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (chdir("build/sync")) {
|
||||
dprintf(2, "can't enter build/sync directory\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < (int)d->num_tracks; ++i) {
|
||||
const struct sync_track *t = d->tracks[i];
|
||||
save_track(t, sync_track_path(d->base, t->name));
|
||||
}
|
||||
|
||||
if (fchdir(cwd)) {
|
||||
dprintf(2, "%s\n", strerror(errno));
|
||||
}
|
||||
|
||||
close(cwd);
|
||||
|
||||
printf("forking\n");
|
||||
pid_t pid = fork();
|
||||
if (pid == 0)
|
||||
{
|
||||
char path[1024];
|
||||
getcwd(path, 1024);
|
||||
dprintf(2, "making in %s...\n", path);
|
||||
execv("/usr/bin/make", (char *[]){ "make", "-f", "Makefile.demo", "run_kick", NULL });
|
||||
}
|
||||
else if (i > 0)
|
||||
{
|
||||
int status;
|
||||
printf("waiting...\n");
|
||||
waitpid(pid, &status, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("failing...\n");
|
||||
perror("fork failed");
|
||||
}
|
||||
}
|
||||
|
||||
static int get_track_data(struct sync_device *d, struct sync_track *t)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user