- size_t const s = fread(read_buf, 1, n, file);
- if (s == 0) {
- /* on OS/X ferror appears to return true on eof as well when running
- * the application in gdb... */
- if (!feof(file) && ferror(file))
- input_error(0, 0, "read from input failed");
- return 0;
+ if (input->kind == INPUT_FILE) {
+ FILE *file = input->in.file;
+ size_t const s = fread(read_buf, 1, n, file);
+ if (s == 0) {
+ /* on OS/X ferror appears to return true on eof as well when running
+ * the application in gdb... */
+ if (!feof(file) && ferror(file))
+ input_error(0, 0, "read from input failed");
+ return 0;
+ }
+ return s;
+ } else {
+ assert(input->kind == INPUT_STRING);
+ size_t len = strlen(input->in.string);
+ if (len > n)
+ len = n;
+ memcpy(read_buf, input->in.string, len);
+ input->in.string += len;
+ return len;