예제 #1
0
파일: library.c 프로젝트: nedwidek/cc65
static void ReadIndex (void)
/* Read the index of a library file */
{
    unsigned Count, I;

    /* Seek to the start of the index */
    fseek (Lib, Header.IndexOffs, SEEK_SET);

    /* Read the object file count and calculate the cross ref size */
    Count = ReadVar (Lib);

    /* Read all entries in the index */
    while (Count--) {
        ReadIndexEntry ();
    }

    /* Read basic object file data from the actual entries */
    for (I = 0; I < CollCount (&ObjPool); ++I) {

        /* Get the object file entry */
        ObjData* O = CollAtUnchecked (&ObjPool, I);

        /* Read data */
        ObjReadData (Lib, O);
    }
}
예제 #2
0
파일: objfile.c 프로젝트: eakmeister/cc65
void ObjAdd (const char* Name)
/* Add an object file to the library */
{
    struct stat StatBuf;
    const char* Module;
    ObjHeader H;
    ObjData* O;

    /* Open the object file */
    FILE* Obj = fopen (Name, "rb");
    if (Obj == 0) {
        Error ("Could not open `%s': %s", Name, strerror (errno));
    }

    /* Get the modification time of the object file. There a race condition
     * here, since we cannot use fileno() (non standard identifier in standard
     * header file), and therefore not fstat. When using stat with the
     * file name, there's a risk that the file was deleted and recreated
     * while it was open. Since mtime and size are only used to check
     * if a file has changed in the debugger, we will ignore this problem
     * here.
     */
    if (FileStat (Name, &StatBuf) != 0) {
        Error ("Cannot stat object file `%s': %s", Name, strerror (errno));
    }

    /* Read and check the header */
    ObjReadHeader (Obj, &H, Name);

    /* Make a module name from the file name */
    Module = GetModule (Name);

    /* Check if we already have a module with this name */
    O = FindObjData (Module);
    if (O == 0) {
        /* Not found, create a new entry */
        O = NewObjData ();
    } else {
        /* Found - check the file modification times of the internal copy
         * and the external one.
         */
        if (difftime ((time_t)O->MTime, StatBuf.st_mtime) > 0.0) {
            Warning ("Replacing module `%s' by older version in library `%s'",
                     O->Name, LibName);
        }

        /* Free data */
        ClearObjData (O);
    }

    /* Initialize the object module data structure */
    O->Name     = xstrdup (Module);
    O->Flags  	= OBJ_HAVEDATA;
    O->MTime  	= StatBuf.st_mtime;
    O->Start    = 0;

    /* Determine the file size. Note: Race condition here */
    fseek (Obj, 0, SEEK_END);
    O->Size     = ftell (Obj);

    /* Read the basic data from the object file */
    ObjReadData (Obj, O);

    /* Copy the complete object data to the library file and update the
     * starting offset
     */
    fseek (Obj, 0, SEEK_SET);
    O->Start    = LibCopyTo (Obj, O->Size);

    /* Done, close the file (we read it only, so no error check) */
    fclose (Obj);
}