]> granicus.if.org Git - php/commitdiff
Use write(2), if we can successfully write to stdout.
authorSascha Schumann <sas@php.net>
Sat, 19 May 2001 14:30:33 +0000 (14:30 +0000)
committerSascha Schumann <sas@php.net>
Sat, 19 May 2001 14:30:33 +0000 (14:30 +0000)
sapi/cgi/cgi_main.c
sapi/cgi/config.m4

index dc1cfe9191270cd0316d65ae40a5f26b408324b7..cf482d0a6753582e68fb99fec551b9f5f747deb9 100644 (file)
@@ -87,6 +87,26 @@ static int _print_module_info ( zend_module_entry *module, void *arg ) {
        return 0;
 }
 
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
+
+static inline size_t sapi_cgibin_single_write(const char *str, uint str_length)
+{
+#ifdef PHP_WRITE_STDOUT
+       long ret;
+
+       ret = write(STDOUT_FILENO, str, str_length);
+       if (ret <= 0) return 0;
+       return ret;
+#else
+       size_t ret;
+
+       ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
+       return ret;
+#endif
+}
+
 static int sapi_cgibin_ub_write(const char *str, uint str_length)
 {
        const char *ptr = str;
@@ -95,7 +115,7 @@ static int sapi_cgibin_ub_write(const char *str, uint str_length)
 
        while (remaining > 0)
        {
-               ret = fwrite(ptr, 1, MIN(remaining, 16384), stdout);
+               ret = sapi_cgibin_single_write(ptr, remaining);
                if (!ret) {
                        php_handle_aborted_connection();
                }
index 9c1ea3acc5ce18e5ed4e686ad9ffb73635511e70..7a0007e572ddb80d746723e32358677a7c21132f 100644 (file)
@@ -1,6 +1,36 @@
+AC_DEFUN(PHP_TEST_WRITE_STDOUT,[
+  AC_CACHE_CHECK(whether writing to stdout works,ac_cv_write_stdout,[
+    AC_TRY_RUN([
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#define TEXT "This is the test message -- "
+        
+main()
+{
+  int n;
+
+  n = write(1, TEXT, sizeof(TEXT)-1);
+  return (!(n == sizeof(TEXT)-1));
+}
+    ],[
+      ac_cv_write_stdout=yes
+    ],[
+      ac_cv_write_stdout=no
+    ],[
+      ac_cv_write_stdout=no
+    ])
+  ])
+  if test "$ac_cv_write_stdout" = "yes"; then
+    AC_DEFINE(PHP_WRITE_STDOUT, 1, [whether write(2) works])
+  fi
+])
 
 if test "$PHP_SAPI" = "cgi"; then
 
+  PHP_TEST_WRITE_STDOUT
+
   PHP_ARG_ENABLE(force-cgi-redirect,whether to force Apache CGI redirect,
 [  --enable-force-cgi-redirect
                           Enable the security check for internal server