diff 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
line wrap: on
line diff
--- /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 <stdio.h>
+#include <string.h>
+#include <strings.h>
+
+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;
+}