if (write(fd, contents, strlen(contents)) != strlen(contents))
err(1, "Failure writing to temporary file %s", tmpfile);
close(fd);
if (write(fd, contents, strlen(contents)) != strlen(contents))
err(1, "Failure writing to temporary file %s", tmpfile);
close(fd);