* support/librarian/sdcclib.c: moved include <limits.h> up to enable
[fw/sdcc] / support / librarian / sdcclib.c
index 1d77bc895ab3289d5d0c89b26c11f76f33694cd6..70d1bda67935220c6c80b2e33f7be74a27509d76 100644 (file)
@@ -15,11 +15,11 @@ 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
@@ -188,6 +188,7 @@ void AddRel(void)
     long newlibpos, indexsize;
     char symname[MAXLINE+1];
     char c;
+    int IsDOSStyle=0;
 
     strcpy(LibNameTmp, LibName);
     ChangeExtension(LibNameTmp, "__L");
@@ -332,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))