size_t alloclen;
prvm_stringbuffer_t *stringbuffer;
char string[VM_STRINGTEMP_LENGTH];
- int filenum, strindex, c, end;
+ int strindex, c, end;
const char *filename;
char vabuf[1024];
+ qfile_t *file;
VM_SAFEPARMCOUNT(2, VM_buf_loadfile);
// get file
filename = PRVM_G_STRING(OFS_PARM0);
- for (filenum = 0;filenum < PRVM_MAX_OPENFILES;filenum++)
- if (prog->openfiles[filenum] == NULL)
- break;
- prog->openfiles[filenum] = FS_OpenVirtualFile(va(vabuf, sizeof(vabuf), "data/%s", filename), false);
- if (prog->openfiles[filenum] == NULL)
- prog->openfiles[filenum] = FS_OpenVirtualFile(va(vabuf, sizeof(vabuf), "%s", filename), false);
- if (prog->openfiles[filenum] == NULL)
+ file = FS_OpenVirtualFile(va(vabuf, sizeof(vabuf), "data/%s", filename), false);
+ if (file == NULL)
+ file = FS_OpenVirtualFile(va(vabuf, sizeof(vabuf), "%s", filename), false);
+ if (file == NULL)
{
if (developer_extra.integer)
VM_Warning(prog, "VM_buf_loadfile: failed to open file %s in %s\n", filename, prog->name);
end = 0;
for (;;)
{
- c = FS_Getc(prog->openfiles[filenum]);
+ c = FS_Getc(file);
if (c == '\r' || c == '\n' || c < 0)
break;
if (end < VM_STRINGTEMP_LENGTH - 1)
// remove \n following \r
if (c == '\r')
{
- c = FS_Getc(prog->openfiles[filenum]);
+ c = FS_Getc(file);
if (c != '\n')
- FS_UnGetc(prog->openfiles[filenum], (unsigned char)c);
+ FS_UnGetc(file, (unsigned char)c);
}
// add and continue
if (c >= 0 || end)
}
// close file
- FS_Close(prog->openfiles[filenum]);
- prog->openfiles[filenum] = NULL;
- if (prog->openfiles_origin[filenum])
- PRVM_Free((char *)prog->openfiles_origin[filenum]);
+ FS_Close(file);
PRVM_G_FLOAT(OFS_RETURN) = 1;
}