diff --git a/src/buffer.hpp b/src/buffer.hpp index eda59c5f6..2900bdc1b 100644 --- a/src/buffer.hpp +++ b/src/buffer.hpp @@ -140,11 +140,30 @@ static inline bool buf_eql_str(Buf *buf, const char *str) { return buf_eql_mem(buf, str, strlen(str)); } -static inline bool buf_starts_with_buf(Buf *buf, Buf *sub) { - if (buf_len(buf) < buf_len(sub)) { +static inline bool buf_starts_with_mem(Buf *buf, const char *mem, int mem_len) { + if (buf_len(buf) < mem_len) { return false; } - return buf_eql_mem(sub, buf_ptr(buf), buf_len(sub)); + return memcmp(buf_ptr(buf), mem, mem_len) == 0; +} + +static inline bool buf_starts_with_buf(Buf *buf, Buf *sub) { + return buf_starts_with_mem(buf, buf_ptr(sub), buf_len(sub)); +} + +static inline bool buf_starts_with_str(Buf *buf, const char *str) { + return buf_starts_with_mem(buf, str, strlen(str)); +} + +static inline bool buf_ends_with_mem(Buf *buf, const char *mem, int mem_len) { + if (buf_len(buf) < mem_len) { + return false; + } + return memcmp(buf_ptr(buf) + buf_len(buf) - mem_len, mem, mem_len) == 0; +} + +static inline bool buf_ends_with_str(Buf *buf, const char *str) { + return buf_ends_with_mem(buf, str, strlen(str)); } bool buf_eql_buf(Buf *buf, Buf *other); diff --git a/src/link.cpp b/src/link.cpp index d58ecd0a1..c7c4b2bb6 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -238,7 +238,14 @@ static void construct_linker_job_linux(LinkJob *lj) { for (int i = 0; i < g->link_libs.length; i += 1) { Buf *link_lib = g->link_libs.at(i); - Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib)); + Buf *arg; + if (buf_starts_with_str(link_lib, "/") || buf_ends_with_str(link_lib, ".a") || + buf_ends_with_str(link_lib, ".so")) + { + arg = link_lib; + } else { + arg = buf_sprintf("-l%s", buf_ptr(link_lib)); + } lj->args.append(buf_ptr(arg)); }