-
Notifications
You must be signed in to change notification settings - Fork 40
/
embed_target.c
52 lines (39 loc) · 1.11 KB
/
embed_target.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <assert.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <scheme.h>
#include "setup.h"
char bootfilename[] = "/tmp/chezschemebootXXXXXX";
char schemefilename[] = "/tmp/schemeprogramXXXXXX";
const char *cleanup_bootfile = 0;
const char *cleanup_schemefile = 0;
void cleanup(void) {
if (cleanup_bootfile) unlink(bootfilename);
if (cleanup_schemefile) unlink(schemefilename);
}
int maketempfile(char *template, const char *contents, size_t size) {
int fd;
fd = mkstemp(template);
assert(fd >= 0);
assert(write(fd, contents, size) == size);
assert(lseek(fd, 0, SEEK_SET) == 0);
return fd;
}
int main(int argc, const char **argv) {
int bootfd;
int schemefd;
int ret;
atexit(cleanup);
bootfd = maketempfile(bootfilename, &chezschemebootfile, chezschemebootfile_size);
cleanup_bootfile = bootfilename;
schemefd = maketempfile(schemefilename, &scheme_program, scheme_program_size);
cleanup_schemefile = schemefilename;
ret = run_program(argc, argv, bootfilename, schemefilename);
close(bootfd);
close(schemefd);
return ret;
}