136 |
{ |
{ |
137 |
size_t buf_len = (end + 1) - pt->read_pos; |
size_t buf_len = (end + 1) - pt->read_pos; |
138 |
/* Allocate a buffer of the perfect size. */ |
/* Allocate a buffer of the perfect size. */ |
139 |
unsigned char *buf = scm_must_malloc (buf_len + 1, "%read-line"); |
unsigned char *buf = scm_malloc (buf_len + 1); |
140 |
|
|
141 |
memcpy (buf, pt->read_pos, buf_len); |
memcpy (buf, pt->read_pos, buf_len); |
142 |
pt->read_pos += buf_len; |
pt->read_pos += buf_len; |
155 |
size_t buf_size = (len < 50) ? 60 : len * 2; |
size_t buf_size = (len < 50) ? 60 : len * 2; |
156 |
/* Invariant: buf always has buf_size + 1 characters allocated; |
/* Invariant: buf always has buf_size + 1 characters allocated; |
157 |
the `+ 1' is for the final '\0'. */ |
the `+ 1' is for the final '\0'. */ |
158 |
unsigned char *buf = scm_must_malloc (buf_size + 1, "%read-line"); |
unsigned char *buf = scm_malloc (buf_size + 1); |
159 |
size_t buf_len = 0; |
size_t buf_len = 0; |
160 |
|
|
161 |
for (;;) |
for (;;) |
163 |
if (buf_len + len > buf_size) |
if (buf_len + len > buf_size) |
164 |
{ |
{ |
165 |
size_t new_size = (buf_len + len) * 2; |
size_t new_size = (buf_len + len) * 2; |
166 |
buf = scm_must_realloc (buf, buf_size + 1, new_size + 1, |
buf = scm_realloc (buf, new_size + 1); |
|
"%read-line"); |
|
167 |
buf_size = new_size; |
buf_size = new_size; |
168 |
} |
} |
169 |
|
|
196 |
} |
} |
197 |
|
|
198 |
/* I wonder how expensive this realloc is. */ |
/* I wonder how expensive this realloc is. */ |
199 |
buf = scm_must_realloc (buf, buf_size + 1, buf_len + 1, "%read-line"); |
buf = scm_realloc (buf, buf_len + 1); |
200 |
buf[buf_len] = '\0'; |
buf[buf_len] = '\0'; |
201 |
*len_p = buf_len; |
*len_p = buf_len; |
202 |
return buf; |
return buf; |
203 |
} |
} |
204 |
} |
} |
205 |
|
|
206 |
|
|
207 |
/* |
/* |
246 |
term = SCM_MAKE_CHAR ('\n'); |
term = SCM_MAKE_CHAR ('\n'); |
247 |
s[slen-1] = '\0'; |
s[slen-1] = '\0'; |
248 |
line = scm_take_str (s, slen-1); |
line = scm_take_str (s, slen-1); |
|
scm_done_free (1); |
|
249 |
SCM_INCLINE (port); |
SCM_INCLINE (port); |
250 |
} |
} |
251 |
else |
else |
254 |
term = SCM_EOF_VAL; |
term = SCM_EOF_VAL; |
255 |
line = scm_take_str (s, slen); |
line = scm_take_str (s, slen); |
256 |
SCM_COL (port) += slen; |
SCM_COL (port) += slen; |
257 |
} |
} |
258 |
} |
} |
259 |
|
|
260 |
if (pt->rw_random) |
if (pt->rw_random) |