comparison libcommon/filesearch.c @ 129:94d87d05f6c5

libcommon: initial support for file search
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 Feb 2021 21:00:24 +0000
parents
children
comparison
equal deleted inserted replaced
128:01aed8d0685a 129:94d87d05f6c5
1 /*
2 * This module implements the function that searches for files
3 * in a dedicated directory for SIM programming scripts.
4 */
5
6 #include <stdio.h>
7 #include <string.h>
8 #include <strings.h>
9
10 static char script_install_dir[] = "/opt/freecalypso/sim-scripts";
11
12 FILE *
13 open_script_input_file(req_filename)
14 char *req_filename;
15 {
16 char pathbuf[256];
17 FILE *f;
18
19 if (!index(req_filename, '/') && strlen(req_filename) < 128) {
20 sprintf(pathbuf, "%s/%s", script_install_dir, req_filename);
21 f = fopen(pathbuf, "r");
22 if (f)
23 return f;
24 }
25 f = fopen(req_filename, "r");
26 return f;
27 }