Some image functions need to skip ofer certain file/stream regions.
The current solution is to skip these regions by reading them into an
allocated buffer. This makes the problem: Allocating the buffer.
Some images are very big so we have to allocate a large amount of
memory.

For files we could simply use fseek but sockets do not have such a
function so we have to read. But They have an internal buffer that is
there without being allocated additionally. So i implemented a new
function that skips the data without writeing it to a receiver buffer as
read functions do.

See diff attached

Please comment, if i hear enough '+' i will commit it.

regards
marcus


--------->>> mailto:[EMAIL PROTECTED] <<<------------
"We are animals among animals, all children of matter,
save that we are the more disarmed. But since, unlike animals,
we know that we must die, let us prepare for that moment
by enjoying the life that has been given us by chance and for chance."
                        Umberto Eco, The island of the day before
--------------->>> http://www.marcus-boerger.de <<<-------------------
diff -u -w -r1.33 ./fopen_wrappers.h
--- main/fopen_wrappers.h       28 Feb 2002 08:27:03 -0000      1.33
+++ ./main/fopen_wrappers.h     8 Mar 2002 23:21:22 -0000
@@ -49,6 +49,7 @@
 #define SOCK_FEOF(sock) php_sock_feof((sock))
 #define SOCK_FREAD(ptr, size, sock) php_sock_fread((ptr), (size), (sock))
 #define SOCK_FCLOSE(s) php_sock_close(s)
+#define SOCK_FSKIP(l, s) php_sock_fskip((l), (s))

 #define FP_FGETS(buf, len, sock, fp, issock) \
        ((issock)?SOCK_FGETS(buf, len, sock):fgets(buf, len, fp))
@@ -58,6 +59,8 @@
        ((issock)?SOCK_FEOF(sock):feof(fp))
 #define FP_FGETC(sock, fp, issock) \
        ((issock)?SOCK_FGETC(sock):fgetc(fp))
+#define FP_FSKIP(len, sock, fp, issock) \
+       ((issock)?SOCK_FSKIP(len,sock):fseek(fp,ftell(fp)+len,SEEK_SET))

 /* values for issock */
 #define IS_NOT_SOCKET  0
diff -u -w -r1.84 ./ext/standard/fsock.c
--- ext/standard/fsock.c        11 Dec 2001 15:30:31 -0000      1.84
+++ ./ext/standard/fsock.c      8 Mar 2002 23:21:22 -0000
@@ -596,8 +596,6 @@
        SOCK_FIND(sock, socket);
        return php_sock_fgets_internal(buf, maxlen, sock);
 }
-
-
 /* }}} */

 /*
@@ -742,6 +740,26 @@
        return ret;
 }

+/* }}} */
+
+/* {{{ php_sock_fskip() */
+/* Skip an amount of bytes in socket
+ */
+PHPAPI int php_sock_fskip(size_t len, int socket)
+{
+       size_t ret = 0;
+       SOCK_FIND_AND_READ_MAX(len);
+
+       if(len < 0)
+               return ret;
+
+       ret = MIN(TOREAD(sock), len);
+       if(ret) {
+               sock->readpos += ret;
+       }
+
+       return !ret; /* 0 if success: same behaviour as fseek */
+}
 /* }}} */

 /* {{{ module start/shutdown functions */
diff -u -w -r1.41 ext/standard/fsock.h
--- ext/standard/fsock.h        28 Feb 2002 08:26:45 -0000      1.41
+++ ./ext/standard/fsock.h      8 Mar 2002 23:21:22 -0000
@@ -63,6 +63,7 @@
 PHPAPI int php_lookup_hostname(const char *addr, struct in_addr *in);
 PHPAPI char *php_sock_fgets(char *buf, size_t maxlen, int socket);
 PHPAPI size_t php_sock_fread(char *buf, size_t maxlen, int socket);
+PHPAPI int php_sock_fskip(size_t len, int socket);
 PHPAPI int php_sock_feof(int socket);
 PHPAPI int php_sock_fgetc(int socket);
 PHPAPI int php_is_persistent_sock(int);


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to