]> diplodocus.org Git - nmh/commitdiff
Added m_getfld_track_filepos() for callers to indicate that they
authorDavid Levine <levinedl@acm.org>
Tue, 29 Jan 2013 03:20:22 +0000 (21:20 -0600)
committerDavid Levine <levinedl@acm.org>
Tue, 29 Jan 2013 03:20:22 +0000 (21:20 -0600)
may interleave fseek*/ftell* calls with m_getfld() calls.  This
eliminates the need for m_getfld() to call fseek() when called
by inc(1) and scan(1).

h/prototypes.h
sbr/m_getfld.c
uip/mhbuildsbr.c
uip/mhparse.c
uip/sendsbr.c

index 53e8b25d45675793902e66e9cdcd392422810c65..6db8e16900cb396e1f711ca8425c2d22ee6badda 100644 (file)
@@ -79,6 +79,7 @@ char *m_draft (char *, char *, int, int *);
 void m_eomsbr (m_getfld_state_t, int (*)(int));
 void m_getfld_state_reset (m_getfld_state_t *);
 void m_getfld_state_destroy (m_getfld_state_t *);
 void m_eomsbr (m_getfld_state_t, int (*)(int));
 void m_getfld_state_reset (m_getfld_state_t *);
 void m_getfld_state_destroy (m_getfld_state_t *);
+void m_getfld_track_filepos (m_getfld_state_t *, FILE *);
 int m_getfld (m_getfld_state_t *, unsigned char[NAMESZ], unsigned char *, int *, FILE *);
 int m_gmprot (void);
 char *m_maildir (char *);
 int m_getfld (m_getfld_state_t *, unsigned char[NAMESZ], unsigned char *, int *, FILE *);
 int m_gmprot (void);
 char *m_maildir (char *);
index 4a512269c6cc9a435bcc50b362a441d7c057b206..e7379dfe81bf83c147f419854df48d6a977f40cf 100644 (file)
@@ -266,6 +266,7 @@ struct m_getfld_state {
     int edelimlen;
     int (*eom_action)(int);
     int state;
     int edelimlen;
     int (*eom_action)(int);
     int state;
+    int track_filepos;
 };
 
 static
 };
 
 static
@@ -285,6 +286,7 @@ m_getfld_state_init (m_getfld_state_t *gstate, FILE *iob) {
     s->fdelimlen = s->edelimlen = 0;
     s->eom_action = NULL;
     s->state = FLD;
     s->fdelimlen = s->edelimlen = 0;
     s->eom_action = NULL;
     s->state = FLD;
+    s->track_filepos = 0;
 }
 
 /* scan() needs to force a state an initial state of FLD for each message. */
 }
 
 /* scan() needs to force a state an initial state of FLD for each message. */
@@ -295,6 +297,18 @@ m_getfld_state_reset (m_getfld_state_t *gstate) {
     }
 }
 
     }
 }
 
+/* If the caller interleaves ftell*()/fseek*() calls with m_getfld()
+   calls, m_getfld() must keep track of the file position.  The caller
+   must use this function to inform m_getfld(). */
+void
+m_getfld_track_filepos (m_getfld_state_t *gstate, FILE *iob) {
+    if (! *gstate) {
+       m_getfld_state_init (gstate, iob);
+    }
+
+    (*gstate)->track_filepos = 1;
+}
+
 void m_getfld_state_destroy (m_getfld_state_t *gstate) {
     m_getfld_state_t s = *gstate;
 
 void m_getfld_state_destroy (m_getfld_state_t *gstate) {
     m_getfld_state_t s = *gstate;
 
@@ -353,7 +367,7 @@ enter_getfld (m_getfld_state_t *gstate, FILE *iob) {
        readpos shift code being currently unused. */
     s->iob = iob;
 
        readpos shift code being currently unused. */
     s->iob = iob;
 
-    if (pos != 0  ||  s->last_internal_pos != 0) {
+    if (s->track_filepos  &&  (pos != 0  ||  s->last_internal_pos != 0)) {
        if (s->last_internal_pos == 0) {
            s->total_bytes_read = pos;
        } else {
        if (s->last_internal_pos == 0) {
            s->total_bytes_read = pos;
        } else {
@@ -397,13 +411,16 @@ enter_getfld (m_getfld_state_t *gstate, FILE *iob) {
 
 static void
 leave_getfld (m_getfld_state_t s) {
 
 static void
 leave_getfld (m_getfld_state_t s) {
-    /* Save the internal file position that we use for the input buffer. */
-    s->last_internal_pos = ftello (s->iob);
-
-    /* Set file stream position so that callers can use ftell(). */
     s->total_bytes_read += s->bytes_read;
     s->total_bytes_read += s->bytes_read;
-    fseeko (s->iob, s->total_bytes_read, SEEK_SET);
-    s->last_caller_pos = ftello (s->iob);
+
+    if (s->track_filepos) {
+       /* Save the internal file position that we use for the input buffer. */
+       s->last_internal_pos = ftello (s->iob);
+
+       /* Set file stream position so that callers can use ftell(). */
+       fseeko (s->iob, s->total_bytes_read, SEEK_SET);
+       s->last_caller_pos = ftello (s->iob);
+    }
 }
 
 static size_t
 }
 
 static size_t
index 7d187b395ed87bdad075c3ed4a0a21a14d03dbd0..a344a7c7536d5fbbf896998411c96854fb5531c1 100644 (file)
@@ -162,6 +162,7 @@ build_mime (char *infile, int directives)
      * draft into the linked list of header fields for
      * the new MIME message.
      */
      * draft into the linked list of header fields for
      * the new MIME message.
      */
+    m_getfld_track_filepos (&gstate, in);
     for (compnum = 1;;) {
        int bufsz = sizeof buf;
        switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
     for (compnum = 1;;) {
        int bufsz = sizeof buf;
        switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
index d4c6f10a037deb4f1b86e23a382674c2bc8a708f..0dcd1333d499e027070a754034b9b41ac21aef53 100644 (file)
@@ -276,6 +276,7 @@ get_content (FILE *in, char *file, int toplevel)
      * Parse the header fields for this
      * content into a linked list.
      */
      * Parse the header fields for this
      * content into a linked list.
      */
+    m_getfld_track_filepos (&gstate, in);
     for (compnum = 1;;) {
        int bufsz = sizeof buf;
        switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
     for (compnum = 1;;) {
        int bufsz = sizeof buf;
        switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
index 4c447414e45315c0b7ea2c8125af5547e29d6080..06358fd38e76e7e7c44b6d6534b98043027278ff 100644 (file)
@@ -603,6 +603,7 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay)
      * Scan through the message and examine the various header fields,
      * as well as locate the beginning of the message body.
      */
      * Scan through the message and examine the various header fields,
      * as well as locate the beginning of the message body.
      */
+    m_getfld_track_filepos (&gstate, in);
     for (compnum = 1;;) {
        int bufsz = sizeof buffer;
        switch (state = m_getfld (&gstate, name, buffer, &bufsz, in)) {
     for (compnum = 1;;) {
        int bufsz = sizeof buffer;
        switch (state = m_getfld (&gstate, name, buffer, &bufsz, in)) {