Commit:    cf987063765e5bdcf8fb9432ef85cdd1ca8a56d9
Author:    Anatoliy Belsky <a...@php.net>         Mon, 2 Apr 2012 17:22:46 +0200
Committer: Johannes Schlüter <johan...@php.net>      Thu, 12 Apr 2012 11:12:10 
+0200
Parents:   56771b86481c7d5fdd92b1e8e1a29b662513f904
Branches:  PHP-5.3.11

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=cf987063765e5bdcf8fb9432ef85cdd1ca8a56d9

Log:
Bug #61566 Fileinfo ext\fileinfo\tests\finfo_file_002.phpt fails

This patch fixes the failure caused by the
posix lseek and read versions under windows in cdf_read() .
Additionally all the occurences of lseek and read
was replaced by _lseek and _reed for windows.

Bugs:
https://bugs.php.net/61566

Changed paths:
  M  ext/fileinfo/libmagic/cdf.c
  M  ext/fileinfo/libmagic/compress.c
  M  ext/fileinfo/libmagic/file.h
  M  ext/fileinfo/libmagic/readelf.c
  M  ext/fileinfo/tests/finfo_open_001.phpt
  M  ext/fileinfo/tests/finfo_open_error.phpt

diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c
index 1f0f63b..7efa43e 100644
--- a/ext/fileinfo/libmagic/cdf.c
+++ b/ext/fileinfo/libmagic/cdf.c
@@ -306,10 +306,10 @@ cdf_read(const cdf_info_t *info, off_t off, void *buf, 
size_t len)
        if (info->i_fd == -1)
                return -1;
 
-       if (lseek(info->i_fd, off, SEEK_SET) == (off_t)-1)
+       if (FINFO_LSEEK_FUNC(info->i_fd, off, SEEK_SET) == (off_t)-1)
                return -1;
 
-       if (read(info->i_fd, buf, len) != (ssize_t)len)
+       if (FINFO_READ_FUNC(info->i_fd, buf, len) != (ssize_t)len)
                return -1;
 
        return (ssize_t)len;
diff --git a/ext/fileinfo/libmagic/compress.c b/ext/fileinfo/libmagic/compress.c
index c31f0f8..4d349cd 100644
--- a/ext/fileinfo/libmagic/compress.c
+++ b/ext/fileinfo/libmagic/compress.c
@@ -224,7 +224,7 @@ sread(int fd, void *buf, size_t n, int canbepipe)
 
 nocheck:
        do
