php-src/ext/fileinfo/libmagic.patch

128 lines
2.8 KiB
Diff

Index: libmagic/apprentice.c
===================================================================
RCS file: /repository/pecl/fileinfo/libmagic/apprentice.c,v
retrieving revision 1.1
diff -u -r1.1 apprentice.c
--- libmagic/apprentice.c 11 Jul 2008 14:13:50 -0000 1.1
+++ libmagic/apprentice.c 25 Jul 2008 08:18:07 -0000
@@ -157,6 +157,10 @@
}
#endif /* COMPILE_ONLY */
+#ifdef PHP_BUNDLE
+#include "../data_file.c"
+#endif
+
static const struct type_tbl_s {
const char name[16];
const size_t len;
@@ -310,6 +314,11 @@
if (p == NULL)
return;
switch (type) {
+#ifdef PHP_BUNDLE
+ case 3:
+ /* Do nothing, it's part of the code segment */
+ break;
+#endif
#ifdef QUICK
case 2:
p--;
@@ -339,8 +348,19 @@
if (fn == NULL)
fn = getenv("MAGIC");
- if (fn == NULL)
+ if (fn == NULL) {
+#ifdef PHP_BUNDLE
+ if ((mlist = malloc(sizeof(*mlist))) == NULL) {
+ file_oomem(ms, sizeof(*mlist));
+ return NULL;
+ }
+ mlist->next = mlist->prev = mlist;
+ apprentice_1(ms, fn, action, mlist);
+ return mlist;
+#else
fn = MAGIC;
+#endif
+ }
if ((mfn = strdup(fn)) == NULL) {
file_oomem(ms, strlen(fn));
@@ -1886,6 +1906,15 @@
int needsbyteswap;
char *dbname = NULL;
void *mm = NULL;
+ int ret = 0;
+
+#ifdef PHP_BUNDLE
+ if (fn == NULL) {
+ mm = &php_magic_database;
+ ret = 3;
+ goto internal_loaded;
+ }
+#endif
mkdbname(fn, &dbname, 0);
if (dbname == NULL)
@@ -1909,7 +1938,7 @@
file_error(ms, errno, "cannot map `%s'", dbname);
goto error1;
}
-#define RET 2
+ ret = 2;
#else
if ((mm = malloc((size_t)st.st_size)) == NULL) {
file_oomem(ms, (size_t)st.st_size);
@@ -1919,11 +1948,14 @@
file_badread(ms);
goto error1;
}
-#define RET 1
+ ret = 1;
#endif
- *magicp = mm;
(void)close(fd);
fd = -1;
+#ifdef PHP_BUNDLE
+internal_loaded:
+#endif
+ *magicp = mm;
ptr = (uint32_t *)(void *)*magicp;
if (*ptr != MAGICNO) {
if (swap4(*ptr) != MAGICNO) {
@@ -1943,6 +1975,11 @@
VERSIONNO, dbname, version);
goto error1;
}
+#ifdef PHP_BUNDLE
+ if (fn == NULL)
+ *nmagicp = (sizeof(php_magic_database) / sizeof(struct magic));
+ else /* the statement after the #endif is used */
+#endif
*nmagicp = (uint32_t)(st.st_size / sizeof(struct magic));
if (*nmagicp > 0)
(*nmagicp)--;
@@ -1950,7 +1987,7 @@
if (needsbyteswap)
byteswap(*magicp, *nmagicp);
free(dbname);
- return RET;
+ return ret;
error1:
if (fd != -1)
Index: libmagic/config.h
===================================================================
RCS file: /repository/pecl/fileinfo/libmagic/config.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- libmagic/config.h 11 Jul 2008 14:49:45 -0000 1.2
+++ libmagic/config.h 24 Jul 2008 13:40:21 -0000 1.3
@@ -2,3 +2,4 @@
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
+#define PHP_BUNDLE