diff options
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/read.c | 25 |
1 files changed, 0 insertions, 25 deletions
diff --git a/libbb/read.c b/libbb/read.c index 7af895207..18f62838e 100644 --- a/libbb/read.c +++ b/libbb/read.c | |||
| @@ -127,31 +127,6 @@ unsigned char FAST_FUNC xread_char(int fd) | |||
| 127 | return tmp; | 127 | return tmp; |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | /* Read one line a-la fgets. Works only on seekable streams */ | ||
| 131 | char* FAST_FUNC reads(int fd, char *buffer, size_t size) | ||
| 132 | { | ||
| 133 | char *p; | ||
| 134 | |||
| 135 | if (size < 2) | ||
| 136 | return NULL; | ||
| 137 | size = full_read(fd, buffer, size-1); | ||
| 138 | if ((ssize_t)size <= 0) | ||
| 139 | return NULL; | ||
| 140 | |||
| 141 | buffer[size] = '\0'; | ||
| 142 | p = strchr(buffer, '\n'); | ||
| 143 | if (p) { | ||
| 144 | off_t offset; | ||
| 145 | *p++ = '\0'; | ||
| 146 | /* avoid incorrect (unsigned) widening */ | ||
| 147 | offset = (off_t)(p - buffer) - (off_t)size; | ||
| 148 | /* set fd position right after '\n' */ | ||
| 149 | if (offset && lseek(fd, offset, SEEK_CUR) == (off_t)-1) | ||
| 150 | return NULL; | ||
| 151 | } | ||
| 152 | return buffer; | ||
| 153 | } | ||
| 154 | |||
| 155 | // Reads one line a-la fgets (but doesn't save terminating '\n'). | 130 | // Reads one line a-la fgets (but doesn't save terminating '\n'). |
| 156 | // Reads byte-by-byte. Useful when it is important to not read ahead. | 131 | // Reads byte-by-byte. Useful when it is important to not read ahead. |
| 157 | // Bytes are appended to pfx (which must be malloced, or NULL). | 132 | // Bytes are appended to pfx (which must be malloced, or NULL). |
