minor linux portability for buffered image writes
authorJustin Wind <justin.wind@gmail.com>
Fri, 4 May 2012 21:45:28 +0000 (14:45 -0700)
committerJustin Wind <justin.wind@gmail.com>
Fri, 4 May 2012 21:45:28 +0000 (14:45 -0700)
Makefile
display.c

index 70445ff8f27955f86faadebf6200ff1805748700..fdd94d25be26003fc452bc190786d4c7328dce0b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,9 @@ ifeq ($(UNAME),Darwin)
 CPPFLAGS += -DHAVE_FUNOPEN
 endif
 ifeq ($(UNAME),Linux)
-CPPFLAGS += -DHAVE_FOPENCOOKIE -D_XOPEN_SOURCE=600
+# linux needs _GNU_SOURCE for fopencookie
+# linux needs _XOPEN_SOURCE=600 (provided by _GNU_SOURCE) for getopt and strdup
+CPPFLAGS += -DHAVE_FOPENCOOKIE -D_GNU_SOURCE
 endif
 
 
index b6488a52df7b85098e2a4ff4266930b363986102..9d59b290030f54b3eaa93fc903dc9df236ef96d5 100644 (file)
--- a/display.c
+++ b/display.c
@@ -115,7 +115,13 @@ void memstream_cookie_fini_(struct memstream_cookie_ *c) {
 }
 
 static
-int memstream_write_fn_(void *c, const char *buf, int size) {
+/* of course these can't be the same */
+#ifdef HAVE_FOPENCOOKIE
+ssize_t memstream_write_fn_(void *c, const char *buf, size_t size)
+#else /* HAVE_FOPENCOOKIE */
+int memstream_write_fn_(void *c, const char *buf, int size)
+#endif /* HAVE_FOPENCOOKIE */
+{
     struct memstream_cookie_ *cookie = c;
 
     while ((size_t)size + cookie->offset > cookie->allocated) {
@@ -227,7 +233,7 @@ void display_png_write_(struct dcpu16_display_ *d) {
 
 #ifdef HAVE_FOPENCOOKIE
     /* linux-style memory stream */
-    struct cookie_io_functions_t cookie_io_functions = {
+    cookie_io_functions_t cookie_io_functions = {
         .read = NULL,
         .write = memstream_write_fn_,
         .seek = NULL,