]> diplodocus.org Git - nmh/blobdiff - sbr/seq_save.c
Disabled incompatible locale check because the output varies too
[nmh] / sbr / seq_save.c
index 83753afb5a1be551f068a06d9768b268b823ee4d..8ac30867308212f0bcea746a2bde1e71e38c0be2 100644 (file)
@@ -77,6 +77,8 @@ priv:
            context_del (attr);                 /* delete sequence from context */
 
            if (!fp) {
            context_del (attr);                 /* delete sequence from context */
 
            if (!fp) {
+               int failed_to_lock = 0;
+
                /*
                 * Attempt to open file for public sequences.
                 * If that fails (probably because folder is
                /*
                 * Attempt to open file for public sequences.
                 * If that fails (probably because folder is
@@ -89,11 +91,19 @@ priv:
                    free(mp->seqname);
                    mp->seqname = NULL;
                    rewind(fp);
                    free(mp->seqname);
                    mp->seqname = NULL;
                    rewind(fp);
-                   ftruncate(fileno(fp), 0);
-               } else if ((fp = lkfopendata (seqfile, "w")) == NULL
-                       && (unlink (seqfile) == -1 ||
-                           (fp = lkfopendata (seqfile, "w")) == NULL)) {
-                   admonish (attr, "unable to write");
+                   if (ftruncate(fileno(fp), 0) < 0) {
+                       advise ("sequence file", "ftruncate");
+                   }
+               } else if ((fp = lkfopendata (seqfile, "w", &failed_to_lock))
+                          == NULL
+                       && (m_unlink (seqfile) == -1 ||
+                           (fp = lkfopendata (seqfile, "w", &failed_to_lock))
+                           == NULL)) {
+                   if (failed_to_lock) {
+                       admonish (attr, "unable to lock");
+                   } else {
+                       admonish (attr, "unable to write");
+                   }
                    goto priv;
                }
 
                    goto priv;
                }
 
@@ -118,7 +128,7 @@ priv:
         * public sequences, then remove that file.
         */
        if (!is_readonly(mp))
         * public sequences, then remove that file.
         */
        if (!is_readonly(mp))
-           unlink (seqfile);
+           (void) m_unlink (seqfile);
     }
 
     /*
     }
 
     /*