scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 3e27f21368cb83a271b34cee758b8506dcd2b1fb
parent e0ca556d2f15d3ebd4f13f79475d046452af2fba
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Feb 2019 14:06:49 +0000

[ld] Search libraries in -L path

Diffstat:
Msrc/cmd/ld/main.c | 30++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/cmd/ld/main.c b/src/cmd/ld/main.c @@ -270,28 +270,46 @@ newlibrary(FILE *fp) static FILE * openfile(char *name, char *buffer) { - size_t len; + size_t pathlen, len; FILE *fp; + char **bp, **base, **end; + char libname[FILENAME_MAX]; filename = name; membname = NULL; - if (name[0] != '-' || name[1] != 'l') { if ((fp = fopen(name, "rb")) == NULL) error(errstr()); return fp; } - len = strlen(name+2); - if (len > FILENAME_MAX-4) { + len = strlen(name+2) + 3; + if (len > FILENAME_MAX-1) { error("library name too long"); return NULL; } - strcat(strcpy(buffer, "lib"), name+2); + filename = buffer; + if ((fp = fopen(libname, "rb")) != NULL) + return fp; + + base = syslibs; + end = &syslibs[MAX_LIB_PATHS]; + for (bp = base; bp < end && *bp; ++bp) { + pathlen = strlen(*bp); + if (pathlen + len > FILENAME_MAX-1) + continue; + memcpy(libname, *bp, pathlen); + memcpy(libname+pathlen+1, buffer, len); + buffer[pathlen] = '/'; + + if ((fp = fopen(buffer, "rb")) != NULL) + return fp; + } - /* TODO: search the library now */ + error("not found"); + return NULL; } static void