/[base]/head/lib/libc/stdio/fgets.c
ViewVC logotype

Diff of /head/lib/libc/stdio/fgets.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 305412 by emaste, Tue Apr 23 14:36:44 2013 UTC revision 305413 by ache, Mon Sep 5 06:46:04 2016 UTC
# Line 37  static char sccsid[] = "@(#)fgets.c    8.2 Line 37  static char sccsid[] = "@(#)fgets.c    8.2
37  __FBSDID("$FreeBSD$");  __FBSDID("$FreeBSD$");
38    
39  #include "namespace.h"  #include "namespace.h"
40    #include <errno.h>
41  #include <stdio.h>  #include <stdio.h>
42  #include <string.h>  #include <string.h>
43  #include "un-namespace.h"  #include "un-namespace.h"
# Line 55  fgets(char * __restrict buf, int n, FILE Line 56  fgets(char * __restrict buf, int n, FILE
56          char *s;          char *s;
57          unsigned char *p, *t;          unsigned char *p, *t;
58    
         if (n <= 0)             /* sanity check */  
                 return (NULL);  
   
59          FLOCKFILE(fp);          FLOCKFILE(fp);
60          ORIENT(fp, -1);          ORIENT(fp, -1);
61    
62            if (n <= 0) {           /* sanity check */
63                    fp->_flags |= __SERR;
64                    errno = EINVAL;
65                    FUNLOCKFILE(fp);
66                    return (NULL);
67            }
68    
69          s = buf;          s = buf;
70          n--;                    /* leave space for NUL */          n--;                    /* leave space for NUL */
71          while (n != 0) {          while (n != 0) {
# Line 69  fgets(char * __restrict buf, int n, FILE Line 75  fgets(char * __restrict buf, int n, FILE
75                  if ((len = fp->_r) <= 0) {                  if ((len = fp->_r) <= 0) {
76                          if (__srefill(fp)) {                          if (__srefill(fp)) {
77                                  /* EOF/error: stop with partial or no line */                                  /* EOF/error: stop with partial or no line */
78                                  if (s == buf) {                                  if (!__sfeof(fp) || s == buf) {
79                                          FUNLOCKFILE(fp);                                          FUNLOCKFILE(fp);
80                                          return (NULL);                                          return (NULL);
81                                  }                                  }

Legend:
Removed from v.305412  
changed lines
  Added in v.305413

  ViewVC Help
Powered by ViewVC 1.1.27