cvs: php4 /sapi/cgi cgi_main.c config.m4
| From: | Sascha Schumann | Date: | Sat, 19 May 2001 14:30:33 +0000 |
| Subject: | cvs: php4 /sapi/cgi cgi_main.c config.m4 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-5842@lists.php.net to get a copy of this message | ||
sas Sat May 19 07:30:33 2001 EDT
Modified files:
/php4/sapi/cgi cgi_main.c config.m4
Log:
Use write(2), if we can successfully write to stdout.
Index: php4/sapi/cgi/cgi_main.c
diff -u php4/sapi/cgi/cgi_main.c:1.109 php4/sapi/cgi/cgi_main.c:1.110
--- php4/sapi/cgi/cgi_main.c:1.109 Fri May 18 07:40:02 2001
+++ php4/sapi/cgi/cgi_main.c Sat May 19 07:30:32 2001
@@ -87,6 +87,26 @@
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 @@
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: php4/sapi/cgi/config.m4
diff -u php4/sapi/cgi/config.m4:1.9 php4/sapi/cgi/config.m4:1.10
--- php4/sapi/cgi/config.m4:1.9 Mon Apr 9 08:47:19 2001
+++ php4/sapi/cgi/config.m4 Sat May 19 07:30:33 2001
@@ -1,5 +1,35 @@
+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