-/*
-====================
-FS_Gets
-
-Extract a line from a file
-====================
-*/
-char* FS_Gets (qfile_t* file, char* buffer, size_t buffersize)
-{
- size_t ind;
-
- for (ind = 0; ind < (size_t) buffersize - 1; ind++)
- {
- int c = FS_Getc (file);
- switch (c)
- {
- // End of file
- case EOF:
- if (!ind)
- return NULL;
-
- buffer[ind] = '\0';
- return buffer;
-
- // End of line
- case '\r':
- case '\n':
- buffer[ind] = '\n';
- buffer[ind + 1] = '\0';
- return buffer;
-
- default:
- buffer[ind] = c;
- }
-
- }
-
- buffer[buffersize - 1] = '\0';
- return buffer;
-}
-
-
-/*
-==========
-FS_Getline
-
-Dynamic length version of fgets. DO NOT free the buffer.
-==========
-*/
-char *FS_Getline (qfile_t *file)
-{
- static int size = 256;
- static char *buf = 0;
- char *t;
- int len;
-
- if (!buf)
- buf = Mem_Alloc (fs_mempool, size);
-
- if (!FS_Gets (file, buf, size))
- return 0;
-
- len = strlen (buf);
- while (buf[len - 1] != '\n' && buf[len - 1] != '\r')
- {
- t = Mem_Alloc (fs_mempool, size + 256);
- memcpy(t, buf, size);
- Mem_Free(buf);
- size += 256;
- buf = t;
- if (!FS_Gets (file, buf + len, size - len))
- break;
- len = strlen (buf);
- }
- while ((len = strlen(buf)) && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
- buf[len - 1] = 0;
- return buf;
-}
-
-