* as/hc08/asmain.c (asexit),
[fw/sdcc] / support / librarian / sdcclib.c
index ef058e7ae165d6425d2ce21225b3f9299ec23c5f..80aedc10ef40d8142aa1fe4391d9462d98072399 100644 (file)
@@ -15,11 +15,14 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 
+#define _POSIX_
+#include <limits.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#define _POSIX_
-#include <limits.h>
+#if !defined(__BORLANDC__) && !defined(_MSC_VER)
+#include <unistd.h>
+#endif
 
 char ProgName[PATH_MAX];
 char LibName[PATH_MAX];
@@ -58,7 +61,7 @@ void GetNameFromPath(char * path, char * name)
 
 void ChangeExtension(char * path, char * ext)
 {
-       int i, j;
+       int i;
 
        for(i=0; path[i]!=0; i++);
        for(; (path[i]!='.')&&(path[i]!='\\')&&(path[i]!='/')&&(i>=0); i--);
@@ -86,7 +89,6 @@ void CleanLine(char * buff)
 
 int set_options (char * opt)
 {
-       char temp[255];
        int rvalue=0, unknown=0;
        static char Help[] =
        "Usage: %s [-options] library relfile\n\n"
@@ -186,6 +188,7 @@ void AddRel(void)
     long newlibpos, indexsize;
     char symname[MAXLINE+1];
     char c;
+    int IsDOSStyle=0;
 
     strcpy(LibNameTmp, LibName);
     ChangeExtension(LibNameTmp, "__L");
@@ -330,10 +333,17 @@ void AddRel(void)
     lib=fopen(LibName, "w");
     libindex=fopen(IndexName, "r");
 
-    fprintf(lib, "<SDCCLIB>\n\n");
-    fprintf(lib, "<INDEX>\n");
+    fprintf(lib, "<SDCCLIB>\n\n<INDEX>\n");
+
+    /*Find out if the \n is expanded to \r\n or not*/
+    if(ftell(lib)!=(long)strlen("<SDCCLIB>\n\n<INDEX>\n"))
+    {
+        IsDOSStyle=1;
+    }
+
+    indexsize+=ftell(lib)+strlen("0123456789\n\n</INDEX>\n\n");
+    if(IsDOSStyle) indexsize+=4;
 
-    indexsize+=ftell(lib)+12+14;
     fprintf(lib, "%10ld\n", indexsize);
 
     while(!feof(libindex))
@@ -357,8 +367,8 @@ void AddRel(void)
     fclose(lib);
     fclose(libindex);
 
-    unlink(LibNameTmp);
-    unlink(IndexName);
+    remove(LibNameTmp);
+    remove(IndexName);
 }
 
 void ExtractRel(void)