-               switch ((rv = read(fd, buf, n))) {
+               switch ((rv = FINFO_READ_FUNC(fd, buf, n))) {
                case -1:
                        if (errno == EINTR)
                                continue;
@@ -301,7 +301,7 @@ file_pipe2file(struct magic_set *ms, int fd, const void 
*startbuf,
                return -1;
        }
        (void)close(tfd);
-       if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
+       if (FINFO_LSEEK_FUNC(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
                file_badseek(ms);
                return -1;
        }
@@ -405,7 +405,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
                (void) close(0);
                if (fd != -1) {
                    (void) dup(fd);
-                   (void) lseek(0, (off_t)0, SEEK_SET);
+                   (void) FINFO_LSEEK_FUNC(0, (off_t)0, SEEK_SET);
                } else {
                    (void) dup(fdin[0]);
                    (void) close(fdin[0]);
diff --git a/ext/fileinfo/libmagic/file.h b/ext/fileinfo/libmagic/file.h
index b73c9b1..e1269ae 100644
--- a/ext/fileinfo/libmagic/file.h
+++ b/ext/fileinfo/libmagic/file.h
@@ -486,4 +486,12 @@ static const char *rcsid(const char *p) { \
 #define FILE_RCSID(id)
 #endif
 
+#ifdef PHP_WIN32
+#define FINFO_LSEEK_FUNC _lseek
+#define FINFO_READ_FUNC _read
+#else
+#define FINFO_LSEEK_FUNC lseek
+#define FINFO_READ_FUNC read
+#endif
+
 #endif /* __file_h__ */
diff --git a/ext/fileinfo/libmagic/readelf.c b/ext/fileinfo/libmagic/readelf.c
index 7e768ca..f18f7d2 100644
--- a/ext/fileinfo/libmagic/readelf.c
+++ b/ext/fileinfo/libmagic/readelf.c
@@ -309,11 +309,11 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int 
fd, off_t off,
         * Loop through all the program headers.
         */
        for ( ; num; num--) {
-               if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
+               if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (off_t)-1) {
                        file_badseek(ms);
                        return -1;
                }
-               if (read(fd, xph_addr, xph_sizeof) == -1) {
+               if (FINFO_READ_FUNC(fd, xph_addr, xph_sizeof) == -1) {
                        file_badread(ms);
                        return -1;
                }
@@ -331,11 +331,11 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int 
fd, off_t off,
                 * This is a PT_NOTE section; loop through all the notes
                 * in the section.
                 */
-               if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
+               if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == (off_t)-1) {
                        file_badseek(ms);
                        return -1;
                }
-               bufsize = read(fd, nbuf,
+               bufsize = FINFO_READ_FUNC(fd, nbuf,
                    ((xph_filesz < sizeof(nbuf)) ? xph_filesz : sizeof(nbuf)));
                if (bufsize == -1) {
                        file_badread(ms);
@@ -858,11 +858,11 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, 
off_t off, int num,
        }
 
        for ( ; num; num--) {
-               if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
+               if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (off_t)-1) {
                        file_badseek(ms);
                        return -1;
                }
-               if (read(fd, xsh_addr, xsh_sizeof) == -1) {
+               if (FINFO_READ_FUNC(fd, xsh_addr, xsh_sizeof) == -1) {
                        file_badread(ms);
                        return -1;
                }
@@ -888,13 +888,13 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, 
off_t off, int num,
                switch (xsh_type) {
                case SHT_NOTE:
                        nbuf = emalloc((size_t)xsh_size);
-                       if ((noff = lseek(fd, (off_t)xsh_offset, SEEK_SET)) ==
+                       if ((noff = FINFO_LSEEK_FUNC(fd, (off_t)xsh_offset, 
SEEK_SET)) ==
                            (off_t)-1) {
                                file_badread(ms);
                                efree(nbuf);
                                return -1;
                        }
-                       if (read(fd, nbuf, (size_t)xsh_size) !=
+                       if (FINFO_READ_FUNC(fd, nbuf, (size_t)xsh_size) !=
                            (ssize_t)xsh_size) {
                                efree(nbuf);
                                file_badread(ms);
@@ -914,7 +914,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, 
off_t off, int num,
                        efree(nbuf);
                        break;
                case SHT_SUNW_cap:
-                       if (lseek(fd, (off_t)xsh_offset, SEEK_SET) ==
+                       if (FINFO_LSEEK_FUNC(fd, (off_t)xsh_offset, SEEK_SET) ==
                            (off_t)-1) {
                                file_badseek(ms);
                                return -1;
@@ -927,7 +927,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, 
off_t off, int num,
                                    MAX(sizeof cap32, sizeof cap64)];
                                if ((coff += xcap_sizeof) > (off_t)xsh_size)
                                        break;
-                               if (read(fd, cbuf, (size_t)xcap_sizeof) !=
+                               if (FINFO_READ_FUNC(fd, cbuf, 
(size_t)xcap_sizeof) !=
                                    (ssize_t)xcap_sizeof) {
                                        file_badread(ms);
                                        return -1;
@@ -1046,12 +1046,12 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, 
int fd, off_t off,
        }
 
        for ( ; num; num--) {
-               if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
+               if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (off_t)-1) {
                        file_badseek(ms);
                        return -1;
                }
 
-               if (read(fd, xph_addr, xph_sizeof) == -1) {
+               if (FINFO_READ_FUNC(fd, xph_addr, xph_sizeof) == -1) {
                        file_badread(ms);
                        return -1;
                }
@@ -1090,11 +1090,11 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, 
int fd, off_t off,
                         * This is a PT_NOTE section; loop through all the notes
                         * in the section.
                         */
-                       if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
+                       if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == 
(off_t)-1) {
                                file_badseek(ms);
                                return -1;
                        }
-                       bufsize = read(fd, nbuf, ((xph_filesz < sizeof(nbuf)) ?
+                       bufsize = FINFO_READ_FUNC(fd, nbuf, ((xph_filesz < 
sizeof(nbuf)) ?
                            xph_filesz : sizeof(nbuf)));
                        if (bufsize == -1) {
                                file_badread(ms);
@@ -1156,7 +1156,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned 
char *buf,
        /*
         * If we cannot seek, it must be a pipe, socket or fifo.
         */
-       if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
+       if((FINFO_LSEEK_FUNC(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == 
ESPIPE))
                fd = file_pipe2file(ms, fd, buf, nbytes);
 
        if (fstat(fd, &st) == -1) {
diff --git a/ext/fileinfo/tests/finfo_open_001.phpt 
b/ext/fileinfo/tests/finfo_open_001.phpt
index 69696eb..17935c3 100644
--- a/ext/fileinfo/tests/finfo_open_001.phpt
+++ b/ext/fileinfo/tests/finfo_open_001.phpt
@@ -14,10 +14,28 @@ var_dump(finfo_open(FILEINFO_MIME, '/foo/bar/inexistent'));
 
 ?>
 --EXPECTF--
-Warning: finfo_open(): Failed to load magic database at ''. in %s on line %d
+Warning: finfo_open() expects parameter 2 to be a valid path, string given in 
%s on line %d
 bool(false)
 resource(%d) of type (file_info)
 resource(%d) of type (file_info)
+
+Warning: finfo_open(%s123): failed to open stream: No such file or directory 
in %s on line %d
+
+Warning: finfo_open(%s123): failed to open stream: No such file or directory 
in %s on line %d
+
+Warning: finfo_open(): Failed to load magic database at '%s123'. in %s on line 
%d
 bool(false)
+
+Warning: finfo_open(%s1): failed to open stream: No such file or directory in 
%s on line %d
+
+Warning: finfo_open(%s1): failed to open stream: No such file or directory in 
%s on line %d
+
+Warning: finfo_open(): Failed to load magic database at '%s1'. in %s on line %d
 bool(false)
+
+Warning: finfo_open(%sinexistent): failed to open stream: No such file or 
directory in %s on line %d
+
+Warning: finfo_open(%sinexistent): failed to open stream: No such file or 
directory in %s on line %d
+
+Warning: finfo_open(): Failed to load magic database at '%sinexistent'. in %s 
on line %d
 bool(false)
diff --git a/ext/fileinfo/tests/finfo_open_error.phpt 
b/ext/fileinfo/tests/finfo_open_error.phpt
index aae229f..19ae7a6 100644
--- a/ext/fileinfo/tests/finfo_open_error.phpt
+++ b/ext/fileinfo/tests/finfo_open_error.phpt
@@ -26,6 +26,12 @@ var_dump( new finfo('foobar') );
 ===DONE===
 --EXPECTF--
 *** Testing finfo_open() : error functionality ***
+
+Warning: finfo_open(%sfoobarfile): failed to open stream: No such file or 
directory in %s on line %d
+
+Warning: finfo_open(%sfoobarfile): failed to open stream: No such file or 
directory in %s on line %d
+
+Warning: finfo_open(): Failed to load magic database at '%sfoobarfile'. in %s 
on line %d
 bool(false)
 
 Warning: finfo_open() expects parameter 1 to be long, array given in %s on 
line %d
@@ -37,9 +43,9 @@ bool(false)
 Notice: finfo_open(): Warning: using regular magic file `%s' in %s on line %d
 resource(%d) of type (file_info)
 
-Warning: finfo_open() expects parameter 1 to be long, 
%unicode_string_optional% given in %s on line %d
+Warning: finfo_open() expects parameter 1 to be long, string given in %s on 
line %d
 bool(false)
 
-Warning: finfo::finfo() expects parameter 1 to be long, 
%unicode_string_optional% given in %s on line %d
+Warning: finfo::finfo() expects parameter 1 to be long, string given in %s on 
line %d
 NULL
 ===DONE===
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to