]>
Commit | Line | Data |
---|---|---|
3407bb49 LT |
1 | #include "cache.h" |
2 | ||
3 | static char *create_temp_file(unsigned char *sha1) | |
4 | { | |
5 | static char path[50]; | |
6 | void *buf; | |
7 | char type[100]; | |
8 | unsigned long size; | |
9 | int fd; | |
10 | ||
11 | buf = read_sha1_file(sha1, type, &size); | |
12 | if (!buf || strcmp(type, "blob")) | |
13 | die("unable to read blob object %s", sha1_to_hex(sha1)); | |
14 | ||
15 | strcpy(path, ".merge_file_XXXXXX"); | |
16 | fd = mkstemp(path); | |
17 | if (fd < 0) | |
18 | die("unable to create temp-file"); | |
19 | if (write(fd, buf, size) != size) | |
20 | die("unable to write temp-file"); | |
21 | close(fd); | |
22 | return path; | |
23 | } | |
24 | ||
25 | int main(int argc, char **argv) | |
26 | { | |
27 | unsigned char sha1[20]; | |
28 | ||
29 | if (argc != 2 || get_sha1_hex(argv[1], sha1)) | |
30 | usage("unpack-file.c <sha1>"); | |
31 | ||
32 | puts(create_temp_file(sha1)); | |
33 | return 0; | |
34 | } |