Rev 4874 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4874 | Rev 4921 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | INDEX |
24 | INDEX |
25 | _fgets_r |
25 | _fgets_r |
Line 26... | Line 26... | ||
26 | 26 | ||
27 | ANSI_SYNOPSIS |
27 | ANSI_SYNOPSIS |
28 | #include |
28 | #include |
Line 29... | Line 29... | ||
29 | char *fgets(char *<[buf]>, int <[n]>, FILE *<[fp]>); |
29 | char *fgets(char *restrict <[buf]>, int <[n]>, FILE *restrict <[fp]>); |
30 | 30 | ||
Line 31... | Line 31... | ||
31 | #include |
31 | #include |
32 | char *_fgets_r(struct _reent *<[ptr]>, char *<[buf]>, int <[n]>, FILE *<[fp]>); |
32 | char *_fgets_r(struct _reent *<[ptr]>, char *restrict <[buf]>, int <[n]>, FILE *restrict <[fp]>); |
33 | 33 | ||
34 | TRAD_SYNOPSIS |
34 | TRAD_SYNOPSIS |
Line 81... | Line 81... | ||
81 | */ |
81 | */ |
Line 82... | Line 82... | ||
82 | 82 | ||
83 | char * |
83 | char * |
84 | _DEFUN(_fgets_r, (ptr, buf, n, fp), |
84 | _DEFUN(_fgets_r, (ptr, buf, n, fp), |
85 | struct _reent * ptr _AND |
85 | struct _reent * ptr _AND |
86 | char *buf _AND |
86 | char *__restrict buf _AND |
87 | int n _AND |
87 | int n _AND |
88 | FILE * fp) |
88 | FILE *__restrict fp) |
89 | { |
89 | { |
90 | size_t len; |
90 | size_t len; |
91 | char *s; |
91 | char *s; |
Line 96... | Line 96... | ||
96 | 96 | ||
Line 97... | Line 97... | ||
97 | s = buf; |
97 | s = buf; |
Line 98... | Line 98... | ||
98 | 98 | ||
99 | CHECK_INIT(ptr, fp); |
99 | CHECK_INIT(ptr, fp); |
100 | 100 | ||
101 | _flockfile (fp); |
101 | _newlib_flockfile_start (fp); |
102 | #ifdef __SCLE |
102 | #ifdef __SCLE |
103 | if (fp->_flags & __SCLE) |
103 | if (fp->_flags & __SCLE) |
104 | { |
104 | { |
105 | int c; |
105 | int c = 0; |
106 | /* Sorry, have to do it the slow way */ |
106 | /* Sorry, have to do it the slow way */ |
107 | while (--n > 0 && (c = __sgetc_r (ptr, fp)) != EOF) |
107 | while (--n > 0 && (c = __sgetc_r (ptr, fp)) != EOF) |
108 | { |
108 | { |
109 | *s++ = c; |
109 | *s++ = c; |
110 | if (c == '\n') |
110 | if (c == '\n') |
111 | break; |
111 | break; |
112 | } |
112 | } |
113 | if (c == EOF && s == buf) |
113 | if (c == EOF && s == buf) |
114 | { |
114 | { |
115 | _funlockfile (fp); |
115 | _newlib_flockfile_exit (fp); |
116 | return NULL; |
116 | return NULL; |
117 | } |
117 | } |
118 | *s = 0; |
118 | *s = 0; |
119 | _funlockfile (fp); |
119 | _newlib_flockfile_exit (fp); |
Line 120... | Line 120... | ||
120 | return buf; |
120 | return buf; |
Line 132... | Line 132... | ||
132 | if (__srefill_r (ptr, fp)) |
132 | if (__srefill_r (ptr, fp)) |
133 | { |
133 | { |
134 | /* EOF: stop with partial or no line */ |
134 | /* EOF: stop with partial or no line */ |
135 | if (s == buf) |
135 | if (s == buf) |
136 | { |
136 | { |
137 | _funlockfile (fp); |
137 | _newlib_flockfile_exit (fp); |
138 | return 0; |
138 | return 0; |
139 | } |
139 | } |
140 | break; |
140 | break; |
141 | } |
141 | } |
142 | len = fp->_r; |
142 | len = fp->_r; |
Line 157... | Line 157... | ||
157 | len = ++t - p; |
157 | len = ++t - p; |
158 | fp->_r -= len; |
158 | fp->_r -= len; |
159 | fp->_p = t; |
159 | fp->_p = t; |
160 | _CAST_VOID memcpy ((_PTR) s, (_PTR) p, len); |
160 | _CAST_VOID memcpy ((_PTR) s, (_PTR) p, len); |
161 | s[len] = 0; |
161 | s[len] = 0; |
162 | _funlockfile (fp); |
162 | _newlib_flockfile_exit (fp); |
163 | return (buf); |
163 | return (buf); |
164 | } |
164 | } |
165 | fp->_r -= len; |
165 | fp->_r -= len; |
166 | fp->_p += len; |
166 | fp->_p += len; |
167 | _CAST_VOID memcpy ((_PTR) s, (_PTR) p, len); |
167 | _CAST_VOID memcpy ((_PTR) s, (_PTR) p, len); |
168 | s += len; |
168 | s += len; |
169 | } |
169 | } |
170 | while ((n -= len) != 0); |
170 | while ((n -= len) != 0); |
171 | *s = 0; |
171 | *s = 0; |
172 | _funlockfile (fp); |
172 | _newlib_flockfile_end (fp); |
173 | return buf; |
173 | return buf; |
174 | } |
174 | } |
Line 175... | Line 175... | ||
175 | 175 | ||
Line 176... | Line 176... | ||
176 | #ifndef _REENT_ONLY |
176 | #ifndef _REENT_ONLY |
177 | 177 | ||
178 | char * |
178 | char * |
179 | _DEFUN(fgets, (buf, n, fp), |
179 | _DEFUN(fgets, (buf, n, fp), |
180 | char *buf _AND |
180 | char *__restrict buf _AND |
181 | int n _AND |
181 | int n _AND |
182 | FILE * fp) |
182 | FILE *__restrict fp) |
183 | { |
183 | { |
Line 184... | Line 184... | ||
184 | return _fgets_r (_REENT, buf, n, fp); |
184 | return _fgets_r (_REENT, buf, n, fp); |