From 8046a3c1390f21ef56b8571c2cecc285f92f646c Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 24 Jan 2010 21:52:46 +0900 Subject: [PATCH] workaround for bug in fmemopen - open /dev/null instead of empty strings --- sexp.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sexp.c b/sexp.c index e0285afc..3549f5b7 100644 --- a/sexp.c +++ b/sexp.c @@ -889,9 +889,18 @@ sexp sexp_make_input_string_port (sexp ctx, sexp str) { sexp res; if (! sexp_stringp(str)) return sexp_type_exception(ctx, "open-input-string: not a string", str); - in = fmemopen(sexp_string_data(str), sexp_string_length(str), "r"); - res = sexp_make_input_port(ctx, in, SEXP_FALSE); - sexp_port_cookie(res) = str; /* for gc preservation */ + if (sexp_string_length(str) == 0) + in = fopen("/dev/null", "r"); + else + in = fmemopen(sexp_string_data(str), sexp_string_length(str), "r"); + if (in) { + res = sexp_make_input_port(ctx, in, SEXP_FALSE); + if (sexp_string_length(str) == 0) + sexp_port_name(res) = sexp_c_string(ctx, "/dev/null", -1); + sexp_port_cookie(res) = str; /* for gc preservation */ + } else { + res = sexp_user_exception(ctx, SEXP_FALSE, "couldn't open string", str); + } return res; }