]> saetta.ns0.it Git - libzakcgi/commitdiff
Use of GIO for ZakCgi::get_stdin.
authorAndrea Zagli <azagli@libero.it>
Sat, 20 Jun 2015 11:53:01 +0000 (13:53 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 20 Jun 2015 11:53:01 +0000 (13:53 +0200)
configure.ac
src/main.c

index 3a2b52f9edbd57a85628a9e76763c2962758f581..df737bfe70755e6667eb84d0446f3fa23ce5e441 100644 (file)
@@ -31,7 +31,8 @@ AC_PROG_RANLIB
 
 # Checks for libraries.
 PKG_CHECK_MODULES(ZAKCGI, [glib-2.0 >= 2.36
-                           gobject-2.0 >= 2.36])
+                           gobject-2.0 >= 2.36
+                           gio-unix-2.0 >= 2.36])
 
 AC_SUBST(ZAKCGI_CFLAGS)
 AC_SUBST(ZAKCGI_LIBS)
index 7732373665067b435805609b55e9789e356b0322..491ac4eb2d6680aa41c91e905c40ee0cfd281118 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <stdio.h>
 
+#include <gio/gunixinputstream.h>
+
 #include "main.h"
 
 static void zak_cgi_main_class_init (ZakCgiMainClass *class);
@@ -212,16 +214,31 @@ gchar
 {
        gchar *ret;
 
+       const gchar *env;
        guint l;
 
+       GError *error;
+       GInputStream *istream;
+
        ret = NULL;
 
-       l = strtol (g_getenv ("CONTENT_LENGTH"), NULL, 10);
-       if (l > 0)
+       env = g_getenv ("CONTENT_LENGTH");
+       if (env != NULL)
                {
-                       ret = g_malloc (l + 1);
-                       fread (ret, l, 1, stdin);
-                       ret[l] = '\0';
+                       l = strtol (env, NULL, 10);
+                       if (l > 0)
+                               {
+                                       error = NULL;
+
+                                       ret = g_malloc0 (l + 1);
+                                       istream = g_unix_input_stream_new (0, TRUE);
+
+                                       g_input_stream_read (istream,
+                                                            ret,
+                                                            l,
+                                                            NULL,
+                                                            &error);
+                               }
                }
 
        return ret;