# HG changeset patch # User Mychaela Falconia # Date 1613854824 0 # Node ID 94d87d05f6c59d7104be56dceb3558d1bc5c5f72 # Parent 01aed8d0685aeac31629c269a3733a5a9341d9da libcommon: initial support for file search diff -r 01aed8d0685a -r 94d87d05f6c5 libcommon/Makefile --- a/libcommon/Makefile Sat Feb 20 20:10:18 2021 +0000 +++ b/libcommon/Makefile Sat Feb 20 21:00:24 2021 +0000 @@ -2,9 +2,9 @@ CFLAGS= -O2 -I/usr/include/PCSC OBJS= alpha_decode.o alpha_fromfile.o alpha_valid.o apdu.o apducmd.o atr.o \ cardconnect.o chkblank.o decimal_str.o dumpdirfunc.o exit.o \ - globalopts.o gsm7_decode.o gsm7_encode.o gsm7_encode_table.o \ - gsm7_unpack.o hexdump.o hexread.o hexstr.o names.o number_decode.o \ - number_encode.o pinentry.o plmncodes.o revnibbles.o + filesearch.o globalopts.o gsm7_decode.o gsm7_encode.o \ + gsm7_encode_table.o gsm7_unpack.o hexdump.o hexread.o hexstr.o names.o \ + number_decode.o number_encode.o pinentry.o plmncodes.o revnibbles.o LIB= libcommon.a all: ${LIB} diff -r 01aed8d0685a -r 94d87d05f6c5 libcommon/filesearch.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/filesearch.c Sat Feb 20 21:00:24 2021 +0000 @@ -0,0 +1,27 @@ +/* + * This module implements the function that searches for files + * in a dedicated directory for SIM programming scripts. + */ + +#include +#include +#include + +static char script_install_dir[] = "/opt/freecalypso/sim-scripts"; + +FILE * +open_script_input_file(req_filename) + char *req_filename; +{ + char pathbuf[256]; + FILE *f; + + if (!index(req_filename, '/') && strlen(req_filename) < 128) { + sprintf(pathbuf, "%s/%s", script_install_dir, req_filename); + f = fopen(pathbuf, "r"); + if (f) + return f; + } + f = fopen(req_filename, "r"); + return f; +} diff -r 01aed8d0685a -r 94d87d05f6c5 libcommon/hexread.c --- a/libcommon/hexread.c Sat Feb 20 20:10:18 2021 +0000 +++ b/libcommon/hexread.c Sat Feb 20 21:00:24 2021 +0000 @@ -5,11 +5,11 @@ #include #include -#include -#include #include #include +extern FILE *open_script_input_file(); + read_hex_data_file(filename, databuf) char *filename; u_char *databuf; @@ -18,7 +18,7 @@ unsigned count; int c, c2; - inf = fopen(filename, "r"); + inf = open_script_input_file(filename); if (!inf) { perror(filename); return(-1);