test: Use open_memstream() only if available On Solaris this function is not yet available.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/configure.ac b/configure.ac
index 1b7d182..78a4c97 100644
--- a/configure.ac
+++ b/configure.ac
@@ -296,6 +296,7 @@ AC_CHECK_FUNCS([\
getentropy \
getexecname \
getline \
+ open_memstream \
pstat_getproc \
sysconf \
])
diff --git a/test/fpurge.c b/test/fpurge.c
index 62d55da..784f32e 100644
--- a/test/fpurge.c
+++ b/test/fpurge.c
@@ -29,23 +29,36 @@
#include <string.h>
static int
-test_memstream(FILE *fp, size_t bufsz)
+test_memstream(void)
{
+ int rc = 0;
+#if HAVE_OPEN_MEMSTREAM
+ FILE *fp;
+ char *buf = NULL;
+ size_t bufsz = 0;
+
+ fp = open_memstream(&buf, &bufsz);
+ if (fp == NULL)
+ return 1;
+
fputs("World", fp);
if (fpurge(fp) < 0)
- return 1;
+ rc = 1;
fflush(fp);
if (bufsz != 0)
- return 1;
- return 0;
+ rc = 1;
+
+ fclose(fp);
+ free(buf);
+#endif
+
+ return rc;
}
int
main(int argc, char *argv[])
{
FILE *fp;
- char *buf = NULL;
- size_t bufsz = 0;
int rc;
if (fpurge(NULL) == 0)
@@ -54,13 +67,9 @@ main(int argc, char *argv[])
fp = fopen("/dev/zero", "r");
if (fpurge(fp) < 0)
return 1;
-
fclose(fp);
- fp = open_memstream(&buf, &bufsz);
- rc = test_memstream(fp, bufsz);
- fclose(fp);
- free(buf);
+ rc = test_memstream();
return rc;
}