@@ -242,35 +242,36 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC)
242
242
return php_stream_fopen_temporary_file (NULL , "php" , NULL );
243
243
}
244
244
245
+ static void detect_is_pipe (php_stdio_stream_data * self ) {
246
+ #if defined(S_ISFIFO ) && defined(S_ISCHR )
247
+ if (self -> fd >= 0 && do_fstat (self , 0 ) == 0 ) {
248
+ self -> is_pipe = S_ISFIFO (self -> sb .st_mode ) || S_ISCHR (self -> sb .st_mode );
249
+ }
250
+ #elif defined(PHP_WIN32 )
251
+ zend_uintptr_t handle = _get_osfhandle (self -> fd );
252
+
253
+ if (handle != (zend_uintptr_t )INVALID_HANDLE_VALUE ) {
254
+ self -> is_pipe = GetFileType ((HANDLE )handle ) == FILE_TYPE_PIPE ;
255
+ }
256
+ #endif
257
+ }
258
+
245
259
PHPAPI php_stream * _php_stream_fopen_from_fd (int fd , const char * mode , const char * persistent_id STREAMS_DC )
246
260
{
247
261
php_stream * stream = php_stream_fopen_from_fd_int_rel (fd , mode , persistent_id );
248
262
249
263
if (stream ) {
250
264
php_stdio_stream_data * self = (php_stdio_stream_data * )stream -> abstract ;
251
265
252
- #ifdef S_ISFIFO
253
- /* detect if this is a pipe */
254
- if (self -> fd >= 0 ) {
255
- self -> is_pipe = (do_fstat (self , 0 ) == 0 && S_ISFIFO (self -> sb .st_mode )) ? 1 : 0 ;
256
- }
257
- #elif defined(PHP_WIN32 )
258
- {
259
- zend_uintptr_t handle = _get_osfhandle (self -> fd );
260
-
261
- if (handle != (zend_uintptr_t )INVALID_HANDLE_VALUE ) {
262
- self -> is_pipe = GetFileType ((HANDLE )handle ) == FILE_TYPE_PIPE ;
263
- }
264
- }
265
- #endif
266
-
266
+ detect_is_pipe (self );
267
267
if (self -> is_pipe ) {
268
268
stream -> flags |= PHP_STREAM_FLAG_NO_SEEK ;
269
+ stream -> position = -1 ;
269
270
} else {
270
271
stream -> position = zend_lseek (self -> fd , 0 , SEEK_CUR );
271
272
#ifdef ESPIPE
273
+ /* FIXME: Is this code still needed? */
272
274
if (stream -> position == (zend_off_t )- 1 && errno == ESPIPE ) {
273
- stream -> position = 0 ;
274
275
stream -> flags |= PHP_STREAM_FLAG_NO_SEEK ;
275
276
self -> is_pipe = 1 ;
276
277
}
@@ -288,23 +289,10 @@ PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STRE
288
289
if (stream ) {
289
290
php_stdio_stream_data * self = (php_stdio_stream_data * )stream -> abstract ;
290
291
291
- #ifdef S_ISFIFO
292
- /* detect if this is a pipe */
293
- if (self -> fd >= 0 ) {
294
- self -> is_pipe = (do_fstat (self , 0 ) == 0 && S_ISFIFO (self -> sb .st_mode )) ? 1 : 0 ;
295
- }
296
- #elif defined(PHP_WIN32 )
297
- {
298
- zend_uintptr_t handle = _get_osfhandle (self -> fd );
299
-
300
- if (handle != (zend_uintptr_t )INVALID_HANDLE_VALUE ) {
301
- self -> is_pipe = GetFileType ((HANDLE )handle ) == FILE_TYPE_PIPE ;
302
- }
303
- }
304
- #endif
305
-
292
+ detect_is_pipe (self );
306
293
if (self -> is_pipe ) {
307
294
stream -> flags |= PHP_STREAM_FLAG_NO_SEEK ;
295
+ stream -> position = -1 ;
308
296
} else {
309
297
stream -> position = zend_ftell (file );
310
298
}
0 commit comments