You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
254 lines
7.4 KiB
254 lines
7.4 KiB
Index: configure |
|
--- configure.orig 2019-05-17 04:27:45.000000000 +0200 |
|
+++ configure 2019-05-17 07:57:58.610495000 +0200 |
|
@@ -3354,7 +3354,7 @@ |
|
fi |
|
|
|
|
|
-pkgdatadir='$(datadir)/misc' |
|
+pkgdatadir='$(datadir)/file' |
|
|
|
|
|
if test x$fsect = x5; then |
|
Index: src/apprentice.c |
|
--- src/apprentice.c.orig 2019-02-20 03:35:27.000000000 +0100 |
|
+++ src/apprentice.c 2019-05-17 07:57:58.610870000 +0200 |
|
@@ -1303,7 +1303,7 @@ |
|
for (i = 0; i < nme; i++) |
|
mentrycount += me[i].cont_count; |
|
|
|
- slen = sizeof(**ma) * mentrycount; |
|
+ slen = sizeof(**ma) * (mentrycount + 1); |
|
if ((*ma = CAST(struct magic *, malloc(slen))) == NULL) { |
|
file_oomem(ms, slen); |
|
return -1; |
|
Index: src/compress.c |
|
--- src/compress.c.orig 2019-05-07 04:27:11.000000000 +0200 |
|
+++ src/compress.c 2019-05-17 08:01:23.118814000 +0200 |
|
@@ -350,7 +350,7 @@ |
|
* `safe' read for sockets and pipes. |
|
*/ |
|
protected ssize_t |
|
-sread(int fd, void *buf, size_t n, int canbepipe __attribute__((__unused__))) |
|
+file_sread(int fd, void *buf, size_t n, int canbepipe __attribute__((__unused__))) |
|
{ |
|
ssize_t rv; |
|
#ifdef FIONREAD |
|
@@ -451,7 +451,7 @@ |
|
if (swrite(tfd, startbuf, nbytes) != CAST(ssize_t, nbytes)) |
|
r = 1; |
|
else { |
|
- while ((r = sread(fd, buf, sizeof(buf), 1)) > 0) |
|
+ while ((r = file_sread(fd, buf, sizeof(buf), 1)) > 0) |
|
if (swrite(tfd, buf, CAST(size_t, r)) != r) |
|
break; |
|
} |
|
@@ -775,14 +775,14 @@ |
|
goto err; |
|
} |
|
rv = OKDATA; |
|
- r = sread(fdp[STDOUT_FILENO][0], *newch, bytes_max, 0); |
|
+ r = file_sread(fdp[STDOUT_FILENO][0], *newch, bytes_max, 0); |
|
if (r <= 0) { |
|
DPRINTF("Read stdout failed %d (%s)\n", fdp[STDOUT_FILENO][0], |
|
r != -1 ? strerror(errno) : "no data"); |
|
|
|
rv = ERRDATA; |
|
if (r == 0 && |
|
- (r = sread(fdp[STDERR_FILENO][0], *newch, bytes_max, 0)) > 0) |
|
+ (r = file_sread(fdp[STDERR_FILENO][0], *newch, bytes_max, 0)) > 0) |
|
{ |
|
r = filter_error(*newch, r); |
|
goto ok; |
|
Index: src/file.h |
|
--- src/file.h.orig 2019-05-07 04:27:11.000000000 +0200 |
|
+++ src/file.h 2019-05-17 07:57:58.611273000 +0200 |
|
@@ -501,7 +501,7 @@ |
|
protected void file_showstr(FILE *, const char *, size_t); |
|
protected size_t file_mbswidth(const char *); |
|
protected const char *file_getbuffer(struct magic_set *); |
|
-protected ssize_t sread(int, void *, size_t, int); |
|
+protected ssize_t file_sread(int, void *, size_t, int); |
|
protected int file_check_mem(struct magic_set *, unsigned int); |
|
protected int file_looks_utf8(const unsigned char *, size_t, unichar *, |
|
size_t *); |
|
@@ -559,9 +559,11 @@ |
|
ssize_t pread(int, void *, size_t, off_t); |
|
#endif |
|
#ifndef HAVE_VASPRINTF |
|
+#define vasprintf file_vasprintf |
|
int vasprintf(char **, const char *, va_list); |
|
#endif |
|
#ifndef HAVE_ASPRINTF |
|
+#define asprintf file_asprintf |
|
int asprintf(char **, const char *, ...); |
|
#endif |
|
#ifndef HAVE_DPRINTF |
|
Index: src/funcs.c |
|
--- src/funcs.c.orig 2019-05-07 04:27:11.000000000 +0200 |
|
+++ src/funcs.c 2019-05-17 07:57:58.611428000 +0200 |
|
@@ -35,6 +35,7 @@ |
|
#include <stdarg.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
+#include <limits.h> |
|
#include <ctype.h> |
|
#if defined(HAVE_WCHAR_H) |
|
#include <wchar.h> |
|
@@ -650,3 +651,108 @@ |
|
*ptr = '\0'; |
|
return buf; |
|
} |
|
+ |
|
+/* |
|
+ * From bsd-asprintf.c in OpenSSH: |
|
+ * Copyright (c) 2004 Darren Tucker. |
|
+ * |
|
+ * Based originally on asprintf.c from OpenBSD: |
|
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> |
|
+ * |
|
+ * Permission to use, copy, modify, and distribute this software for any |
|
+ * purpose with or without fee is hereby granted, provided that the above |
|
+ * copyright notice and this permission notice appear in all copies. |
|
+ * |
|
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
+ */ |
|
+ |
|
+#ifndef HAVE_ASPRINTF |
|
+int asprintf(char **str, const char *fmt, ...) |
|
+{ |
|
+ va_list ap; |
|
+ int ret; |
|
+ |
|
+ *str = NULL; |
|
+ va_start(ap, fmt); |
|
+ ret = vasprintf(str, fmt, ap); |
|
+ va_end(ap); |
|
+ |
|
+ return ret; |
|
+} |
|
+#endif |
|
+ |
|
+#ifndef HAVE_VASPRINTF |
|
+ |
|
+#ifdef HAVE_LIMITS_H |
|
+#include <limits.h> |
|
+#endif |
|
+ |
|
+#include <errno.h> |
|
+#include <stdarg.h> |
|
+#include <stdlib.h> |
|
+ |
|
+#ifndef VA_COPY |
|
+# ifdef HAVE_VA_COPY |
|
+# define VA_COPY(dest, src) va_copy(dest, src) |
|
+# else |
|
+# ifdef HAVE___VA_COPY |
|
+# define VA_COPY(dest, src) __va_copy(dest, src) |
|
+# else |
|
+# define VA_COPY(dest, src) (dest) = (src) |
|
+# endif |
|
+# endif |
|
+#endif |
|
+ |
|
+#define INIT_SZ 128 |
|
+ |
|
+int vasprintf(char **str, const char *fmt, va_list ap) |
|
+{ |
|
+ int ret = -1; |
|
+ va_list ap2; |
|
+ char *string, *newstr; |
|
+ size_t len; |
|
+ |
|
+ VA_COPY(ap2, ap); |
|
+ if ((string = malloc(INIT_SZ)) == NULL) |
|
+ goto fail; |
|
+ |
|
+ ret = vsnprintf(string, INIT_SZ, fmt, ap2); |
|
+ if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */ |
|
+ *str = string; |
|
+ } else if (ret == INT_MAX || ret < 0) { /* Bad length */ |
|
+ free(string); |
|
+ goto fail; |
|
+ } else { /* bigger than initial, realloc allowing for nul */ |
|
+ len = (size_t)ret + 1; |
|
+ if ((newstr = realloc(string, len)) == NULL) { |
|
+ free(string); |
|
+ goto fail; |
|
+ } else { |
|
+ va_end(ap2); |
|
+ VA_COPY(ap2, ap); |
|
+ ret = vsnprintf(newstr, len, fmt, ap2); |
|
+ if (ret >= 0 && (size_t)ret < len) { |
|
+ *str = newstr; |
|
+ } else { /* failed with realloc'ed string, give up */ |
|
+ free(newstr); |
|
+ goto fail; |
|
+ } |
|
+ } |
|
+ } |
|
+ va_end(ap2); |
|
+ return (ret); |
|
+ |
|
+fail: |
|
+ *str = NULL; |
|
+ errno = ENOMEM; |
|
+ va_end(ap2); |
|
+ return (-1); |
|
+} |
|
+#endif |
|
+ |
|
Index: src/getopt_long.h |
|
--- src/getopt_long.h.orig 2019-05-17 07:57:58.611532000 +0200 |
|
+++ src/getopt_long.h 2019-05-17 07:57:58.611518000 +0200 |
|
@@ -0,0 +1,14 @@ |
|
+#ifndef __GETOPT_LONG_H |
|
+#define __GETOPT_LONG_H 1 |
|
+struct option { |
|
+ const char *name; |
|
+ int has_arg; |
|
+ int *flag; |
|
+ int val; |
|
+}; |
|
+#define no_argument 0 |
|
+#define required_argument 1 |
|
+#define optional_argument 2 |
|
+int getopt_long(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex); |
|
+ |
|
+#endif |
|
Index: src/magic.c |
|
--- src/magic.c.orig 2019-05-07 04:27:11.000000000 +0200 |
|
+++ src/magic.c 2019-05-17 08:01:36.628818000 +0200 |
|
@@ -122,7 +122,7 @@ |
|
_w32_get_magic_relative_to(char **hmagicpath, HINSTANCE module) |
|
{ |
|
static const char *trypaths[] = { |
|
- "%s/share/misc/magic.mgc", |
|
+ "%s/share/file/magic.mgc", |
|
"%s/magic.mgc", |
|
}; |
|
LPSTR dllpath; |
|
@@ -146,7 +146,7 @@ |
|
sp = strlen(dllpath); |
|
if (sp > 3 && stricmp(&dllpath[sp - 3], "bin") == 0) { |
|
_w32_append_path(hmagicpath, |
|
- "%s/../share/misc/magic.mgc", dllpath); |
|
+ "%s/../share/file/magic.mgc", dllpath); |
|
goto out; |
|
} |
|
|
|
@@ -478,7 +478,7 @@ |
|
if (fd != -1) { |
|
ssize_t r = 0; |
|
|
|
- while ((r = sread(fd, RCAST(void *, &buf[nbytes]), |
|
+ while ((r = file_sread(fd, RCAST(void *, &buf[nbytes]), |
|
CAST(size_t, ms->bytes_max - nbytes), 1)) > 0) { |
|
nbytes += r; |
|
if (r < PIPE_BUF) break;
|
|
|