This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/5468] New: Error in getline(3) manpage


The getline(3) manpage states:

       ssize_t getline(char **lineptr, size_t *n, FILE *stream);
 [...]
       If  *lineptr  is  NULL,  then getline() will allocate a buffer for
storing the line, which should be
       freed by the user program.  (The value in *n is ignored.)

Based on this description (particularly the part that says the value *n is
ignored), you should be able to do something like:

    char *line = NULL;
    getline(&line, NULL, stream);

However this always fails, because the code for getline does the following:

  if (!lineptr || !n || !stream)
    {
      errno = EINVAL;
      return -1;
    }

  if (!*lineptr)
    {
      *n = MIN_CHUNK;
      *lineptr = malloc (*n);
      if (!*lineptr)
	{
	  errno = ENOMEM;
	  return -1;
	}
      *lineptr[0] = '\0';
    }

(thus the !n check always causes -1 to be returned).

Probably the manpage should just be modified to say something like "(The value
in *n is ignored on entry, but *n must still point to a valid int, and its value
is updated on exit to reflect the size of the newly malloc'd buffer.)"

This is pretty confusing behavior otherwise -- I had to read the source for
getline() to know what was going on.

Thanks!

-- 
           Summary: Error in getline(3) manpage
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: luke dot hutch at mit dot edu
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=5468

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]