- Timestamp:
- Sep 6, 2012 3:16:25 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/input.c
r2424 r2629 172 172 173 173 static int 174 preadfd (shinstance *psh)174 preadfd_inner(shinstance *psh, char *buf, int bufsize) 175 175 { 176 176 int nr; 177 char *buf = psh->parsefile->buf;178 psh->parsenextc = buf;179 180 177 retry: 181 178 #ifndef SMALL … … 190 187 else { 191 188 nr = el_len; 192 if (nr > BUFSIZ - 8)193 nr = BUFSIZ - 8;189 if (nr > bufsize) 190 nr = bufsize; 194 191 memcpy(buf, rl_cp, nr); 195 192 if (nr != el_len) { … … 202 199 } else 203 200 #endif 204 nr = shfile_read(&psh->fdtab, psh->parsefile->fd, buf, BUFSIZ - 8);201 nr = shfile_read(&psh->fdtab, psh->parsefile->fd, buf, bufsize); 205 202 206 203 … … 221 218 } 222 219 nr = -1; 223 } else { 220 } 221 return nr; 222 } 223 224 225 226 static int 227 preadfd(shinstance *psh) 228 { 229 int nr; 230 char *buf = psh->parsefile->buf; 231 psh->parsenextc = buf; 232 224 233 #ifdef SH_DEAL_WITH_CRLF 234 /* Convert CRLF to LF. */ 235 nr = preadfd_inner(psh, buf, BUFSIZ - 9); 236 if (nr > 0) { 225 237 char *cr = memchr(buf, '\r', nr); 226 238 while (cr) { 227 239 size_t left = nr - (cr - buf); 240 228 241 if (left > 1 && cr[1] == '\n') { 229 242 left--; … … 231 244 memmove(cr, cr + 1, left); 232 245 cr = memchr(cr, '\r', left); 246 } else if (left == 1) { 247 /* Special case: \r at buffer end. Read one more char. Screw \r\r\n sequences. */ 248 int nr2 = preadfd_inner(psh, cr + 1, 1); 249 if (nr2 != 1) 250 break; 251 if (cr[1] == '\n') { 252 *cr = '\n'; 253 } else { 254 nr++; 255 } 256 break; 233 257 } else { 234 258 cr = memchr(cr + 1, '\r', left); 235 259 } 236 260 } 261 } 262 #else 263 nr = preadfd_inner(psh, buf, BUFSIZ - 8); 237 264 #endif 238 }239 265 return nr; 240 266 }
Note:
See TracChangeset
for help on using the changeset viewer.