]> granicus.if.org Git - php/commitdiff
some tweaks for seek/read used in image.c (thanks Marcus)
authorWez Furlong <wez@php.net>
Sat, 16 Mar 2002 02:39:39 +0000 (02:39 +0000)
committerWez Furlong <wez@php.net>
Sat, 16 Mar 2002 02:39:39 +0000 (02:39 +0000)
main/streams.c

index 32905e6f182cb8979a4734bf3328243d5590ce30..5157fe9ce76f00a1f123ffb999005741d4488226 100755 (executable)
@@ -132,7 +132,7 @@ PHPAPI int php_stream_getc(php_stream *stream)
        char buf;
 
        if (php_stream_read(stream, &buf, 1) > 0) {
-               return buf;
+               return buf & 0xff;
        }
        return EOF;
 }
@@ -210,10 +210,15 @@ PHPAPI int php_stream_seek(php_stream *stream, off_t offset, int whence)
 
        /* emulate forward moving seeks with reads */
        if (whence == SEEK_CUR && offset > 0) {
-               while(offset-- > 0) {
-                       if (php_stream_getc(stream) == EOF) {
+               char tmp[1024];
+               while(offset >= sizeof(tmp)) {
+                       if (php_stream_read(stream, tmp, sizeof(tmp)) == 0)
+                               return -1;
+                       offset -= sizeof(tmp);
+               }
+               if (offset)     {
+                       if (php_stream_read(stream, tmp, offset) == 0)
                                return -1;
-                       }
                }
                return 0;
        }