SHA256
3
0
forked from pool/file
Dominique Leuenberger 2021-12-01 10:28:59 +00:00 committed by Git OBS Bridge
parent f87fa6b7be
commit 80eb29f619
2 changed files with 127 additions and 145 deletions

View File

@ -1,181 +1,168 @@
From f67fe8bb658fbc19df76128e1012580cf135da78 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Wed, 20 Oct 2021 13:56:15 +0000
Subject: [PATCH] Use the system byte swapping functions if available (Werner
Fink)
--- ---
ChangeLog | 4 ++++ src/apprentice.c | 71 ++++---------------------------------------------------
configure.ac | 4 ++-- src/cdf.c | 53 +++--------------------------------------
src/apprentice.c | 28 ++++++++++++++++++++++++---- 2 files changed, 10 insertions(+), 114 deletions(-)
src/cdf.c | 18 +++++++++++++++++-
4 files changed, 47 insertions(+), 7 deletions(-)
diff --git ChangeLog ChangeLog
index 0bb334c9..0be9711b 100644
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,7 @@
+2021-10-20 9:55 Christos Zoulas <christos@zoulas.com>
+
+ * use the system byte swapping functions if available (Werner Fink)
+
2021-10-18 11:57 Christos Zoulas <christos@zoulas.com>
* release 5.41
diff --git configure.ac configure.ac
index ccc57e13..528bb40d 100644
--- configure.ac
+++ configure.ac
@@ -99,10 +99,10 @@ gl_VISIBILITY
dnl Checks for headers
AC_HEADER_MAJOR
AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS(stdint.h fcntl.h inttypes.h unistd.h)
+AC_CHECK_HEADERS(stdint.h fcntl.h inttypes.h unistd.h byteswap.h)
AC_CHECK_HEADERS(utime.h wchar.h wctype.h)
AC_CHECK_HEADERS(getopt.h err.h xlocale.h)
-AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h sys/sysmacros.h)
+AC_CHECK_HEADERS(sys/bswap.h sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h sys/sysmacros.h)
if test "$enable_zlib" != "no"; then
AC_CHECK_HEADERS(zlib.h)
fi
diff --git src/apprentice.c src/apprentice.c
index eb3b4a59..8f51b922 100644
--- src/apprentice.c --- src/apprentice.c
+++ src/apprentice.c +++ src/apprentice.c 2021-10-19 08:56:33.418646912 +0000
@@ -32,7 +32,7 @@ @@ -50,7 +50,7 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.309 2021/09/24 13:59:19 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.310 2021/10/20 13:56:15 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -50,6 +50,12 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.309 2021/09/24 13:59:19 christos Exp $")
#endif #endif
#include <dirent.h> #include <dirent.h>
#include <limits.h> #include <limits.h>
+#ifdef HAVE_BYTESWAP_H -
+#include <byteswap.h> +#include <byteswap.h>
+#endif
+#ifdef HAVE_SYS_BSWAP_H
+#include <sys/bswap.h>
+#endif
#define EATAB {while (isascii(CAST(unsigned char, *l)) && \ #define EATAB {while (isascii(CAST(unsigned char, *l)) && \
@@ -124,9 +130,21 @@ private void mlist_free_all(struct magic_set *); isspace(CAST(unsigned char, *l))) ++l;}
@@ -124,9 +124,11 @@ private void mlist_free_all(struct magic
private void mlist_free(struct mlist *); private void mlist_free(struct mlist *);
private void byteswap(struct magic *, uint32_t); private void byteswap(struct magic *, uint32_t);
private void bs1(struct magic *); private void bs1(struct magic *);
-private uint16_t swap2(uint16_t);
-private uint32_t swap4(uint32_t);
-private uint64_t swap8(uint64_t);
+ +
+#if defined(HAVE_BYTESWAP_H)
+#define swap2(x) bswap_16(x) +#define swap2(x) bswap_16(x)
+#define swap4(x) bswap_32(x) +#define swap4(x) bswap_32(x)
+#define swap8(x) bswap_64(x) +#define swap8(x) bswap_64(x)
+#elif defined(HAVE_SYS_BSWAP_H)
+#define swap2(x) bswap16(x)
+#define swap4(x) bswap32(x)
+#define swap8(x) bswap64(x)
+#else
private uint16_t swap2(uint16_t);
private uint32_t swap4(uint32_t);
private uint64_t swap8(uint64_t);
+#endif
+ +
private char *mkdbname(struct magic_set *, const char *, int); private char *mkdbname(struct magic_set *, const char *, int);
private struct magic_map *apprentice_buf(struct magic_set *, struct magic *, private struct magic_map *apprentice_buf(struct magic_set *, struct magic *,
size_t); size_t);
@@ -3355,6 +3373,7 @@ byteswap(struct magic *magic, uint32_t nmagic) @@ -3355,67 +3357,6 @@ byteswap(struct magic *magic, uint32_t n
bs1(&magic[i]); bs1(&magic[i]);
} }
+#if !defined(HAVE_BYTESWAP_H) && !defined(HAVE_SYS_BSWAP_H) -/*
/* - * swap a short
* swap a short - */
*/ -private uint16_t
@@ -3394,7 +3413,7 @@ swap8(uint64_t sv) -swap2(uint16_t sv)
uint64_t rv; -{
uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv)); - uint16_t rv;
uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv)); - uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
- d[0] = s[1];
- d[1] = s[0];
- return rv;
-}
-
-/*
- * swap an int
- */
-private uint32_t
-swap4(uint32_t sv)
-{
- uint32_t rv;
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
- d[0] = s[3];
- d[1] = s[2];
- d[2] = s[1];
- d[3] = s[0];
- return rv;
-}
-
-/*
- * swap a quad
- */
-private uint64_t
-swap8(uint64_t sv)
-{
- uint64_t rv;
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
-#if 0 -#if 0
+# if 0 - d[0] = s[3];
d[0] = s[3]; - d[1] = s[2];
d[1] = s[2]; - d[2] = s[1];
d[2] = s[1]; - d[3] = s[0];
@@ -3403,7 +3422,7 @@ swap8(uint64_t sv) - d[4] = s[7];
d[5] = s[6]; - d[5] = s[6];
d[6] = s[5]; - d[6] = s[5];
d[7] = s[4]; - d[7] = s[4];
-#else -#else
+# else - d[0] = s[7];
d[0] = s[7]; - d[1] = s[6];
d[1] = s[6]; - d[2] = s[5];
d[2] = s[5]; - d[3] = s[4];
@@ -3412,9 +3431,10 @@ swap8(uint64_t sv) - d[4] = s[3];
d[5] = s[2]; - d[5] = s[2];
d[6] = s[1]; - d[6] = s[1];
d[7] = s[0]; - d[7] = s[0];
-#endif -#endif
+# endif - return rv;
return rv; -}
} -
+#endif
protected uintmax_t protected uintmax_t
file_varint2uintmax_t(const unsigned char *us, int t, size_t *l) file_varint2uintmax_t(const unsigned char *us, int t, size_t *l)
diff --git src/cdf.c src/cdf.c {
index b5ad2f6a..874a6ed3 100644
--- src/cdf.c --- src/cdf.c
+++ src/cdf.c +++ src/cdf.c 2021-10-19 08:53:37.577690786 +0000
@@ -35,7 +35,7 @@ @@ -48,6 +48,7 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.120 202
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.120 2021/09/24 13:59:19 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.121 2021/10/20 13:56:15 christos Exp $")
#endif
#include <assert.h>
@@ -48,6 +48,12 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.120 2021/09/24 13:59:19 christos Exp $")
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
+#ifdef HAVE_BYTESWAP_H
+#include <byteswap.h> +#include <byteswap.h>
+#endif
+#ifdef HAVE_SYS_BSWAP_H
+#include <sys/bswap.h>
+#endif
#ifndef EFTYPE #ifndef EFTYPE
#define EFTYPE EINVAL #define EFTYPE EINVAL
@@ -124,6 +130,15 @@ cdf_calloc(const char *file __attribute__((__unused__)), @@ -124,55 +125,9 @@ cdf_calloc(const char *file __attribute_
return calloc(n, u); return calloc(n, u);
} }
+#if defined(HAVE_BYTESWAP_H) -/*
+# define _cdf_tole2(x) bswap_16(x) - * swap a short
+# define _cdf_tole4(x) bswap_32(x) - */
+# define _cdf_tole8(x) bswap_64(x) -static uint16_t
+#elif defined(HAVE_SYS_BSWAP_H) -_cdf_tole2(uint16_t sv)
+# define _cdf_tole2(x) bswap16(x) -{
+# define _cdf_tole4(x) bswap32(x) - uint16_t rv;
+# define _cdf_tole8(x) bswap64(x) - uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
+#else - uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
/* - d[0] = s[1];
* swap a short - d[1] = s[0];
*/ - return rv;
@@ -173,6 +188,7 @@ _cdf_tole8(uint64_t sv) -}
d[7] = s[0]; -
return rv; -/*
} - * swap an int
+#endif - */
-static uint32_t
-_cdf_tole4(uint32_t sv)
-{
- uint32_t rv;
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
- d[0] = s[3];
- d[1] = s[2];
- d[2] = s[1];
- d[3] = s[0];
- return rv;
-}
-
-/*
- * swap a quad
- */
-static uint64_t
-_cdf_tole8(uint64_t sv)
-{
- uint64_t rv;
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
- d[0] = s[7];
- d[1] = s[6];
- d[2] = s[5];
- d[3] = s[4];
- d[4] = s[3];
- d[5] = s[2];
- d[6] = s[1];
- d[7] = s[0];
- return rv;
-}
+#define _cdf_tole2(x) bswap_16(x)
+#define _cdf_tole4(x) bswap_32(x)
+#define _cdf_tole8(x) bswap_64(x)
/* /*
* grab a uint32_t from a possibly unaligned address, and return it in * grab a uint32_t from a possibly unaligned address, and return it in
--
2.26.2

View File

@ -1,12 +1,7 @@
-------------------------------------------------------------------
Thu Oct 21 08:33:48 UTC 2021 - Dr. Werner Fink <werner@suse.de>
- Now file-5.23-endian.patch is at upstream git repository, use it
------------------------------------------------------------------- -------------------------------------------------------------------
Thu Oct 21 06:24:35 UTC 2021 - Dr. Werner Fink <werner@suse.de> Thu Oct 21 06:24:35 UTC 2021 - Dr. Werner Fink <werner@suse.de>
- Remove file-5.38-allow-readlinkat.dif as already done in latest - Remove file-5.38-allow-readlinkat.dif as already doen in latest
file 5.41 file 5.41
------------------------------------------------------------------- -------------------------------------------------------------------