| To: | shwaresyst@xxxxxxx |
|---|---|
| Subject: | Re: fgets/strtok and LINE_MAX |
| From: | Don Cragun <dcragun@xxxxxxxxx> |
| Date: | Thu, 5 Nov 2009 15:26:08 -0800 |
| Cc: | austin-group-l@xxxxxxxxxxxxx |
| References: | <ee3ffd5cb61c11046aea665c63c5adbd@austingroupbugs.net> <8CC2B9DD22E07E8-AF4-14C01@webmail-m088.sysops.aol.com> <20091105102458.GA11253@squonk.masqnet> <8CC2C4B8D552A03-2DFC-9667@webmail-m095.sysops.aol.com> |
|
The subject line on this used to be: "Re: [1003.1(2008)/Issue 7 0000177]: mismatch between example description and code". I have changed it back to "Re: fgets/strtok and LINE_MAX" because Bug #177 is about a mismatch between the header of the example in strtok() (where it says "The following example uses strtok( ) to break a line into two character strings separated by any combination of <space>, <tab>, or <newline> characters." and the following code that includes: key = strtok(line, " \n"); data = strtok(NULL, " \n"); which does not look for <tab> characters. This discussion and the recent comments added to Bug #177 have nothing to do with strtok(). Please find further comments in-line below... Cheers, Don On Nov 5, 2009, at 8:24 AM, shwaresyst@aol.com wrote: ... ... ... 2. {LINE_MAX} is in the class of variables that aren't allowed to return -1 from sysconf(). In the absence of a larger value set at runtime it is required to return the static LINE_MAX from limits.h, which in turn is required to be >= _POSIX2_LINE_MAX, so the test on sysconf()'s return is superfluous.
This is not true. It is true that LINE_MAX has to be defined in
<limits.h> and may have a value that is less than the maximum line
length supported by the system when an application is running. But,
as stated on P2063, L65328-65331 in the RETURN VALUE section of the
description of sysconf() ("If the variable corresponding to name is
described in <limits.h> as a maximum or minimum value and the
variable has no limit, sysconf( ) shall return −1 without changing
the value of errno. Note that indefinite limits do not imply infinite
limits; see <limits.h>."), sysconf(_SC_LINE_MAX) may indeed return
-1 without setting errno to indicate that the standard utilities
support lines of arbitrary length.
I will work off-line to come up with a better example for fgets() before the conference call next Thursday. I don't know yet if I will try to make it a tutorial on how to process arbitrary length lines or if I will just add comments noting that lines can be arbitrarily long and state that the example has limitations by ignoring this possibility.
As noted above, this can set line_max to zero. line = malloc(line_max); /* get the buffer space */ And, malloc(0) is allowed to return a pointer to a newly allocated buffer that is zero bytes long... if (line=NULL) return ENOMEM; /* error check required by malloc() */ I assume you meant "line == NULL" instead of "line = NULL". But the idea of having an example always fail on a system that doesn't limit line lengths doesn't seem to be setting a good example of how to write portable code. /* set up other declared variables needed for the loop's processing */ |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: fgets/strtok and LINE_MAX, Don Cragun |
|---|---|
| Next by Date: | Re: fgets/strtok and LINE_MAX, Don Cragun |
| Previous by Thread: | Re: fgets/strtok and LINE_MAX, Don Cragun |
| Next by Thread: | Re: fgets/strtok and LINE_MAX, Don Cragun |
| Indexes: | [Date] [Thread] [All Lists] |