]> git.sur5r.net Git - cc65/blobdiff - src/od65/fileio.c
Rather stay with OFF_YEAR as it is an "officially" name.
[cc65] / src / od65 / fileio.c
index f700f3186b9e0a77e97e6fd4e419313f64432d1d..a1493500689331bc6b8cde996cd6fb1de88b1722 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -51,9 +51,9 @@
 
 
 
-void FileSeek (FILE* F, unsigned long Pos)
+void FileSetPos (FILE* F, unsigned long Pos)
 /* Seek to the given absolute position, fail on errors */
-{
+{                 
     if (fseek (F, Pos, SEEK_SET) != 0) {
        Error ("Cannot seek: %s", strerror (errno));
     }
@@ -61,6 +61,18 @@ void FileSeek (FILE* F, unsigned long Pos)
 
 
 
+unsigned long FileGetPos (FILE* F)
+/* Return the current file position, fail on errors */
+{
+    long Pos = ftell (F);
+    if (Pos < 0) {
+               Error ("Error in ftell: %s", strerror (errno));
+    }
+    return Pos;
+}
+
+
+
 unsigned Read8 (FILE* F)
 /* Read an 8 bit value from the file */
 {
@@ -179,8 +191,11 @@ FilePos* ReadFilePos (FILE* F, FilePos* Pos)
 void* ReadData (FILE* F, void* Data, unsigned Size)
 /* Read data from the file */
 {
-    if (fread (Data, 1, Size, F) != Size) {
-       Error ("Read error (file corrupt?)");
+    /* Accept zero sized reads */
+    if (Size > 0) {
+       if (fread (Data, 1, Size, F) != Size) {
+           Error ("Read error (file corrupt?)");
+       }
     }
     return Data;
 }
@@ -206,6 +221,30 @@ void ReadObjHeader (FILE* F, ObjHeader* H)
     H->ExportSize   = Read32 (F);
     H->DbgSymOffs   = Read32 (F);
     H->DbgSymSize   = Read32 (F);
+    H->LineInfoOffs = Read32 (F);
+    H->LineInfoSize = Read32 (F);
+    H->StrPoolOffs  = Read32 (F);
+    H->StrPoolSize  = Read32 (F);
+    H->AssertOffs   = Read32 (F);
+    H->AssertSize   = Read32 (F);
+    H->ScopeOffs    = Read32 (F);
+    H->ScopeSize    = Read32 (F);
+    H->SpanOffs     = Read32 (F);
+    H->SpanSize     = Read32 (F);
+}
+
+
+
+void ReadStrPool (FILE* F, Collection* C)
+/* Read a string pool from the current position into C. */
+{
+    /* The number of strings is the first item */
+    unsigned long Count = ReadVar (F);
+
+    /* Read all the strings into C */
+    while (Count--) {
+        CollAppend (C, ReadStr (F));
+    }
 }