Results 1 to 2 of 2

Thread: Trouble with opening a file using "openfile"

  1. #1
    ... connecting
    Join Date
    Apr 2021
    Location
    Michigan
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Trouble with opening a file using "openfile"

    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:
    Code:
      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:

    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.
    Last edited by Borch; 23rd July 2023 at 18:54.

  2. #2
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    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/bl...utils.cpp#L588
    https://en.cppreference.com/w/cpp/io/c/fopen
    Last edited by Mitch; 23rd July 2023 at 20:12.

  3. The Following User Says Thank You to Mitch For This Useful Post:

    Borch (23rd July 2023)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •