+ char *filename = sha1_file_name(sha1);
+ int fd;
+
+ fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ if (fd < 0) {
+ if (errno != EEXIST)
+ return -1;
+ if (collision_check(filename, buf, size))
+ return error("SHA1 collision detected!"
+ " This is bad, bad, BAD!\a\n");
+ return 0;
+ }
+ write(fd, buf, size);
+ close(fd);
+ return 0;