@@ -499,51 +499,17 @@ VAL idris_strlen(VM* vm, VAL l) {
499 return MKINT((i_int)(idris_utf8_strlen(GETSTR(l))));
499 return MKINT((i_int)(idris_utf8_strlen(GETSTR(l))));
504VAL idris_readStr(VM* vm, FILE* h) {
502VAL idris_readStr(VM* vm, FILE* h) {
505−// Modified from 'safe-fgets.c' in the gdb distribution.
503+ // FIXME (quickly...): This will fail if there is a line longer than
506−// (see http://www.gnu.org/software/gdb/current/)
504+ // bufsize characters!
507− char *line_ptr;
505+ int bufsize = 255;
508− char* line_buf = (char *) malloc (BUFSIZE);
509− int line_buf_size = BUFSIZE;
511− /* points to last byte */
512− line_ptr = line_buf + line_buf_size - 1;
514− /* so we can see if fgets put a 0 there */
516− if (fgets (line_buf, line_buf_size, h) == 0)
517− return MKSTR(vm, "");
519− /* we filled the buffer? */
520− while (line_ptr[0] == 0 && line_ptr[-1] != '\n')
522− /* Make the buffer bigger and read more of the line */
523− line_buf_size += BUFSIZE;
524− { /* limit the scope of new_line_buf to where it's needed for errors*/
525− char *new_line_buf = realloc (line_buf, line_buf_size);
526− if (new_line_buf == NULL)
528− fprintf(stderr, "Fatal Error: couldn't allocate a larger line buffer.");
531− line_buf = new_line_buf;
534− /* points to last byte again */
535− line_ptr = line_buf + line_buf_size - 1;
536− /* so we can see if fgets put a 0 there */
539− if (fgets (line_buf + line_buf_size - BUFSIZE - 1, BUFSIZE + 1, h) == 0)
507+ char* buffer = malloc(bufsize+1);
508+ if (fgets(buffer, bufsize, h) == 0) {
540− return MKSTR(vm, "");
509+ return MKSTR(vm, "");
511+ return MKSTR(vm, buffer);
543− VAL str = MKSTR(vm, line_buf);
544−// printf("DBG: %s\n", line_buf);
549VAL idris_strHead(VM* vm, VAL str) {
515VAL idris_strHead(VM* vm, VAL str) {