/* */
/* */
/* */
-/* (C) 1998-2012, Ullrich von Bassewitz */
+/* (C) 1998-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
#include <errno.h>
/* common */
+#include "cmdline.h"
#include "exprdefs.h"
#include "libdefs.h"
#include "print.h"
/*****************************************************************************/
-
+
/* Name of the library file */
const char* LibName = 0;
+static char* NewLibName = 0;
/* File descriptor for the library file */
-FILE* NewLib = 0;
static FILE* Lib = 0;
+static FILE* NewLib = 0;
/* The library header */
static LibHeader Header = {
}
Header.Flags = Read16 (Lib);
Header.IndexOffs = Read32 (Lib);
-}
+}
void LibOpen (const char* Name, int MustExist, int NeedTemp)
/* Open an existing library and a temporary copy. If MustExist is true, the
- * old library is expected to exist. If NeedTemp is true, a temporary library
- * is created.
- */
+** old library is expected to exist. If NeedTemp is true, a temporary library
+** is created.
+*/
{
/* Remember the name */
LibName = xstrdup (Name);
if (MustExist) {
Error ("Library `%s' does not exist", Name);
} else {
- Warning ("Library `%s' not found - will be created", Name);
+ /* Announce the library's creation if ar65 is verbose. */
+ Print (stdout, 1,
+ "%s: Library `%s' will be created.\n", ProgName, Name);
}
} else {
}
if (NeedTemp) {
+
+ /* Create the temporary library name */
+ NewLibName = xmalloc (strlen (Name) + strlen (".temp") + 1);
+ strcpy (NewLibName, Name);
+ strcat (NewLibName, ".temp");
+
/* Create the temporary library */
- NewLib = tmpfile ();
+ NewLib = fopen (NewLibName, "w+b");
if (NewLib == 0) {
- Error ("Cannot create temporary file: %s", strerror (errno));
+ Error ("Cannot create temporary library file: %s", strerror (errno));
}
/* Write a dummy header to the temp file */
unsigned long LibCopyTo (FILE* F, unsigned long Bytes)
/* Copy data from F to the temp library file, return the start position in
- * the temporary library file.
- */
+** the temporary library file.
+*/
{
unsigned char Buf [4096];
static void LibCheckExports (ObjData* O)
/* Insert all exports from the given object file into the global list
- * checking for duplicates.
- */
+** checking for duplicates.
+*/
{
unsigned I;
/* Let the user know what we do */
- Print (stdout, 1, "Module `%s' (%u exports):\n", O->Name, CollCount (&O->Exports));
+ Print (stdout, 2, "Module `%s' (%u exports):\n", O->Name, CollCount (&O->Exports));
/* Insert the exports into the global table */
for (I = 0; I < CollCount (&O->Exports); ++I) {
const char* Name = CollConstAt (&O->Exports, I);
/* Insert the name into the hash table */
- Print (stdout, 1, " %s\n", Name);
+ Print (stdout, 2, " %s\n", Name);
ExpInsert (Name, O);
}
}
void LibClose (void)
/* Write remaining data, close both files and copy the temp file to the old
- * filename
- */
+** filename
+*/
{
/* Do we have a temporary library? */
if (NewLib) {
size_t Count;
/* Walk through the object file list, inserting exports into the
- * export list checking for duplicates. Copy any data that is still
- * in the old library into the new one.
- */
+ ** export list checking for duplicates. Copy any data that is still
+ ** in the old library into the new one.
+ */
for (I = 0; I < CollCount (&ObjPool); ++I) {
/* Get a pointer to the object */
LibName, strerror (errno));
}
- /* Copy the new library to the new one */
+ /* Copy the temporary library to the new one */
fseek (NewLib, 0, SEEK_SET);
while ((Count = fread (Buf, 1, sizeof (Buf), NewLib)) != 0) {
if (fwrite (Buf, 1, Count, Lib) != Count) {
if (NewLib && fclose (NewLib) != 0) {
Error ("Problem closing temporary library file: %s", strerror (errno));
}
+ if (NewLibName && remove (NewLibName) != 0) {
+ Error ("Problem deleting temporary library file: %s", strerror (errno));
+ }
}
-
-
-