summaryrefslogtreecommitdiff
path: root/ext/fileinfo/libmagic.patch
blob: 1427d87d6105b3888267b510b651abb767d037f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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