+
+ // Give the file a proper name, making it visible in the file system.
+ // TODO: It would be nice to be able to do this atomically, like with rename.
+ unlink(outfile.c_str());
+ char procpath[256];
+ snprintf(procpath, sizeof(procpath), "/proc/self/fd/%d", fileno(outfp));
+ if (linkat(AT_FDCWD, procpath, AT_FDCWD, outfile.c_str(), AT_SYMLINK_FOLLOW) == -1) {
+ perror("linkat");
+ exit(1);
+ }
+