nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] Fwd: .gz support, DONE


From: Tilman WEIERS
Subject: Re: [Nano-devel] Fwd: .gz support, DONE
Date: Sat, 9 Jan 2016 12:29:31 +0100
User-agent: Mutt/1.5.22+18 (3306cb186f49) (2013-10-16)

Hi Mike and everyone:

If I used zlib instead of gzip, my approach would have been different 
from that of lv, vim, and less(pipe). I chose gzip out of consistency.

Regards,

Tilman



On Fri, Jan 08, 2016 at 03:39:23PM -0500, Mike Frysinger wrote:
> On 08 Jan 2016 21:22, Benno Schulenberg wrote:
> > Tilman Weiers wrote:
> > +/* Does the given filename end in ".gz"? */
> > +int isgz(char *fname)
> > +{
> > +    char *strend;
> > +    int len;
> > +
> > +    if (fname == NULL)
> > +   return -1;
> > +
> > +    len = strlen(fname);
> > +    if (len < 3)
> > +   return -1;
> > +
> > +    strend = malloc(4 * sizeof(char));
> > +    sprintf(strend, "%c%c%c", fname[len - 3], fname[len - 2], fname[len - 
> > 1]);
> > +
> > +    if (strcmp(strend, ".gz") == 0) {
> > +   free(strend);
> > +
> > +   /* The filename ends in ".gz", but do we have gzip? */
> > +   if (system("gzip --version > /dev/null 2>&1") != 0)
> > +       return -2;
> > +
> > +   /* Use gzip to handle the file. */
> > +   return 0;
> > +    }
> > +
> > +    free(strend);
> > +    return -1;
> > +}
> 
> this malloc logic is unnecessary and wasteful.  just do:
>   size_t len = strlen(fname);
>   if (strcmp(fname + len - 3, ".gz") == 0)
> 
> > +   /* The file is A-OK.  Open it, via gzip or directly. */
> > +   if (isgz(full_filename) == 0) {
> > +       char *open_cmd = (char *) nmalloc(sizeof(char) * (20 + 
> > strlen(full_filename)));
> > +       sprintf(open_cmd, "gzip -cdfq \'%s\'", full_filename);
> > +       *f = popen(open_cmd, "r");
> > +       free(open_cmd);
> > +   } else
> > +       *f = fdopen(fd, "rb");
> 
> imo we really should be using zlib directly instead of shelling (ugh) out
> to random tools
> -mike





reply via email to

[Prev in Thread] Current Thread [Next in Thread]