Re: [dev] [sbase] [patch v3] Add strings(1)

From: sin <sin_AT_2f30.org>
Date: Thu, 15 Aug 2013 14:22:29 +0300

On Thu, Aug 15, 2013 at 01:06:25PM +0200, Roberto E. Vargas Caballero wrote:
> Only other sugestion, this loop could be done better with a do while:
>
> dostrings(FILE *fp, const char *fname)
> {
> unsigned char buf[BUFSIZ];
> int c, i = 0;
> off_t offset = 0;
> do {
> offset++;
> if (isprint(c = getc(fp)))
> buf[i++] = c
>
> if ((!isprint(c) && i >= 6) || i == sizeof(buf) - 1) {
> buf[i] = '\0';
> printf("%8ld: %s\n", (long)offset - i - 1, buf);
> i = 0;
> }
> } while (c != EOF);
>
> if (ferror(fp))
> eprintf("%s read error:", fname);
> }
> }

Much better, will incorporate this.

Thanks,
sin
Received on Thu Aug 15 2013 - 13:22:29 CEST

This archive was generated by hypermail 2.3.0 : Thu Aug 15 2013 - 13:24:12 CEST