Applying reformime subsequent on makemime
Denys Vlasenko
vda.linux at googlemail.com
Tue Jul 7 05:50:50 UTC 2009
On Monday 06 July 2009 21:42, Vladimir Dronnikov wrote:
> >>
> >> In fact this is the matter of the following condition:
> >>
> >> while ((line = xmalloc_fgets_str(stdin, "\r\n\r\n")) != NULL) { ...
> >>
> >> So we can do the following: upon the first occurance of \n to
> >> determine whether or not it is prepended by \r, and then use the rule
> >> to the whole content, right?
> >
> > I do not understand the above.
> >
> > Just read lines a-la fgets, strip trailing \n, *and if there is
> > trailing \r, strip it too.
>
> This can dramatically reduce the peformance. Right now reformime reads
> the "super-line" (containing all the headers in a MIME section) ending
> with a blank line in one go. Then performs fast scanning for critical
> headers (which some server toss and even duplicate!) within allocated
> memory.
>
> That is why duplication in \r\n\r\n and failure when a blank line is
> found at \n\n.
> So I'm hesitating. Help me choose among speed and usability, please :)
Having a dos2unix process will definitely be much slower.
xmalloc_fgets_str() is not magically fast right now. Take a look.
It's a fgetc + realloc loop IIRC.
How about implementing xmalloc_fgets_str(stdin, "\r\n\r\n")-like
operation as a static function in mailutils/mime.c, but which stops at
two empty lines, either \n ones or \r\n? You can also
add any other convenient ops there, like auto-stripping all \r
chars if you need.
Btw: in mailutils/mime.c:
xdup2(fd[0], STDIN_FILENO);
close(fd[0]); close(fd[1]);
there it's ok since STDIN_FILENO is known to be not closed,
and therefore fd[i] != STDIN_FILENO, but 100% correct way is:
close(fd[1]);
xmove_fd(fd[0], STDIN_FILENO);
because either of fd[i] can be == STDIN_FILENO!
The second code fragment is safe.
Hmm, you also forgot to check vfork failure :(
--
vda
More information about the busybox
mailing list