| 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" |
| 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) { |
| 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 |
} |
} |