+ static bool registered;
+ struct stat s;
+ struct replace_file *rf;
+ int fd;
+
+ /* If FILE_NAME represents a special file, write to it directly
+ instead of trying to replace it. */
+ if (stat (file_name, &s) == 0 && !S_ISREG (s.st_mode))
+ {
+ /* Open file descriptor. */
+ fd = open (file_name, O_WRONLY);
+ if (fd < 0)
+ {
+ msg (ME, _("Opening %s for writing: %s."),
+ file_name, strerror (errno));
+ return NULL;
+ }
+
+ /* Open file as stream. */
+ *fp = fdopen (fd, mode);
+ if (*fp == NULL)
+ {
+ msg (ME, _("Opening stream for %s: %s."),
+ file_name, strerror (errno));
+ close (fd);
+ return NULL;
+ }
+
+ rf = xmalloc (sizeof *rf);
+ rf->file_name = NULL;
+ rf->tmp_name = xstrdup (file_name);
+ if (tmp_name != NULL)
+ *tmp_name = rf->tmp_name;
+ return rf;
+ }