[BACK]Return to fgetln.3 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / stdio

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libc/stdio/fgetln.3 between version 1.13 and 1.14

version 1.13, 2004/04/21 00:21:04 version 1.14, 2004/05/10 17:15:28
Line 115  or
Line 115  or
 .Sh SEE ALSO  .Sh SEE ALSO
 .Xr ferror 3 ,  .Xr ferror 3 ,
 .Xr fgets 3 ,  .Xr fgets 3 ,
 .Xr fgetstr 3 ,  
 .Xr fopen 3 ,  .Xr fopen 3 ,
 .Xr putc 3  .Xr putc 3
 .Sh HISTORY  .Sh HISTORY
Line 123  The
Line 122  The
 .Fn fgetln  .Fn fgetln
 function first appeared in  function first appeared in
 .Bx 4.4 .  .Bx 4.4 .
 .Sh NOTES  .Sh CAVEATS
 The  Since the returned buffer is not a C string (it is not null terminated), a
 .Fn fgetln  common practice is to replace the newline character with
 function is equivalent to  .Sq \e0 .
 .Fn fgetstr  However, if the last line in a file does not contain a newline,
 with a \en  the returned text won't contain a newline either.
 .Fa delim .  The following code demonstrates how to deal with this problem by allocating a
   temporary buffer:
   .Bd -literal
           char *buf, *lbuf;
           size_t len;
   
           lbuf = NULL;
           while ((buf = fgetln(fp, &len))) {
                   if (buf[len - 1] == '\en')
                           buf[len - 1] = '\e0';
                   else {
                           if ((lbuf = (char *)malloc(len + 1)) == NULL)
                                   err(1, NULL);
                           memcpy(lbuf, buf, len);
                           lbuf[len] = '\e0';
                           buf = lbuf;
                   }
                   printf("%s\en", buf);
   
                   if (lbuf != NULL) {
                           free(lbuf);
                           lbuf = NULL;
                   }
           }
   .Ed

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

CVSweb <webmaster@jp.NetBSD.org>