/*****************************************************************************/
-/* */
-/* objfile.c */
-/* */
-/* Object file handling for the ar65 archiver */
-/* */
-/* */
-/* */
+/* */
+/* objfile.c */
+/* */
+/* Object file handling for the ar65 archiver */
+/* */
+/* */
+/* */
/* (C) 1998-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
-/* */
-/* */
-/* This software is provided 'as-is', without any expressed or implied */
+/* */
+/* */
+/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
-/* arising from the use of this software. */
-/* */
+/* arising from the use of this software. */
+/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
-/* freely, subject to the following restrictions: */
-/* */
+/* freely, subject to the following restrictions: */
+/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
-/* appreciated but is not required. */
+/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
-/* be misrepresented as being the original software. */
-/* 3. This notice may not be removed or altered from any source */
-/* distribution. */
-/* */
+/* be misrepresented as being the original software. */
+/* 3. This notice may not be removed or altered from any source */
+/* distribution. */
+/* */
/*****************************************************************************/
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
/* Must not end with a path separator */
if (*Module == 0) {
- Error ("Cannot make module name from `%s'", Name);
+ Error ("Cannot make module name from `%s'", Name);
}
/* Done */
static void ObjReadHeader (FILE* Obj, ObjHeader* H, const char* Name)
/* Read the header of the object file checking the signature */
{
- H->Magic = Read32 (Obj);
+ H->Magic = Read32 (Obj);
if (H->Magic != OBJ_MAGIC) {
- Error ("`%s' is not an object file", Name);
+ Error ("`%s' is not an object file", Name);
}
- H->Version = Read16 (Obj);
+ H->Version = Read16 (Obj);
if (H->Version != OBJ_VERSION) {
- Error ("Object file `%s' has wrong version", Name);
+ Error ("Object file `%s' has wrong version", Name);
}
- H->Flags = Read16 (Obj);
+ H->Flags = Read16 (Obj);
H->OptionOffs = Read32 (Obj);
H->OptionSize = Read32 (Obj);
H->FileOffs = Read32 (Obj);
H->FileSize = Read32 (Obj);
- H->SegOffs = Read32 (Obj);
- H->SegSize = Read32 (Obj);
+ H->SegOffs = Read32 (Obj);
+ H->SegSize = Read32 (Obj);
H->ImportOffs = Read32 (Obj);
H->ImportSize = Read32 (Obj);
H->ExportOffs = Read32 (Obj);
/* Handle then different expression nodes */
switch (Op) {
- case EXPR_NULL:
- break;
+ case EXPR_NULL:
+ break;
case EXPR_LITERAL:
- /* 32 bit literal value */
- (void) Read32 (F);
- break;
+ /* 32 bit literal value */
+ (void) Read32 (F);
+ break;
case EXPR_SYMBOL:
- /* Variable seized symbol index */
- (void) ReadVar (F);
- break;
+ /* Variable seized symbol index */
+ (void) ReadVar (F);
+ break;
case EXPR_SECTION:
- /* 8 bit segment number */
- (void) Read8 (F);
- break;
+ /* 8 bit segment number */
+ (void) Read8 (F);
+ break;
default:
/* What's left are unary and binary nodes */
/* Open the object file */
FILE* Obj = fopen (Name, "rb");
if (Obj == 0) {
- Error ("Could not open `%s': %s", Name, strerror (errno));
+ Error ("Could not open `%s': %s", Name, strerror (errno));
}
/* Get the modification time of the object file. There a race condition
* here.
*/
if (FileStat (Name, &StatBuf) != 0) {
- Error ("Cannot stat object file `%s': %s", Name, strerror (errno));
+ Error ("Cannot stat object file `%s': %s", Name, strerror (errno));
}
/* Read and check the header */
/* Check if we already have a module with this name */
O = FindObjData (Module);
if (O == 0) {
- /* Not found, create a new entry */
- O = NewObjData ();
+ /* 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'",
+ /* 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 = (unsigned long) StatBuf.st_mtime;
+ O->Flags = OBJ_HAVEDATA;
+ O->MTime = (unsigned long) StatBuf.st_mtime;
O->Start = 0;
/* Determine the file size. Note: Race condition here */
/* Bail out if the module does not exist */
if (O == 0) {
- Error ("Module `%s' not found in library `%s'", Module, LibName);
+ Error ("Module `%s' not found in library `%s'", Module, LibName);
}
/* Open the output file */
Obj = fopen (Name, "w+b");
if (Obj == 0) {
- Error ("Cannot open target file `%s': %s", Name, strerror (errno));
+ Error ("Cannot open target file `%s': %s", Name, strerror (errno));
}
/* Copy the complete object file data from the library to the new object
/* Close the file */
if (fclose (Obj) != 0) {
- Error ("Problem closing object file `%s': %s", Name, strerror (errno));
+ Error ("Problem closing object file `%s': %s", Name, strerror (errno));
}
/* Set access and modification time */
if (SetFileTimes (Name, O->MTime) != 0) {
- Error ("Cannot set mod time on `%s': %s", Name, strerror (errno));
+ Error ("Cannot set mod time on `%s': %s", Name, strerror (errno));
}
}