new copyright notice
[unix-history] / usr / src / old / ld / ld.c
index fd57962..10b643f 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)ld.c       5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)ld.c       5.14 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -19,14 +19,15 @@ static char sccsid[] = "@(#)ld.c    5.11 (Berkeley) %G%";
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
-#include <signal.h>
-#include <stdio.h>
-#include <ctype.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <sys/signal.h>
 #include <ar.h>
 #include <a.out.h>
 #include <ranlib.h>
 #include <ar.h>
 #include <a.out.h>
 #include <ranlib.h>
-#include <sys/stat.h>
-#include <sys/file.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
 #include "pathnames.h"
 
 /*
 #include "pathnames.h"
 
 /*
@@ -321,7 +322,8 @@ struct      biobuf *tout, *dout, *trout, *drout, *sout, *strout;
 off_t  offset = sizeof (off_t);
 
 int    ofilfnd;                /* -o given; otherwise move l.out to a.out */
 off_t  offset = sizeof (off_t);
 
 int    ofilfnd;                /* -o given; otherwise move l.out to a.out */
-char   *ofilename = "l.out";
+char   *defaultname;           /* l.out */
+char   *ofilename;             /* name given to -o */
 int    ofilemode;              /* respect umask even for unsucessful ld's */
 int    infil;                  /* current input file descriptor */
 char   *filname;               /* and its name */
 int    ofilemode;              /* respect umask even for unsucessful ld's */
 int    infil;                  /* current input file descriptor */
 char   *filname;               /* and its name */
@@ -360,6 +362,7 @@ char **argv;
        }
        if (argc == 1)
                exit(4);
        }
        if (argc == 1)
                exit(4);
+       ofilename = defaultname = (char *)genbuildname("l.out");
        pagesize = getpagesize();
 
        /* 
        pagesize = getpagesize();
 
        /* 
@@ -376,7 +379,6 @@ char **argv;
                }
        }
        /* add default search directories */
                }
        }
        /* add default search directories */
-       dirs[ndir++] = _PATH_LIB;
        dirs[ndir++] = _PATH_USRLIB;
        dirs[ndir++] = _PATH_LOCALLIB;
 
        dirs[ndir++] = _PATH_USRLIB;
        dirs[ndir++] = _PATH_LOCALLIB;
 
@@ -398,7 +400,7 @@ char **argv;
                case 'o':
                        if (++c >= argc)
                                error(1, "-o where?");
                case 'o':
                        if (++c >= argc)
                                error(1, "-o where?");
-                       ofilename = *p++;
+                       ofilename = (char *)genbuildname(*p++);
                        ofilfnd++;
                        continue;
                case 'u':
                        ofilfnd++;
                        continue;
                case 'u':
@@ -550,7 +552,7 @@ delexit()
        char c = 0;
 
        bflush();
        char c = 0;
 
        bflush();
-       unlink("l.out");
+       unlink(defaultname);
        /*
         * We have to insure that the last block of the data segment
         * is allocated a full pagesize block. If the underlying
        /*
         * We have to insure that the last block of the data segment
         * is allocated a full pagesize block. If the underlying
@@ -1047,17 +1049,16 @@ struct  biobuf toutb;
 
 setupout()
 {
 
 setupout()
 {
+       extern int errno;
        int bss;
        struct stat stbuf;
        int bss;
        struct stat stbuf;
-       extern char *sys_errlist[];
-       extern int errno;
 
        ofilemode = 0777 & ~umask(0);
        biofd = creat(ofilename, 0666 & ofilemode);
        if (biofd < 0) {
                filname = ofilename;            /* kludge */
                archdr.ar_name[0] = 0;          /* kludge */
 
        ofilemode = 0777 & ~umask(0);
        biofd = creat(ofilename, 0666 & ofilemode);
        if (biofd < 0) {
                filname = ofilename;            /* kludge */
                archdr.ar_name[0] = 0;          /* kludge */
-               error(1, sys_errlist[errno]);   /* kludge */
+               error(1, strerror(errno));      /* kludge */
        }
        fstat(biofd, &stbuf);           /* suppose file exists, wrong*/
        if (stbuf.st_mode & 0111) {     /* mode, ld fails? */
        }
        fstat(biofd, &stbuf);           /* suppose file exists, wrong*/
        if (stbuf.st_mode & 0111) {     /* mode, ld fails? */
@@ -1538,6 +1539,7 @@ load2td(creloc, position, b1, b2)
 finishout()
 {
        register int i;
 finishout()
 {
        register int i;
+       char *newname;
        int nsymt;
 
        if (sflag==0) {
        int nsymt;
 
        if (sflag==0) {
@@ -1547,10 +1549,11 @@ finishout()
                bwrite(&offset, sizeof offset, sout);
        }
        if (!ofilfnd) {
                bwrite(&offset, sizeof offset, sout);
        }
        if (!ofilfnd) {
-               unlink("a.out");
-               if (link("l.out", "a.out") < 0)
+               newname = (char *)genbuildname("a.out");
+               unlink(newname);
+               if (link(defaultname, newname) < 0)
                        error(1, "cannot move l.out to a.out");
                        error(1, "cannot move l.out to a.out");
-               ofilename = "a.out";
+               ofilename = newname;
        }
        delarg = errlev;
        delexit();
        }
        delarg = errlev;
        delexit();
@@ -1710,7 +1713,7 @@ char *acp;
        if (filname[0] == '-' && filname[1] == 'l')
                infil = libopen(filname + 2, O_RDONLY);
        else
        if (filname[0] == '-' && filname[1] == 'l')
                infil = libopen(filname + 2, O_RDONLY);
        else
-               infil = open(filname, O_RDONLY);
+               infil = open((char *)genbuildname(filname), O_RDONLY);
        if (infil < 0)
                error(1, "cannot open");
        fstat(infil, &stb);
        if (infil < 0)
                error(1, "cannot open");
        fstat(infil, &stb);