sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 1106076d535f8c9e93694a0343e5508865df9a4b
parent d898b61ed22e7d7ced081cbf2f646c82cbf88f00
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Fri, 12 Dec 2025 12:14:21 +0100

bc: Simplify loading internal library

Testing can be done using directly the path to the bc.library
file, and get rid of the ugly function that we had to build
dynamically the path to the library.

Diffstat:
Mbc.y | 37+------------------------------------
1 file changed, 1 insertion(+), 36 deletions(-)

diff --git a/bc.y b/bc.y @@ -846,41 +846,6 @@ bc(char *fname) } static void -loadlib(void) -{ - int r; - size_t len; - char bin[FILENAME_MAX], fname[FILENAME_MAX]; - static char bclib[] = "bc.library"; - - /* - * try first to load the library from the same directory than - * the executable, because that can makes easier the tests - * because it does not require to install to test the last version - */ - len = strlen(argv0); - if (len >= FILENAME_MAX) - goto share; - memcpy(bin, argv0, len + 1); - - r = snprintf(fname, sizeof(fname), "%s/%s", dirname(bin), bclib); - if (r < 0 || r >= sizeof(fname)) - goto share; - - if (access(fname, F_OK) < 0) - goto share; - - bc(fname); - return; - -share: - r = snprintf(fname, sizeof(fname), "%s/share/misc/%s", PREFIX, bclib); - if (r < 0 || r >= sizeof(fname)) - eprintf("invalid path name for bc.library\n"); - bc(fname); -} - -static void usage(void) { eprintf("usage: %s [-cdls]\n", argv0); @@ -916,7 +881,7 @@ main(int argc, char *argv[]) if (!cflag) spawn(); if (lflag) - loadlib(); + bc(PREFIX "/bc.library"); while (*argv) bc(*argv++);