+/* Creates a new file named FN with the given PERMISSIONS bits,
+ and returns a stream for it or a null pointer on failure.
+ MODE should be "w" or "wb". */
+FILE *
+create_stream (const char *fn, const char *mode, mode_t permissions)
+{
+ int fd;
+ FILE *stream;
+
+ fd = open (fn, O_WRONLY | O_CREAT | O_TRUNC, permissions);
+ if (fd < 0)
+ return NULL;
+
+ stream = fdopen (fd, mode);
+ if (stream == NULL)
+ {
+ int save_errno = errno;
+ close (fd);
+ errno = save_errno;
+ }
+
+ return stream;
+}
+
+/* A file's identity:
+
+ - For a file that exists, this is its device and inode.
+
+ - For a file that does not exist, but which has a directory
+ name that exists, this is the device and inode of the
+ directory, plus the file's base name.
+
+ - For a file that does not exist and has a nonexistent
+ directory, this is the file name.
+
+ Windows doesn't have inode numbers, so we just use the name
+ there. */