cvs: php4 /main streams.c
| From: | Wez Furlong | Date: | Sun, 25 Aug 2002 11:23:20 +0000 |
| Subject: | cvs: php4 /main streams.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-13659@lists.php.net to get a copy of this message | ||
wez Sun Aug 25 07:23:20 2002 EDT
Modified files:
/php4/main streams.c
Log:
Hopefully really fix #18022 this time.
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.71 php4/main/streams.c:1.72
--- php4/main/streams.c:1.71 Sun Aug 25 07:02:05 2002
+++ php4/main/streams.c Sun Aug 25 07:23:19 2002
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.71 2002/08/25 11:02:05 wez Exp $ */
+/* $Id: streams.c,v 1.72 2002/08/25 11:23:19 wez Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -703,7 +703,8 @@
typedef struct {
FILE *file;
- int is_pipe; /* use pclose */
+ int is_process_pipe; /* use pclose instead of fclose */
+ int is_pipe; /* don't try and seek */
#if HAVE_FLUSHIO
char last_op;
#endif
@@ -751,10 +752,24 @@
PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC)
{
php_stdio_stream_data *self;
-
+#ifdef S_ISFIFO
+ int fd;
+#endif
+
self = emalloc_rel_orig(sizeof(*self));
self->file = file;
self->is_pipe = 0;
+ self->is_process_pipe = 0;
+
+#ifdef S_ISFIFO
+ /* detect if this is a pipe */
+ fd = fileno(file);
+ if (fd >= 0) {
+ struct stat sb;
+ self->is_pipe = (fstat(fd, &sb) == 0 && S_ISFIFO(sb.st_mode)) ? 1 : 0;
+ }
+#endif
+
return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
}
@@ -765,8 +780,10 @@
self = emalloc_rel_orig(sizeof(*self));
self->file = file;
self->is_pipe = 1;
+ self->is_process_pipe = 1;
return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
}
+
static size_t php_stdiop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
{
php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
@@ -814,7 +831,7 @@
assert(data != NULL);
if (close_handle) {
- if (data->is_pipe) {
+ if (data->is_process_pipe) {
ret = pclose(data->file);
} else {
ret = fclose(data->file);
@@ -844,6 +861,11 @@
assert(data != NULL);
+ if (data->is_pipe) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot seek on a pipe");
+ return -1;
+ }
+
if (offset == 0 && whence == SEEK_CUR)
return ftell(data->file);