include aculib in cleanup
[unix-history] / usr / src / usr.bin / mail / fio.c
index 55b3889..9839076 100644 (file)
@@ -10,7 +10,7 @@
  * File I/O.
  */
 
  * File I/O.
  */
 
-static char *SccsId = "@(#)fio.c       2.9 %G%";
+static char *SccsId = "@(#)fio.c       2.15 %G%";
 
 /*
  * Set up the input pointers while copying the mail file into
 
 /*
  * Set up the input pointers while copying the mail file into
@@ -22,7 +22,8 @@ setptr(ibuf)
 {
        register int c;
        register char *cp, *cp2;
 {
        register int c;
        register char *cp, *cp2;
-       register int count, s, l;
+       register int count, l;
+       long s;
        off_t offset;
        char linebuf[LINESIZE];
        char wbuf[LINESIZE];
        off_t offset;
        char linebuf[LINESIZE];
        char wbuf[LINESIZE];
@@ -34,7 +35,7 @@ setptr(ibuf)
                exit(1);
        msgCount = 0;
        offset = 0;
                exit(1);
        msgCount = 0;
        offset = 0;
-       s = 0;
+       s = 0L;
        l = 0;
        maybe = 1;
        flag = MUSED|MNEW;
        l = 0;
        maybe = 1;
        flag = MUSED|MNEW;
@@ -84,7 +85,7 @@ setptr(ibuf)
                        this.m_offset = offsetof(offset);
                        this.m_size = s;
                        this.m_lines = l;
                        this.m_offset = offsetof(offset);
                        this.m_size = s;
                        this.m_lines = l;
-                       s = 0;
+                       s = 0L;
                        l = 0;
                        if (append(&this, mestmp)) {
                                perror(tempSet);
                        l = 0;
                        if (append(&this, mestmp)) {
                                perror(tempSet);
@@ -109,7 +110,7 @@ setptr(ibuf)
                        }
                }
                offset += count;
                        }
                }
                offset += count;
-               s += count;
+               s += (long) count;
                l++;
                maybe = 0;
                if (linebuf[0] == 0)
                l++;
                maybe = 0;
                if (linebuf[0] == 0)
@@ -248,7 +249,7 @@ makemessage(f)
                m->m_lines = (m+1)->m_lines;
                m->m_flag = (m+1)->m_flag;
        }
                m->m_lines = (m+1)->m_lines;
                m->m_flag = (m+1)->m_flag;
        }
-       message[msgCount].m_size = 0;
+       message[msgCount].m_size = 0L;
        message[msgCount].m_lines = 0;
 }
 
        message[msgCount].m_lines = 0;
 }
 
@@ -351,17 +352,18 @@ edstop()
        }
        printf("\"%s\" ", editfile);
        flush();
        }
        printf("\"%s\" ", editfile);
        flush();
-       if ((obuf = fopen(editfile, "w")) == NULL) {
+       if ((obuf = fopen(editfile, "r+")) == NULL) {
                perror(editfile);
                relsesigs();
                reset(0);
        }
                perror(editfile);
                relsesigs();
                reset(0);
        }
+       trunc(obuf);
        c = 0;
        for (mp = &message[0]; mp < &message[msgCount]; mp++) {
                if ((mp->m_flag & MDELETED) != 0)
                        continue;
                c++;
        c = 0;
        for (mp = &message[0]; mp < &message[msgCount]; mp++) {
                if ((mp->m_flag & MDELETED) != 0)
                        continue;
                c++;
-               if (send(mp, obuf) < 0) {
+               if (send(mp, obuf, 0) < 0) {
                        perror(editfile);
                        relsesigs();
                        reset(0);
                        perror(editfile);
                        relsesigs();
                        reset(0);
@@ -392,6 +394,8 @@ done:
        relsesigs();
 }
 
        relsesigs();
 }
 
+static int sigdepth = 0;               /* depth of holdsigs() */
+static int sigmask = 0;
 /*
  * Hold signals SIGHUP - SIGQUIT.
  */
 /*
  * Hold signals SIGHUP - SIGQUIT.
  */
@@ -399,8 +403,8 @@ holdsigs()
 {
        register int i;
 
 {
        register int i;
 
-       for (i = SIGHUP; i <= SIGQUIT; i++)
-               sighold(i);
+       if (sigdepth++ == 0)
+               sigmask = sigblock(mask(SIGHUP)|mask(SIGINT)|mask(SIGQUIT));
 }
 
 /*
 }
 
 /*
@@ -410,8 +414,8 @@ relsesigs()
 {
        register int i;
 
 {
        register int i;
 
-       for (i = SIGHUP; i <= SIGQUIT; i++)
-               sigrelse(i);
+       if (--sigdepth == 0)
+               sigsetmask(sigmask);
 }
 
 /*
 }
 
 /*