Example #1
0
void AddObjFiles (int argc, char* argv [])
/* Add object files to a library */
{
    int I;

    /* Check the argument count */
    if (argc <= 0) {
    	Error ("No library name given");
    }
    if (argc <= 1) {
    	Error ("No object files to add");
    }

    /* Open the library, read the index */
    LibOpen (argv [0], 0, 1);

    /* Add the object files */
    I = 1;
    while (I < argc) {
    	ObjAdd (argv [I]);
    	++I;
    }

    /* Create a new library file and close the old one */
    LibClose ();

    /* Successful end */
    exit (EXIT_SUCCESS);
}
Example #2
0
void WriteNewLib( void )
{
    char tmp[ _MAX_PATH + 1 ];
    char *bak,*lib,*out;

    lib = Options.input_name;
    if( Options.output_name != NULL && !SameFile( lib, Options.output_name ) ) {
        out = Options.output_name;
    } else {
        out = MakeTmpName( tmp );
    }
    if( Options.export_list_file ) {
        ExportListFile = LibOpen( Options.export_list_file, LIBOPEN_BINARY_WRITE | O_CREAT);
    } else {
        ExportListFile = NULL;
    }
    NewLibrary = LibOpen( out, LIBOPEN_BINARY_WRITE );
    if( NewLibrary == NULL ) {
        if( out == tmp ) {
            FatalError( ERR_CANT_OPEN, out, "Cannot create temporary file" );
        } else {
            FatalError( ERR_CANT_OPEN, out, strerror( errno ) );
        }
    }
    WriteFileTable();
    LibClose( NewLibrary );
    if( ExportListFile != NULL ) {
        LibClose( ExportListFile );
    }
    ResetInputLibs();//closes all input libs
    if( out == tmp ) {
        bak = MakeBakName();
        if( access( bak, F_OK ) == 0 && remove( bak ) != 0 ) {
            FatalError( ERR_CANT_REMOVE, bak );
        }
        if( access( lib, F_OK ) == 0 && rename( lib, bak ) != 0 ) {
            FatalError( ERR_CANT_REPLACE, lib, strerror( errno ) );
        }
        if( rename( tmp, lib ) != 0 ) {
            rename( bak, lib );
            FatalError( ERR_CANT_REPLACE, lib, strerror( errno ) );
        }
        if( Options.no_backup ) {
            remove( bak );
        }
    }
}
Example #3
0
void CloseObjFile( obj_file *ofile )
/**********************************/
{
    libfile     hdl;

    hdl = ofile->hdl;
    DoCloseObjFile( ofile );
    LibClose( hdl );
}
Example #4
0
void ow_exit(int exit_code)
{
    LEVEL_DEBUG("Exit code = %d", exit_code);
    if (IS_MAINTHREAD) {
        LibClose();
    }

#ifdef __UCLIBC__
    /* Process never die on WRT54G router with uClibc if exit() is used */
    _exit(exit_code);
#else
    exit(exit_code);
#endif
}
Example #5
0
static void ExtractObj( libfile io, char *name, arch_header *arch, char *newname )
{
    file_offset  pos;
    libfile      out;
    char        *obj_name;

    obj_name = MakeObjOutputName( name, newname );
    remove( obj_name );
    out = LibOpen( obj_name, LIBOPEN_WRITE );
    pos = LibTell( io );
    CopyObj( io, out, arch );
    LibSeek( io, pos, SEEK_SET );
    LibClose( out );
    if( Options.ar && Options.verbose ) {
        Message( "x - %s", obj_name );
    }
}
Example #6
0
static void ProcessLibOrObj( char *name, objproc obj, void (*process)( arch_header *arch, libfile io ) )
{
    libfile     io;
    unsigned char   buff[ AR_IDENT_LEN ];
    arch_header arch;

    NewArchHeader( &arch, name );
    io = LibOpen( name, LIBOPEN_READ );
    if( LibRead( io, buff, sizeof( buff ) ) != sizeof( buff ) ) {
        FatalError( ERR_CANT_READ, name, strerror( errno ) );
    }
    if( memcmp( buff, AR_IDENT, sizeof( buff ) ) == 0 ) {
        // AR format
        AddInputLib( io, name );
        LibWalk( io, name, process );
        if( Options.libtype == WL_LTYPE_NONE ) {
            Options.libtype = WL_LTYPE_AR;
        }
    } else if( memcmp( buff, LIBMAG, LIBMAG_LEN ) == 0 ) {
        // MLIB format
        if( LibRead( io, buff, sizeof( buff ) ) != sizeof( buff ) ) {
            FatalError( ERR_CANT_READ, name, strerror( errno ) );
        }
        if( memcmp( buff, LIB_CLASS_DATA_SHOULDBE, LIB_CLASS_LEN + LIB_DATA_LEN ) ) {
            BadLibrary( name );
        }
        AddInputLib( io, name );
        LibWalk( io, name, process );
        if( Options.libtype == WL_LTYPE_NONE ) {
            Options.libtype = WL_LTYPE_MLIB;
        }
    } else if( AddImport( &arch, io ) ) {
        LibClose( io );
    } else if( buff[ 0 ] == LIB_HEADER_REC && buff[ 1 ] != 0x01 ) {
        /*
          The buff[ 1 ] != 1 bit above is a bad hack to get around
          the fact that the coff cpu_type for PPC object files is
          0x1f0.  Really, we should be reading in the first object
          record and doing the checksum and seeing if it is actually
          a LIB_HEADER_REC.  All file format designers who are too
          stupid to recognize the need for a signature should be
          beaten up with large blunt objects.
         */
        // OMF format
        AddInputLib( io, name );
        LibSeek( io, 0, SEEK_SET );
        if( Options.libtype == WL_LTYPE_NONE ) {
            Options.libtype = WL_LTYPE_OMF;
        }
        OMFLibWalk( io, name, process );
    } else if( obj == OBJ_PROCESS ) {
        // Object
        LibSeek( io, 0, SEEK_SET );
        AddObjectSymbols( &arch, io, 0 );
        LibClose( io );
    } else if( obj == OBJ_ERROR ) {
        BadLibrary( name );
    } else {
        LibClose( io );
    }
}