Ascii pfiles file access routines.

From: Patrick J. Dughi (dughi@IMAXX.NET)
Date: 11/21/97


        I hadn't really noticed it before, but I was just searching
through some code to fix a bug and found something rather puzzling.

        first, I'm using sammy's pfile code, from way back, and pretty
much fixed it myself long ago. In most respects, it should be functionally
equivalant.

        Now, looking through db.c in the file loading procedures,
and under save_char, i see the file lookup in the following manner:

    for (i = 0;
      (*(bits + i) = LOWER(*(player.name + i))); i++);
    sprintf(outname, "pfiles/%c/%s", *bits, bits);

    if (!(outfile = fopen(outname, "w"))) {
      perror("error opening output file");
      exit(1);
    }

        Simple, we make sure the characters name is lowercased, and then
take "pfiles/<first letter of lowercased name>/<lowercased name>" as the
path to the file we want to write to.

        Later, in load_char, we see this same file accessed in the
following way:

    sprintf(filename, "%s/%c/%s", PLR_PREFIX, *player_table[id].name,
      player_table[id].name);
    fl=fopen(filename, "a");
    fclose(fl);
    if(!(fl = fopen(filename, "r"))) {
      sprintf(buf, "SYSERR: Couldn't open player file %s", filename);
      log(buf);
      free(player);
      return (-1);
    }
(btw, #define PLR_PREFIX "pfiles"        /* player ascii file directory */)

        Now, I was fooling around with some incredibly unrelated code
(boards of all things), and created a problem - after a
Board_save_board() call, which doesn't do much beyond writing out a board
file, the "load_char" call causes a seg fault.  Actually, it prints out
the "SYSERR: Couldn't open player file pfiles/<capital first
letter>/<Capitalized name>". Then, it crashes on the "free(player)" line.
        Well, maybe that makes sense.  I mean, the file isn't there, as
its path has capital letters in it.
        I'm lazy. I made it de-capitalize the letters, mimicing the code
from the first part. So, the file opens, no problem.. but now,

        Question1:  How did it work before w/o de-capitalizing?
        Question2:  Aside from opening another file handle, why would this
board saving function cause the fopen to not work, in regards to question
1?  Even if it opened the other file handle (only one, and it closes it
too..), it still ought to continue functioning as it did before...

        ObMeasureOfSkill:
                Yes, I know how to code. I've done it for a few years now.
                No, I haven't changed anything else, only playing with
                boards files, nothing char related.
                Yes, I'm sure.
                Yes, I checked twice.
                I'm not stupid. It was only the board files.
                All above info is true. Assume that knowledge of crashes
                and functions is correct, used gdb, etc.

Additional errata:
Linux 2.1.64
libc.so.5.4.33
gcc 2.7.2.2

                                                PjD


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST