Commit: dcdd6dab56c58c5798ee36269724e29c6bb562b8
Author: Anatoliy Belsky <a...@php.net> Mon, 2 Apr 2012 17:22:46 +0200
Committer: Stanislav Malyshev <s...@php.net> Wed, 11 Apr 2012 20:23:32
-0700
Parents: ea3e0d5a7370df63af9372780b91a749fda773b1
Branches: PHP-5.4.1
Link:
http://git.php.net/?p=php-src.git;a=commitdiff;h=dcdd6dab56c58c5798ee36269724e29c6bb562b8
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 de55ae3..17935c3 100644
--- a/ext/fileinfo/tests/finfo_open_001.phpt
+++ b/ext/fileinfo/tests/finfo_open_001.phpt
@@ -19,23 +19,23 @@ bool(false)
resource(%d) of type (file_info)
resource(%d) of type (file_info)
-Warning: finfo_open(%s/123): 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(%s/123): 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 '%s/123'. 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(%s/1): 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(%s/1): 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 '%s/1'. 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(/foo/bar/inexistent): 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(/foo/bar/inexistent): 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 '/foo/bar/inexistent'.
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 6f5e79f..19ae7a6 100644
--- a/ext/fileinfo/tests/finfo_open_error.phpt
+++ b/ext/fileinfo/tests/finfo_open_error.phpt
@@ -27,11 +27,11 @@ var_dump( new finfo('foobar') );
--EXPECTF--
*** Testing finfo_open() : error functionality ***
-Warning: finfo_open(%s/foobarfile): 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(%s/foobarfile): 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 '%s/foobarfile'. 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
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php