PDA

View Full Version : Trouble with opening a file using "openfile"



Borch
23rd July 2023, 16:16
I am running Ubuntu 22.04 and have been having problems getting a script to open a file. This is an unpatched version of cod2lnxded, is it possible that I don't have libcod installed properly? (I get a statement when I shut down the server that the plugin is unloaded).

At first I could not get file_exists or fileopen to work, but then found that it doesn't seem to work across filesystems, since when I put the target on the same filesystem, file_exists, using path, it started working.

After I figured out the file_exists issue with filesystems, I started getting the proper result when running that, but using the same path, I do not get a file to open successfully using openfile.

output of my logprints:

0:00 path=/home/dev/v3/ohmycod/extreme/spawns/mp_toujane.csv
0:00 exists=1
0:00 filenum=-1
0:00 count=-1 //count is the attempt to read the file

This is the code:



...
path="/home/dev/v3/ohmycod/extreme/spawns/" + level.ex_currentmap + ".csv";
logprint("path=" + path+ "\n");
logprint("exists=" + file_exists(path) + "\n");
if(file_exists(path))
{
filenum = openfile( path , "read" );
logprint("filenum=" + filenum + "\n");
count=FReadLn(filenum); //read first line, should be ok but will be skipped if not.
logprint("count=" + count + "\n");
...


I was able to get openfile to write to a file in the directory .callofduty2/fs_mod/scriptdata folder, in my home directory, without any directories in the path.

I am going to recompile and verify the settings.

Any ideas? Thanks in advance.

Mitch
23rd July 2023, 20:04
openfile is a stock function that only reads in the scriptdata directory.
You should look into the fopen, fread and fclose functions.
The documentation is missing these functions.

https://github.com/voron00/libcod/blob/master/gsc_utils.cpp#L588
https://en.cppreference.com/w/cpp/io/c/fopen