Re: Use off_t for lineno in csplit
Mark Kettenis wrote: > > Date: Sat, 12 Dec 2015 16:26:30 -0500 > > From: Michael McConville> > > > Mark Kettenis wrote: > > > It really is confusing to use off_t for something that's not a byte > > > offset. If integer overflow really is an issue you care about, use > > > "long long". > > > > ok for the below diff to update my grep change? > > Fine with me. Thanks. And how about this for csplit? Index: csplit.c === RCS file: /cvs/src/usr.bin/csplit/csplit.c,v retrieving revision 1.8 diff -u -p -r1.8 csplit.c --- csplit.c11 Oct 2015 17:43:03 - 1.8 +++ csplit.c14 Dec 2015 20:03:43 - @@ -80,7 +80,7 @@ intkflag; /* Keep output if error oc /* * Other miscellaneous globals (XXX too many) */ -longlineno;/* Current line number in input file */ +long long lineno; /* Current line number in input file */ longreps; /* Number of repetitions for this pattern */ longnfiles;/* Number of files output so far */ longmaxfiles; /* Maximum number of files we can create */ @@ -439,7 +439,7 @@ do_rexp(const char *expr) void do_lineno(const char *expr) { - long lastline, tgtline; + long long lastline, tgtline; char *ep, *p; FILE *ofp; @@ -455,7 +455,7 @@ do_lineno(const char *expr) ofp = newfile(); while (lineno + 1 != lastline) { if ((p = get_line()) == NULL) - errx(1, "%ld: out of range", lastline); + errx(1, "%lld: out of range", lastline); if (fputs(p, ofp) != 0) break; }
Re: Use off_t for lineno in csplit
Mark Kettenis wrote: > It really is confusing to use off_t for something that's not a byte > offset. If integer overflow really is an issue you care about, use > "long long". ok for the below diff to update my grep change? > Note that on many non-BSD systems off_t is still a 32-bit integer, at > least by default. So using off_t doesn't help portability. Search > the interwebs for "Large File Summit" for the full horror story! Thanks for the reference. :-) Interesting read. Index: grep.h === RCS file: /cvs/src/usr.bin/grep/grep.h,v retrieving revision 1.23 diff -u -p -r1.23 grep.h --- grep.h 7 Dec 2015 18:50:06 - 1.23 +++ grep.h 11 Dec 2015 02:18:02 - @@ -43,7 +43,7 @@ typedef struct { size_t len; - off_tline_no; + long longline_no; off_toff; char*file; char*dat; Index: util.c === RCS file: /cvs/src/usr.bin/grep/util.c,v retrieving revision 1.51 diff -u -p -r1.51 util.c --- util.c 7 Dec 2015 18:50:06 - 1.51 +++ util.c 11 Dec 2015 02:18:02 - @@ -623,7 +623,7 @@ printline(str_t *line, int sep, regmatch if (nflag) { if (n) putchar(sep); - printf("%lld", (long long)line->line_no); + printf("%lld", line->line_no); ++n; } if (bflag) {
Re: Use off_t for lineno in csplit
> Date: Sat, 12 Dec 2015 16:26:30 -0500 > From: Michael McConville> > Mark Kettenis wrote: > > It really is confusing to use off_t for something that's not a byte > > offset. If integer overflow really is an issue you care about, use > > "long long". > > ok for the below diff to update my grep change? Fine with me. > Index: grep.h > === > RCS file: /cvs/src/usr.bin/grep/grep.h,v > retrieving revision 1.23 > diff -u -p -r1.23 grep.h > --- grep.h7 Dec 2015 18:50:06 - 1.23 > +++ grep.h11 Dec 2015 02:18:02 - > @@ -43,7 +43,7 @@ > > typedef struct { > size_t len; > - off_tline_no; > + long longline_no; > off_toff; > char*file; > char*dat; > Index: util.c > === > RCS file: /cvs/src/usr.bin/grep/util.c,v > retrieving revision 1.51 > diff -u -p -r1.51 util.c > --- util.c7 Dec 2015 18:50:06 - 1.51 > +++ util.c11 Dec 2015 02:18:02 - > @@ -623,7 +623,7 @@ printline(str_t *line, int sep, regmatch > if (nflag) { > if (n) > putchar(sep); > - printf("%lld", (long long)line->line_no); > + printf("%lld", line->line_no); > ++n; > } > if (bflag) { >
Re: Use off_t for lineno in csplit
> Date: Tue, 8 Dec 2015 13:00:49 -0500 > From: Michael McConville> > I thought I'd look for other examples after the grep fix. > > ok? It really is confusing to use off_t for something that's not a byte offset. If integer overflow really is an issue you care about, use "long long". Note that on many non-BSD systems off_t is still a 32-bit integer, at least by default. So using off_t doesn't help portability. Search the interwebs for "Large File Summit" for the full horror story! > Index: csplit.c > === > RCS file: /cvs/src/usr.bin/csplit/csplit.c,v > retrieving revision 1.8 > diff -u -p -r1.8 csplit.c > --- csplit.c 11 Oct 2015 17:43:03 - 1.8 > +++ csplit.c 8 Dec 2015 17:57:50 - > @@ -80,7 +80,7 @@ int kflag; /* Keep output if error oc > /* > * Other miscellaneous globals (XXX too many) > */ > -long lineno;/* Current line number in input file */ > +off_t lineno;/* Current line number in input file */ > long reps; /* Number of repetitions for this pattern */ > long nfiles;/* Number of files output so far */ > long maxfiles; /* Maximum number of files we can create */ > @@ -439,7 +439,7 @@ do_rexp(const char *expr) > void > do_lineno(const char *expr) > { > - long lastline, tgtline; > + off_t lastline, tgtline; > char *ep, *p; > FILE *ofp; > > @@ -455,7 +455,8 @@ do_lineno(const char *expr) > ofp = newfile(); > while (lineno + 1 != lastline) { > if ((p = get_line()) == NULL) > - errx(1, "%ld: out of range", lastline); > + errx(1, "%lld: out of range", > + (long long)lastline); > if (fputs(p, ofp) != 0) > break; > } > >
Use off_t for lineno in csplit
I thought I'd look for other examples after the grep fix. ok? Index: csplit.c === RCS file: /cvs/src/usr.bin/csplit/csplit.c,v retrieving revision 1.8 diff -u -p -r1.8 csplit.c --- csplit.c11 Oct 2015 17:43:03 - 1.8 +++ csplit.c8 Dec 2015 17:57:50 - @@ -80,7 +80,7 @@ intkflag; /* Keep output if error oc /* * Other miscellaneous globals (XXX too many) */ -longlineno;/* Current line number in input file */ +off_t lineno;/* Current line number in input file */ longreps; /* Number of repetitions for this pattern */ longnfiles;/* Number of files output so far */ longmaxfiles; /* Maximum number of files we can create */ @@ -439,7 +439,7 @@ do_rexp(const char *expr) void do_lineno(const char *expr) { - long lastline, tgtline; + off_t lastline, tgtline; char *ep, *p; FILE *ofp; @@ -455,7 +455,8 @@ do_lineno(const char *expr) ofp = newfile(); while (lineno + 1 != lastline) { if ((p = get_line()) == NULL) - errx(1, "%ld: out of range", lastline); + errx(1, "%lld: out of range", + (long long)lastline); if (fputs(p, ofp) != 0) break; }