Back to index

php5  5.3.10
Classes | Defines | Functions | Variables
zlib_fopen_wrapper.c File Reference
#include "php.h"
#include "php_zlib.h"
#include "fopen_wrappers.h"

Go to the source code of this file.

Classes

struct  php_gz_stream_data_t

Defines

#define _GNU_SOURCE

Functions

static size_t php_gziop_read (php_stream *stream, char *buf, size_t count TSRMLS_DC)
static size_t php_gziop_write (php_stream *stream, const char *buf, size_t count TSRMLS_DC)
static int php_gziop_seek (php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
static int php_gziop_close (php_stream *stream, int close_handle TSRMLS_DC)
static int php_gziop_flush (php_stream *stream TSRMLS_DC)
php_stream * php_stream_gzopen (php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)

Variables

static php_stream_ops php_stream_gzio_ops
static php_stream_wrapper_ops gzip_stream_wops
php_stream_wrapper php_stream_gzip_wrapper

Class Documentation

struct php_gz_stream_data_t

Definition at line 28 of file zlib_fopen_wrapper.c.

Class Members
gzFile gz_file
php_stream * stream

Define Documentation

#define _GNU_SOURCE

Definition at line 22 of file zlib_fopen_wrapper.c.


Function Documentation

static int php_gziop_close ( php_stream *  stream,
int close_handle  TSRMLS_DC 
) [static]

Definition at line 72 of file zlib_fopen_wrapper.c.

{
       struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;
       int ret = EOF;
       
       if (close_handle) {
              if (self->gz_file) {
                     ret = gzclose(self->gz_file);
                     self->gz_file = NULL;
              }
              if (self->stream) {
                     php_stream_close(self->stream);
                     self->stream = NULL;
              }
       }
       efree(self);

       return ret;
}
static int php_gziop_flush ( php_stream *stream  TSRMLS_DC) [static]

Definition at line 92 of file zlib_fopen_wrapper.c.

{
       struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;

       return gzflush(self->gz_file, Z_SYNC_FLUSH);
}
static size_t php_gziop_read ( php_stream *  stream,
char *  buf,
size_t count  TSRMLS_DC 
) [static]

Definition at line 33 of file zlib_fopen_wrapper.c.

{
       struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;
       int read;
       
       read = gzread(self->gz_file, buf, count);
       
       if (gzeof(self->gz_file)) {
              stream->eof = 1;
       }
              
       return (read < 0) ? 0 : read;
}

Here is the call graph for this function:

static int php_gziop_seek ( php_stream *  stream,
off_t  offset,
int  whence,
off_t *newoffs  TSRMLS_DC 
) [static]

Definition at line 57 of file zlib_fopen_wrapper.c.

{
       struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;

       assert(self != NULL);

       if (whence == SEEK_END) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "SEEK_END is not supported");
              return -1;
       }
       *newoffs = gzseek(self->gz_file, offset, whence);

       return (*newoffs < 0) ? -1 : 0;
}
static size_t php_gziop_write ( php_stream *  stream,
const char *  buf,
size_t count  TSRMLS_DC 
) [static]

Definition at line 47 of file zlib_fopen_wrapper.c.

{
       struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;
       int wrote;

       wrote = gzwrite(self->gz_file, (char *) buf, count);

       return (wrote < 0) ? 0 : wrote;
}
php_stream* php_stream_gzopen ( php_stream_wrapper *  wrapper,
char *  path,
char *  mode,
int  options,
char **  opened_path,
php_stream_context *context STREAMS_DC  TSRMLS_DC 
)

Definition at line 109 of file zlib_fopen_wrapper.c.

{
       struct php_gz_stream_data_t *self = {0};
       php_stream *stream = NULL, *innerstream = NULL;

       /* sanity check the stream: it can be either read-only or write-only */
       if (strchr(mode, '+')) {
              if (options & REPORT_ERRORS) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot open a zlib stream for reading and writing at the same time!");
              }
              return NULL;
       }
       
       self = emalloc(sizeof(*self));

       if (strncasecmp("compress.zlib://", path, 16) == 0) {
              path += 16;
       } else if (strncasecmp("zlib:", path, 5) == 0) {
              path += 5;
       }
       
       innerstream = php_stream_open_wrapper_ex(path, mode, STREAM_MUST_SEEK | options | STREAM_WILL_CAST, opened_path, context);
       
       if (innerstream) {
              int fd;

              if (SUCCESS == php_stream_cast(innerstream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) {
                     self->gz_file = gzdopen(dup(fd), mode);
                     self->stream = innerstream;
                     if (self->gz_file)   {
                            stream = php_stream_alloc_rel(&php_stream_gzio_ops, self, 0, mode);
                            if (stream) {
                                   stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
                                   return stream;
                            }
                            gzclose(self->gz_file);
                     }
                     if (options & REPORT_ERRORS) {
                            php_error_docref(NULL TSRMLS_CC, E_WARNING, "gzopen failed");
                     }
              } else if (innerstream) {
                     php_stream_close(innerstream);
              }
       }

       if (stream) {
              php_stream_close(stream);
       }
       
       if (self) {
              efree(self);
       }
       
       return NULL;
}

Here is the caller graph for this function:


Variable Documentation

Initial value:
 {
       php_stream_gzopen,
       NULL, 
       NULL, 
       NULL, 
       NULL, 
       "ZLIB",
       NULL, 
       NULL, 
       NULL, 
       NULL  
}

Definition at line 166 of file zlib_fopen_wrapper.c.

Initial value:

Definition at line 99 of file zlib_fopen_wrapper.c.

php_stream_wrapper php_stream_gzip_wrapper
Initial value:

Definition at line 179 of file zlib_fopen_wrapper.c.