+#ifndef MAIL_USE_SYSTEM_LOCK
+ if (! preserve_mail)
+ {
+ /* Delete the input file; if we can't, at least get rid of its
+ contents. */
+#ifdef MAIL_UNLINK_SPOOL
+ /* This is generally bad to do, because it destroys the permissions
+ that were set on the file. Better to just empty the file. */
+ if (unlink (inname) < 0 && errno != ENOENT)
+#endif /* MAIL_UNLINK_SPOOL */
+ creat (inname, 0600);
+ }
+#endif /* not MAIL_USE_SYSTEM_LOCK */
+
+#ifdef MAIL_USE_MAILLOCK
+ /* This has to occur in the child, i.e., in the process that
+ acquired the lock! */
+ if (spool_name)
+ mailunlock ();
+#endif
+ exit (0);
+ }
+
+ wait (&status);
+ if (!WIFEXITED (status))
+ exit (1);
+ else if (WRETCODE (status) != 0)
+ exit (WRETCODE (status));
+
+#if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
+#ifdef MAIL_USE_MAILLOCK
+ if (! spool_name)
+#endif /* MAIL_USE_MAILLOCK */
+ unlink (lockname);
+#endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */
+
+#endif /* ! DISABLE_DIRECT_ACCESS */
+
+ return 0;
+}
+
+#ifdef MAIL_USE_MAILLOCK
+/* This function uses stat to confirm that the mail directory is
+ identical to the directory of the input file, rather than just
+ string-comparing the two paths, because one or both of them might
+ be symbolic links pointing to some other directory. */
+static char *
+mail_spool_name (inname)
+ char *inname;
+{
+ struct stat stat1, stat2;
+ char *indir, *fname;
+ int status;
+
+ if (! (fname = rindex (inname, '/')))
+ return NULL;
+
+ fname++;
+
+ if (stat (MAILDIR, &stat1) < 0)
+ return NULL;
+
+ indir = (char *) xmalloc (fname - inname + 1);
+ strncpy (indir, inname, fname - inname);
+ indir[fname-inname] = '\0';
+
+
+ status = stat (indir, &stat2);
+
+ free (indir);
+
+ if (status < 0)
+ return NULL;
+
+ if (stat1.st_dev == stat2.st_dev
+ && stat1.st_ino == stat2.st_ino)
+ return fname;
+
+ return NULL;