]> diplodocus.org Git - nmh/blobdiff - uip/whatnowsbr.c
Removed "sleazy hack" of negative bufsz because commit
[nmh] / uip / whatnowsbr.c
index d54877e343cf1bfd08b28b938ae93af11a297453..a56446f8c6f482375ea802c9153a5b7f12bc94b4 100644 (file)
@@ -683,7 +683,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
            *ed = defaulteditor;
     }
 
-    if (altmsg && atfile) {
+    if (altmsg) {
        if (mp == NULL || *altmsg == '/' || cwd == NULL)
            strncpy (altpath, altmsg, sizeof(altpath));
        else
@@ -693,17 +693,19 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
        else
            snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
 
-       unlink (linkpath);
+       if (atfile) {
+           unlink (linkpath);
 #ifdef HAVE_LSTAT
-       if (link (altpath, linkpath) == NOTOK) {
-           symlink (altpath, linkpath);
-           slinked = 1;
-       } else {
-           slinked = 0;
-       }
+           if (link (altpath, linkpath) == NOTOK) {
+               symlink (altpath, linkpath);
+               slinked = 1;
+           } else {
+               slinked = 0;
+           }
 #else /* not HAVE_LSTAT */
-       link (altpath, linkpath);
+           link (altpath, linkpath);
 #endif /* not HAVE_LSTAT */
+       }
     }
 
     context_save ();   /* save the context file */
@@ -939,8 +941,9 @@ check_draft (char *msgnam)
 
     if ((fp = fopen (msgnam, "r")) == NULL)
        return 0;
-    for (state = FLD;;)
-       switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) {
+    for (state = FLD;;) {
+       int bufsz = sizeof buf;
+       switch (state = m_getfld (state, name, buf, &bufsz, fp)) {
            case FLD:
            case FLDPLUS:
            case FLDEOF:
@@ -953,8 +956,10 @@ check_draft (char *msgnam)
                    fclose (fp);
                    return 0;
                }
-               while (state == FLDPLUS)
-                   state = m_getfld (state, name, buf, sizeof(buf), fp);
+               while (state == FLDPLUS) {
+                   bufsz = sizeof buf;
+                   state = m_getfld (state, name, buf, &bufsz, fp);
+               }
                break;
 
            case BODY:
@@ -967,7 +972,8 @@ check_draft (char *msgnam)
                            return 1;
                        }
 
-                   state = m_getfld (state, name, buf, sizeof(buf), fp);
+                   bufsz = sizeof buf;
+                   state = m_getfld (state, name, buf, &bufsz, fp);
                } while (state == BODY);
                /* and fall... */
 
@@ -975,6 +981,7 @@ check_draft (char *msgnam)
                fclose (fp);
                return 0;
        }
+    }
 }