summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <justus@g10code.com>2017-07-18 16:15:45 +0200
committerJustus Winter <justus@g10code.com>2017-07-18 16:15:45 +0200
commitc4230af0e62d7c8812eaedf4e6451a6288ff5769 (patch)
treee7a778c4d07246ac00872e51a09ced9ebe1319c7
parenta4dbace8c1d771bed5783aadf87a8075454e5a35 (diff)
downloadlibgpg-error-c4230af0e62d7c8812eaedf4e6451a6288ff5769.tar.gz
gpgscm,w32: Fix testing for absolute paths.
* tests/gpgscm/main.c (path_absolute_p): New function. (load): Use new function. Signed-off-by: Justus Winter <justus@g10code.com>
-rw-r--r--main.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/main.c b/main.c
index 4dae365..5540ac3 100644
--- a/main.c
+++ b/main.c
@@ -124,6 +124,19 @@ my_strusage( int level )
}
+
+static int
+path_absolute_p (const char *p)
+{
+#if _WIN32
+ return ((strlen (p) > 2 && p[1] == ':' && (p[2] == '\\' || p[2] == '/'))
+ || p[0] == '\\' || p[0] == '/');
+#else
+ return p[0] == '/';
+#endif
+}
+
+
/* Load the Scheme program from FILE_NAME. If FILE_NAME is not an
absolute path, and LOOKUP_IN_PATH is given, then it is qualified
with the values in scmpath until the file is found. */
@@ -139,9 +152,9 @@ load (scheme *sc, char *file_name,
FILE *h = NULL;
use_path =
- lookup_in_path && ! (file_name[0] == '/' || scmpath_len == 0);
+ lookup_in_path && ! (path_absolute_p (file_name) || scmpath_len == 0);
- if (file_name[0] == '/' || lookup_in_cwd || scmpath_len == 0)
+ if (path_absolute_p (file_name) || lookup_in_cwd || scmpath_len == 0)
{
h = fopen (file_name, "r");
if (! h)