Re: memory streams

From: Date: Sat, 16 Mar 2002 18:50:52 +0000
Subject: Re: memory streams
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-81355@lists.php.net to get a copy of this message
At 18:58 16.03.2002, Marcus Boerger wrote:
At the moment i am working at memory-streams.... If have the following problem left: I must extend struct _php_stream_ops with ftell.... by the way php_stream_tell is wrong because it relies on seek and that does return either 0 on success or an erroecode....
The following patch adds ftell as a stream function and changes the default implementation. diff -u -w -r1.13 php_streams.h
--- main/php_streams.h  16 Mar 2002 14:39:51 -0000      1.13
+++ main/php_streams.h 16 Mar 2002 18:48:47 -0000 @@ -47,6 +47,7 @@
        int    (*flush)(php_stream *stream);
        /* these are optional */
        int    (*seek)(php_stream *stream, off_t offset, int whence);
+       long   (*tell)(php_stream *stream);
        char *(*gets)(php_stream *stream, char *buf, size_t size);
        int (*cast)(php_stream *stream, int castas, void **ret);
        const char *label; /* label for this ops structure */
@@ -90,7 +91,7 @@ PHPAPI int php_stream_seek(php_stream *stream, off_t offset, int whence);
 #define php_stream_rewind(stream)      php_stream_seek(stream, 0L, SEEK_SET)
-PHPAPI off_t php_stream_tell(php_stream *stream); +PHPAPI long php_stream_tell(php_stream *stream); PHPAPI size_t php_stream_read(php_stream *stream, char *buf, size_t count); PHPAPI size_t php_stream_write(php_stream *stream, const char *buf, size_t count); #define php_stream_write_string(stream, str) php_stream_write(stream, str, strlen(str)) diff -u -w -r1.21 streams.c
--- main/streams.c      16 Mar 2002 16:06:18 -0000      1.21
+++ main/streams.c      16 Mar 2002 18:48:48 -0000
@@ -197,12 +197,12 @@
        return stream->ops->write(stream, buf, count);
} -PHPAPI off_t php_stream_tell(php_stream *stream) +PHPAPI long php_stream_tell(php_stream *stream) {
        off_t ret = -1;
-       if (stream->ops->seek) {
-               ret = stream->ops->seek(stream, 0, SEEK_CUR);
+       if (stream->ops->tell) {
+               ret = stream->ops->tell(stream);
        }
        return ret;
} @@ -539,6 +539,15 @@
        return fseek(data->file, offset, whence);
} +static long php_stdio_tell(php_stream *stream) +{
+       php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
+
+       assert(data != NULL);
+
+       return ftell(data->file);
+} + static char *php_stdiop_gets(php_stream *stream, char *buf, size_t size) {
        php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
@@ -583,7 +592,8 @@ php_stream_ops php_stream_stdio_ops = {
        php_stdiop_write, php_stdiop_read,
-       php_stdiop_close, php_stdiop_flush, php_stdiop_seek,
+       php_stdiop_close, php_stdiop_flush,
+       php_stdiop_seek, php_stdio_tell,
        php_stdiop_gets, php_stdiop_cast,
        "STDIO"
};
regards marcus --------->>> mailto:marcus.boerger@post.rwth-aachen.de <<<------------
        I don't want to start any blashphemous rumours
        but i think that god's got a sick sense of humor
        and when i die i expect to find him laughing.
                                             Depeche Mode
--------------->>> http://www.marcus-boerger.de <<<------------------- -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.dev (#81355) next »