diff -u libmagic.orig/apprentice.c libmagic/apprentice.c
--- libmagic.orig/apprentice.c 2013-03-21 18:45:14.000000000 +0100
-+++ libmagic/apprentice.c 2013-04-08 16:14:17.828357711 +0200
++++ libmagic/apprentice.c 2013-04-27 13:53:32.175250261 +0200
@@ -29,6 +29,8 @@
* apprentice - make one pass through /etc/magic, learning its secrets.
*/
file_oomem(ms, slen);
return -1;
}
-@@ -1102,14 +1121,14 @@
+@@ -1102,27 +1121,29 @@
if (me == NULL)
return;
for (i = 0; i < nme; i++)
struct magic_entry *mentry[MAGIC_SETS] = { NULL };
uint32_t mentrycount[MAGIC_SETS] = { 0 };
uint32_t i, j;
-@@ -1117,12 +1136,14 @@
- char **filearr = NULL, *mfn;
+ size_t files = 0, maxfiles = 0;
+- char **filearr = NULL, *mfn;
++ char **filearr = NULL;
struct stat st;
struct magic_map *map;
- DIR *dir;
+ int mflen;
+ char mfn[MAXPATHLEN];
+
-+ dir = php_stream_opendir(fn, REPORT_ERRORS, NULL);
++ dir = php_stream_opendir((char *)fn, REPORT_ERRORS, NULL);
if (!dir) {
errs++;
goto out;
+#ifdef PHP_WIN32
+ /* Don't bother on windows with php_stream_open_wrapper,
+ return to give apprentice_load() a chance. */
-+ if (php_stream_stat_path_ex(fn, 0, &st, NULL) == SUCCESS) {
++ if (php_stream_stat_path_ex((char *)fn, 0, &st, NULL) == SUCCESS) {
+ if (st.sb.st_mode & S_IFDIR) {
+ goto error;
+ }
}
- if (write(fd, map->nmagic, nm) != (ssize_t)nm) {
-+ if (php_stream_write(stream, map->nmagic, nm) != (ssize_t)nm) {
++ if (php_stream_write(stream, (const char *)map->nmagic, nm) != (ssize_t)nm) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
for (i = 0; i < MAGIC_SETS; i++) {
len = m * map->nmagic[i];
- if (write(fd, map->magic[i], len) != (ssize_t)len) {
-+ if (php_stream_write(stream, map->magic[i], len) != (ssize_t)len) {
++ if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
+
diff -u libmagic.orig/magic.c libmagic/magic.c
--- libmagic.orig/magic.c 2013-01-11 17:43:09.000000000 +0100
-+++ libmagic/magic.c 2013-04-08 15:42:57.328298809 +0200
++++ libmagic/magic.c 2013-04-27 13:53:32.175250261 +0200
@@ -25,11 +25,6 @@
* SUCH DAMAGE.
*/
#if defined(HAVE_UTIMES)
# include <sys/time.h>
#elif defined(HAVE_UTIME)
-@@ -71,18 +75,24 @@
+@@ -71,18 +75,25 @@
#endif
#endif
+# undef S_IFIFO
+#endif
+
-+private void free_mlist(struct mlist *);
private void close_and_restore(const struct magic_set *, const char *, int,
const struct stat *);
private int unreadable_info(struct magic_set *, mode_t, const char *);
++#if 0
private const char* get_default_magic(void);
-#ifndef COMPILE_ONLY
-private const char *file_or_fd(struct magic_set *, const char *, int);
--#endif
+ #endif
+private const char *file_or_stream(struct magic_set *, const char *, php_stream *);
#ifndef STDIN_FILENO
private const char *
get_default_magic(void)
{
-@@ -90,7 +100,7 @@
+@@ -90,7 +101,7 @@
static char *default_magic;
char *home, *hmagicpath;
struct stat st;
if (default_magic) {
-@@ -104,17 +114,17 @@
+@@ -104,17 +115,17 @@
return MAGIC;
if (stat(hmagicpath, &st) == -1) {
free(hmagicpath);
}
if (asprintf(&default_magic, "%s:%s", hmagicpath, MAGIC) < 0)
-@@ -128,6 +138,7 @@
+@@ -128,6 +139,7 @@
#else
char *hmagicp = hmagicpath;
char *tmppath = NULL;
#define APPENDPATH() \
do { \
-@@ -172,7 +183,7 @@
+@@ -172,7 +184,7 @@
}
/* Third, try to get magic file relative to dll location */
dllpath[MAX_PATH] = 0; /* just in case long path gets truncated and not null terminated */
if (GetModuleFileNameA(NULL, dllpath, MAX_PATH)){
PathRemoveFileSpecA(dllpath);
-@@ -210,6 +221,7 @@
+@@ -210,6 +222,7 @@
return action == FILE_LOAD ? get_default_magic() : MAGIC;
}
public struct magic_set *
magic_open(int flags)
-@@ -250,7 +262,7 @@
+@@ -250,7 +263,7 @@
magic_load(struct magic_set *ms, const char *magicfile)
{
if (ms == NULL)
return file_apprentice(ms, magicfile, FILE_LOAD);
}
-@@ -262,13 +274,6 @@
+@@ -262,13 +275,6 @@
return file_apprentice(ms, magicfile, FILE_COMPILE);
}
public int
magic_list(struct magic_set *ms, const char *magicfile)
-@@ -282,9 +287,6 @@
+@@ -282,9 +288,6 @@
close_and_restore(const struct magic_set *ms, const char *name, int fd,
const struct stat *sb)
{
if ((ms->flags & MAGIC_PRESERVE_ATIME) != 0) {
/*
-@@ -311,7 +313,6 @@
+@@ -311,7 +314,6 @@
}
}
/*
* find type of descriptor
-@@ -321,7 +322,7 @@
+@@ -321,7 +323,7 @@
{
if (ms == NULL)
return NULL;
}
/*
-@@ -332,30 +333,42 @@
+@@ -332,30 +334,42 @@
{
if (ms == NULL)
return NULL;
case -1: /* error */
goto done;
case 0: /* nothing found */
-@@ -365,68 +378,48 @@
+@@ -365,68 +379,48 @@
goto done;
}
return rv == 0 ? file_getbuffer(ms) : NULL;
}
-@@ -440,14 +433,13 @@
+@@ -440,14 +434,13 @@
return NULL;
/*
* The main work is done here!
diff -u libmagic.orig/print.c libmagic/print.c
--- libmagic.orig/print.c 2013-03-21 18:45:14.000000000 +0100
-+++ libmagic/print.c 2013-04-08 15:42:57.328298809 +0200
-@@ -28,6 +28,8 @@
++++ libmagic/print.c 2013-04-27 13:53:32.175250261 +0200
+@@ -28,13 +28,17 @@
/*
* print.c - debugging printout routines
*/
+#include "php.h"
#include "file.h"
++#include "cdf.h"
-@@ -35,6 +37,7 @@
+ #ifndef lint
FILE_RCSID("@(#)$File: print.c,v 1.76 2013/02/26 18:25:00 christos Exp $")
#endif /* lint */
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
-@@ -43,188 +46,28 @@
+@@ -43,188 +47,28 @@
#endif
#include <time.h>
- (void) fprintf(stderr, "Warning: ");
va_start(va, f);
- (void) vfprintf(stderr, f, va);
-+ vasprintf(&expanded_format, f, va);
++ if (vasprintf(&expanded_format, f, va)); /* silence */
va_end(va);
- (void) fputc('\n', stderr);
+
}
protected const char *
-@@ -235,7 +78,7 @@
+@@ -235,7 +79,7 @@
struct tm *tm;
if (flags & FILE_T_WINDOWS) {