+
+SCM_DEFINE (scm_search_path, "search-path", 2, 0, 1,
+ (SCM path, SCM filename, SCM rest),
+ "Search @var{path} for a directory containing a file named\n"
+ "@var{filename}. The file must be readable, and not a directory.\n"
+ "If we find one, return its full filename; otherwise, return\n"
+ "@code{#f}. If @var{filename} is absolute, return it unchanged.\n"
+ "If given, @var{extensions} is a list of strings; for each\n"
+ "directory in @var{path}, we search for @var{filename}\n"
+ "concatenated with each @var{extension}.")
+#define FUNC_NAME s_scm_search_path
+{
+ SCM extensions, require_exts;
+ struct stat stat_buf;
+
+ if (SCM_UNBNDP (rest) || scm_is_null (rest))
+ {
+ /* Called either by Scheme code that didn't provide the optional
+ arguments, or C code that used the Guile 1.8 signature (2 required,
+ 1 optional arg) and passed '() or nothing as the EXTENSIONS
+ argument. */
+ extensions = SCM_EOL;
+ require_exts = SCM_UNDEFINED;
+ }
+ else
+ {
+ if (scm_is_null (SCM_CAR (rest)) || scm_is_pair (SCM_CAR (rest)))
+ {
+ /* Called by Scheme code written for 1.9. */
+ extensions = SCM_CAR (rest);
+ if (scm_is_null (SCM_CDR (rest)))
+ require_exts = SCM_UNDEFINED;
+ else
+ {
+ require_exts = SCM_CADR (rest);
+ if (SCM_UNLIKELY (!scm_is_null (SCM_CDDR (rest))))
+ scm_wrong_num_args (scm_from_locale_string (FUNC_NAME));
+ }
+ }
+ else
+ {
+ /* Called by C code that uses the 1.8 signature, i.e., which
+ expects the 3rd argument to be EXTENSIONS. */
+ extensions = rest;
+ require_exts = SCM_UNDEFINED;
+ }
+ }
+
+ if (SCM_UNBNDP (extensions))
+ extensions = SCM_EOL;
+
+ if (SCM_UNBNDP (require_exts))
+ require_exts = SCM_BOOL_F;
+
+ return search_path (path, filename, extensions, require_exts, &stat_buf);
+}