FILE5_47-57-g797a2755.add-le-be-guid.patch 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. Subject: Add LE/BE GUID
  2. Origin: upstream, commit FILE5_47-57-g797a2755 <https://github.com/file/file/commit/FILE5_47-57-g797a2755>
  3. Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Sun Apr 19 19:56:49 2026 +0000
  5. Forwarded: not-needed
  6. --- a/doc/magic.man
  7. +++ b/doc/magic.man
  8. @@ -373,7 +373,9 @@
  9. .Dv rel-oid-iri .
  10. These types can be followed by an optional numeric size, which indicates
  11. the field width in bytes.
  12. -.It Dv guid
  13. +.It Dv guid ,
  14. +.It Dv leguid ,
  15. +.It Dv beguid
  16. A Globally Unique Identifier, parsed and printed as
  17. XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.
  18. It's format is a string.
  19. --- a/src/Makefile.am
  20. +++ b/src/Makefile.am
  21. @@ -10,7 +10,8 @@
  22. libmagic_la_SOURCES = buffer.c magic.c apprentice.c softmagic.c ascmagic.c \
  23. encoding.c compress.c is_csv.c is_json.c is_simh.c is_tar.c readelf.c \
  24. print.c fsmagic.c funcs.c file.h readelf.h tar.h apptype.c der.c der.h \
  25. - file_opts.h elfclass.h mygetopt.h cdf.c cdf_time.c readcdf.c cdf.h
  26. + file_opts.h elfclass.h mygetopt.h cdf.c cdf_time.c readcdf.c cdf.h \
  27. + swap.c swap.h
  28. libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
  29. if MINGW
  30. MINGWLIBS = -lgnurx -lshlwapi
  31. --- a/src/apprentice.c
  32. +++ b/src/apprentice.c
  33. @@ -36,6 +36,7 @@
  34. #endif /* lint */
  35. #include "magic.h"
  36. +#include "swap.h"
  37. #include <stdlib.h>
  38. #ifdef HAVE_UNISTD_H
  39. #include <unistd.h>
  40. @@ -50,12 +51,6 @@
  41. #endif
  42. #include <dirent.h>
  43. #include <limits.h>
  44. -#ifdef HAVE_BYTESWAP_H
  45. -#include <byteswap.h>
  46. -#endif
  47. -#ifdef HAVE_SYS_BSWAP_H
  48. -#include <sys/bswap.h>
  49. -#endif
  50. #define EATAB {while (*l && isascii(CAST(unsigned char, *l)) && \
  51. @@ -131,20 +126,6 @@
  52. file_private void byteswap(struct magic *, uint32_t);
  53. file_private void bs1(struct magic *);
  54. -#if defined(HAVE_BYTESWAP_H)
  55. -#define swap2(x) bswap_16(x)
  56. -#define swap4(x) bswap_32(x)
  57. -#define swap8(x) bswap_64(x)
  58. -#elif defined(HAVE_SYS_BSWAP_H)
  59. -#define swap2(x) bswap16(x)
  60. -#define swap4(x) bswap32(x)
  61. -#define swap8(x) bswap64(x)
  62. -#else
  63. -file_private uint16_t swap2(uint16_t);
  64. -file_private uint32_t swap4(uint32_t);
  65. -file_private uint64_t swap8(uint64_t);
  66. -#endif
  67. -
  68. file_private char *mkdbname(struct magic_set *, const char *, int);
  69. file_private struct magic_map *apprentice_buf(struct magic_set *, struct magic *,
  70. size_t);
  71. @@ -285,6 +266,8 @@
  72. { XX("clear"), FILE_CLEAR, FILE_FMT_NONE },
  73. { XX("der"), FILE_DER, FILE_FMT_STR },
  74. { XX("guid"), FILE_GUID, FILE_FMT_STR },
  75. + { XX("leguid"), FILE_LEGUID, FILE_FMT_STR },
  76. + { XX("beguid"), FILE_BEGUID, FILE_FMT_STR },
  77. { XX("offset"), FILE_OFFSET, FILE_FMT_QUAD },
  78. { XX("bevarint"), FILE_BEVARINT, FILE_FMT_STR },
  79. { XX("levarint"), FILE_LEVARINT, FILE_FMT_STR },
  80. @@ -926,6 +909,8 @@
  81. case FILE_LEVARINT:
  82. return 8;
  83. + case FILE_LEGUID:
  84. + case FILE_BEGUID:
  85. case FILE_GUID:
  86. return 16;
  87. @@ -989,6 +974,8 @@
  88. case FILE_BEVARINT:
  89. case FILE_LEVARINT:
  90. case FILE_GUID:
  91. + case FILE_LEGUID:
  92. + case FILE_BEGUID:
  93. case FILE_BEID3:
  94. case FILE_LEID3:
  95. case FILE_OFFSET:
  96. @@ -1251,6 +1238,8 @@
  97. case FILE_LEVARINT:
  98. case FILE_DER:
  99. case FILE_GUID:
  100. + case FILE_LEGUID:
  101. + case FILE_BEGUID:
  102. case FILE_OFFSET:
  103. case FILE_MSDOSDATE:
  104. case FILE_BEMSDOSDATE:
  105. @@ -1727,6 +1716,8 @@
  106. case FILE_CLEAR:
  107. case FILE_DER:
  108. case FILE_GUID:
  109. + case FILE_LEGUID:
  110. + case FILE_BEGUID:
  111. case FILE_OCTAL:
  112. break;
  113. default:
  114. @@ -2947,6 +2938,8 @@
  115. if (errno == 0)
  116. *p = ep;
  117. return 0;
  118. + case FILE_BEGUID:
  119. + case FILE_LEGUID:
  120. case FILE_GUID:
  121. if (file_parse_guid(*p, m->value.guid) == -1) {
  122. file_magwarn(ms, "Error parsing guid `%s'", *p);
  123. @@ -3422,7 +3415,7 @@
  124. ptr = CAST(uint32_t *, map->p);
  125. if (*ptr != MAGICNO) {
  126. - if (swap4(*ptr) != MAGICNO) {
  127. + if (file_swap4(*ptr) != MAGICNO) {
  128. file_error(ms, 0, "bad magic in `%s'", dbname);
  129. return -1;
  130. }
  131. @@ -3430,7 +3423,7 @@
  132. } else
  133. needsbyteswap = 0;
  134. if (needsbyteswap)
  135. - version = swap4(ptr[1]);
  136. + version = file_swap4(ptr[1]);
  137. else
  138. version = ptr[1];
  139. if (version != VERSIONNO) {
  140. @@ -3443,7 +3436,7 @@
  141. nentries = 0;
  142. for (i = 0; i < MAGIC_SETS; i++) {
  143. if (needsbyteswap)
  144. - map->nmagic[i] = swap4(ptr[i + 2]);
  145. + map->nmagic[i] = file_swap4(ptr[i + 2]);
  146. else
  147. map->nmagic[i] = ptr[i + 2];
  148. if (i != MAGIC_SETS - 1)
  149. @@ -3576,69 +3569,6 @@
  150. bs1(&magic[i]);
  151. }
  152. -#if !defined(HAVE_BYTESWAP_H) && !defined(HAVE_SYS_BSWAP_H)
  153. -/*
  154. - * swap a short
  155. - */
  156. -file_private uint16_t
  157. -swap2(uint16_t sv)
  158. -{
  159. - uint16_t rv;
  160. - uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
  161. - uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
  162. - d[0] = s[1];
  163. - d[1] = s[0];
  164. - return rv;
  165. -}
  166. -
  167. -/*
  168. - * swap an int
  169. - */
  170. -file_private uint32_t
  171. -swap4(uint32_t sv)
  172. -{
  173. - uint32_t rv;
  174. - uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
  175. - uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
  176. - d[0] = s[3];
  177. - d[1] = s[2];
  178. - d[2] = s[1];
  179. - d[3] = s[0];
  180. - return rv;
  181. -}
  182. -
  183. -/*
  184. - * swap a quad
  185. - */
  186. -file_private uint64_t
  187. -swap8(uint64_t sv)
  188. -{
  189. - uint64_t rv;
  190. - uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
  191. - uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
  192. -# if 0
  193. - d[0] = s[3];
  194. - d[1] = s[2];
  195. - d[2] = s[1];
  196. - d[3] = s[0];
  197. - d[4] = s[7];
  198. - d[5] = s[6];
  199. - d[6] = s[5];
  200. - d[7] = s[4];
  201. -# else
  202. - d[0] = s[7];
  203. - d[1] = s[6];
  204. - d[2] = s[5];
  205. - d[3] = s[4];
  206. - d[4] = s[3];
  207. - d[5] = s[2];
  208. - d[6] = s[1];
  209. - d[7] = s[0];
  210. -# endif
  211. - return rv;
  212. -}
  213. -#endif
  214. -
  215. file_protected uintmax_t
  216. file_varint2uintmax_t(const unsigned char *us, int t, size_t *l)
  217. {
  218. @@ -3675,16 +3605,16 @@
  219. file_private void
  220. bs1(struct magic *m)
  221. {
  222. - m->flag = swap2(m->flag);
  223. - m->offset = swap4(CAST(uint32_t, m->offset));
  224. - m->in_offset = swap4(CAST(uint32_t, m->in_offset));
  225. - m->lineno = swap4(CAST(uint32_t, m->lineno));
  226. + m->flag = file_swap2(m->flag);
  227. + m->offset = file_swap4(CAST(uint32_t, m->offset));
  228. + m->in_offset = file_swap4(CAST(uint32_t, m->in_offset));
  229. + m->lineno = file_swap4(CAST(uint32_t, m->lineno));
  230. if (IS_STRING(m->type)) {
  231. - m->str_range = swap4(m->str_range);
  232. - m->str_flags = swap4(m->str_flags);
  233. + m->str_range = file_swap4(m->str_range);
  234. + m->str_flags = file_swap4(m->str_flags);
  235. } else {
  236. - m->value.q = swap8(m->value.q);
  237. - m->num_mask = swap8(m->num_mask);
  238. + m->value.q = file_swap8(m->value.q);
  239. + m->num_mask = file_swap8(m->num_mask);
  240. }
  241. }
  242. @@ -3707,6 +3637,7 @@
  243. return FILE_BADSIZE;
  244. }
  245. }
  246. +
  247. file_protected size_t
  248. file_pstring_get_length(struct magic_set *ms, const struct magic *m,
  249. const char *ss)
  250. --- a/src/file.h
  251. +++ b/src/file.h
  252. @@ -179,7 +179,7 @@
  253. #define MAXstring 128 /* max len of "string" types */
  254. #define MAGICNO 0xF11E041C
  255. -#define VERSIONNO 20
  256. +#define VERSIONNO 21
  257. #define FILE_MAGICSIZE 432
  258. #define FILE_GUID_SIZE sizeof("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
  259. @@ -292,17 +292,19 @@
  260. #define FILE_CLEAR 47
  261. #define FILE_DER 48
  262. #define FILE_GUID 49
  263. -#define FILE_OFFSET 50
  264. -#define FILE_BEVARINT 51
  265. -#define FILE_LEVARINT 52
  266. -#define FILE_MSDOSDATE 53
  267. -#define FILE_LEMSDOSDATE 54
  268. -#define FILE_BEMSDOSDATE 55
  269. -#define FILE_MSDOSTIME 56
  270. -#define FILE_LEMSDOSTIME 57
  271. -#define FILE_BEMSDOSTIME 58
  272. -#define FILE_OCTAL 59
  273. -#define FILE_NAMES_SIZE 60 /* size of array to contain all names */
  274. +#define FILE_LEGUID 50
  275. +#define FILE_BEGUID 51
  276. +#define FILE_OFFSET 52
  277. +#define FILE_BEVARINT 53
  278. +#define FILE_LEVARINT 54
  279. +#define FILE_MSDOSDATE 55
  280. +#define FILE_LEMSDOSDATE 56
  281. +#define FILE_BEMSDOSDATE 57
  282. +#define FILE_MSDOSTIME 58
  283. +#define FILE_LEMSDOSTIME 59
  284. +#define FILE_BEMSDOSTIME 60
  285. +#define FILE_OCTAL 61
  286. +#define FILE_NAMES_SIZE 62 /* size of array to contain all names */
  287. #define IS_STRING(t) \
  288. ((t) == FILE_STRING || \
  289. @@ -557,7 +559,8 @@
  290. file_protected char *file_copystr(char *, size_t, size_t, const char *);
  291. file_protected int file_checkfmt(char *, size_t, const char *);
  292. file_protected size_t file_printedlen(const struct magic_set *);
  293. -file_protected int file_print_guid(char *, size_t, const uint64_t *);
  294. +file_protected int file_print_leguid(char *, size_t, const uint64_t *);
  295. +file_protected int file_print_beguid(char *, size_t, const uint64_t *);
  296. file_protected int file_parse_guid(const char *, uint64_t *);
  297. file_protected int file_replace(struct magic_set *, const char *, const char *);
  298. file_protected int file_printf(struct magic_set *, const char *, ...)
  299. --- a/src/funcs.c
  300. +++ b/src/funcs.c
  301. @@ -31,6 +31,7 @@
  302. #endif /* lint */
  303. #include "magic.h"
  304. +#include "swap.h"
  305. #include <assert.h>
  306. #include <stdarg.h>
  307. #include <stdlib.h>
  308. @@ -934,12 +935,9 @@
  309. return 0;
  310. }
  311. -file_protected int
  312. -file_print_guid(char *str, size_t len, const uint64_t *guid)
  313. +file_private int
  314. +file_print_guid(char *str, size_t len, const struct guid *g)
  315. {
  316. - const struct guid *g = CAST(const struct guid *,
  317. - CAST(const void *, guid));
  318. -
  319. #ifndef WIN32
  320. return snprintf(str, len, "%.8X-%.4hX-%.4hX-%.2hhX%.2hhX-"
  321. "%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX",
  322. @@ -956,6 +954,26 @@
  323. }
  324. file_protected int
  325. +file_print_leguid(char *str, size_t len, const uint64_t *guid)
  326. +{
  327. + const struct guid *g = CAST(const struct guid *,
  328. + CAST(const void *, guid));
  329. + return file_print_guid(str, len, g);
  330. +}
  331. +
  332. +file_protected int
  333. +file_print_beguid(char *str, size_t len, const uint64_t *guid)
  334. +{
  335. + const struct guid *g = CAST(const struct guid *,
  336. + CAST(const void *, guid));
  337. + struct guid gg = *g;
  338. + gg.data1 = file_swap4(gg.data1);
  339. + gg.data2 = file_swap2(gg.data2);
  340. + gg.data3 = file_swap2(gg.data3);
  341. + return file_print_guid(str, len, &gg);
  342. +}
  343. +
  344. +file_protected int
  345. file_pipe_closexec(int *fds)
  346. {
  347. #ifdef __MINGW32__
  348. --- a/src/print.c
  349. +++ b/src/print.c
  350. @@ -227,12 +227,17 @@
  351. case FILE_DER:
  352. (void) fprintf(stderr, "'%s'", m->value.s);
  353. break;
  354. + case FILE_LEGUID:
  355. case FILE_GUID:
  356. - (void) file_print_guid(tbuf, sizeof(tbuf),
  357. + (void) file_print_leguid(tbuf, sizeof(tbuf),
  358. + m->value.guid);
  359. + (void) fprintf(stderr, "%s", tbuf);
  360. + break;
  361. + case FILE_BEGUID:
  362. + (void) file_print_beguid(tbuf, sizeof(tbuf),
  363. m->value.guid);
  364. (void) fprintf(stderr, "%s", tbuf);
  365. break;
  366. -
  367. default:
  368. (void) fprintf(stderr, "*bad type %d*", m->type);
  369. break;
  370. --- a/src/softmagic.c
  371. +++ b/src/softmagic.c
  372. @@ -802,7 +802,13 @@
  373. return -1;
  374. break;
  375. case FILE_GUID:
  376. - (void) file_print_guid(buf, sizeof(buf), ms->ms_value.guid);
  377. + case FILE_LEGUID:
  378. + (void) file_print_leguid(buf, sizeof(buf), ms->ms_value.guid);
  379. + if (file_printf(ms, F(ms, desc, "%s"), buf) == -1)
  380. + return -1;
  381. + break;
  382. + case FILE_BEGUID:
  383. + (void) file_print_beguid(buf, sizeof(buf), ms->ms_value.guid);
  384. if (file_printf(ms, F(ms, desc, "%s"), buf) == -1)
  385. return -1;
  386. break;
  387. @@ -965,6 +971,8 @@
  388. }
  389. break;
  390. + case FILE_BEGUID:
  391. + case FILE_LEGUID:
  392. case FILE_GUID:
  393. o = CAST(int32_t, (ms->offset + 2 * sizeof(uint64_t)));
  394. break;
  395. @@ -1326,6 +1334,8 @@
  396. case FILE_USE:
  397. case FILE_DER:
  398. case FILE_GUID:
  399. + case FILE_LEGUID:
  400. + case FILE_BEGUID:
  401. return 1;
  402. default:
  403. file_magerror(ms, "invalid type %d in mconvert()", m->type);
  404. @@ -1891,6 +1901,8 @@
  405. return 0;
  406. break;
  407. + case FILE_LEGUID:
  408. + case FILE_BEGUID:
  409. case FILE_GUID:
  410. if (OFFSET_OOB(nbytes, offset, 16))
  411. return 0;
  412. @@ -2404,6 +2416,8 @@
  413. return 0;
  414. }
  415. return matched;
  416. + case FILE_BEGUID:
  417. + case FILE_LEGUID:
  418. case FILE_GUID:
  419. l = 0;
  420. v = memcmp(m->value.guid, p->guid, sizeof(p->guid));
  421. --- /dev/null
  422. +++ b/src/swap.c
  423. @@ -0,0 +1,101 @@
  424. +/*
  425. + * Copyright (c) Ian F. Darwin 1986-1995.
  426. + * Software written by Ian F. Darwin and others;
  427. + * maintained 1995-present by Christos Zoulas and others.
  428. + *
  429. + * Redistribution and use in source and binary forms, with or without
  430. + * modification, are permitted provided that the following conditions
  431. + * are met:
  432. + * 1. Redistributions of source code must retain the above copyright
  433. + * notice immediately at the beginning of the file, without modification,
  434. + * this list of conditions, and the following disclaimer.
  435. + * 2. Redistributions in binary form must reproduce the above copyright
  436. + * notice, this list of conditions and the following disclaimer in the
  437. + * documentation and/or other materials provided with the distribution.
  438. + *
  439. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  440. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  441. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  442. + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  443. + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  444. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  445. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  446. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  447. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  448. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  449. + * SUCH DAMAGE.
  450. + */
  451. +/*
  452. + * apprentice - make one pass through /etc/magic, learning its secrets.
  453. + */
  454. +
  455. +#include "file.h"
  456. +
  457. +#ifndef lint
  458. +FILE_RCSID("@(#)$File$")
  459. +#endif /* lint */
  460. +
  461. +#include "swap.h"
  462. +
  463. +#if !defined(HAVE_BYTESWAP_H) && !defined(HAVE_SYS_BSWAP_H)
  464. +/*
  465. + * swap a short
  466. + */
  467. +file_protected uint16_t
  468. +file_swap2(uint16_t sv)
  469. +{
  470. + uint16_t rv;
  471. + uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
  472. + uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
  473. + d[0] = s[1];
  474. + d[1] = s[0];
  475. + return rv;
  476. +}
  477. +
  478. +/*
  479. + * swap an int
  480. + */
  481. +file_protected uint32_t
  482. +file_swap4(uint32_t sv)
  483. +{
  484. + uint32_t rv;
  485. + uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
  486. + uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
  487. + d[0] = s[3];
  488. + d[1] = s[2];
  489. + d[2] = s[1];
  490. + d[3] = s[0];
  491. + return rv;
  492. +}
  493. +
  494. +/*
  495. + * swap a quad
  496. + */
  497. +file_protected uint64_t
  498. +file_swap8(uint64_t sv)
  499. +{
  500. + uint64_t rv;
  501. + uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
  502. + uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
  503. +# if 0
  504. + d[0] = s[3];
  505. + d[1] = s[2];
  506. + d[2] = s[1];
  507. + d[3] = s[0];
  508. + d[4] = s[7];
  509. + d[5] = s[6];
  510. + d[6] = s[5];
  511. + d[7] = s[4];
  512. +# else
  513. + d[0] = s[7];
  514. + d[1] = s[6];
  515. + d[2] = s[5];
  516. + d[3] = s[4];
  517. + d[4] = s[3];
  518. + d[5] = s[2];
  519. + d[6] = s[1];
  520. + d[7] = s[0];
  521. +# endif
  522. + return rv;
  523. +}
  524. +#endif
  525. --- /dev/null
  526. +++ b/src/swap.h
  527. @@ -0,0 +1,48 @@
  528. +/*
  529. + * Copyright (c) Ian F. Darwin 1986-1995.
  530. + * Software written by Ian F. Darwin and others;
  531. + * maintained 1995-present by Christos Zoulas and others.
  532. + *
  533. + * Redistribution and use in source and binary forms, with or without
  534. + * modification, are permitted provided that the following conditions
  535. + * are met:
  536. + * 1. Redistributions of source code must retain the above copyright
  537. + * notice immediately at the beginning of the file, without modification,
  538. + * this list of conditions, and the following disclaimer.
  539. + * 2. Redistributions in binary form must reproduce the above copyright
  540. + * notice, this list of conditions and the following disclaimer in the
  541. + * documentation and/or other materials provided with the distribution.
  542. + *
  543. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  544. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  545. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  546. + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  547. + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  548. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  549. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  550. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  551. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  552. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  553. + * SUCH DAMAGE.
  554. + */
  555. +
  556. +#ifdef HAVE_BYTESWAP_H
  557. +#include <byteswap.h>
  558. +#endif
  559. +#ifdef HAVE_SYS_BSWAP_H
  560. +#include <sys/bswap.h>
  561. +#endif
  562. +
  563. +#if defined(HAVE_BYTESWAP_H)
  564. +#define file_swap2(x) bswap_16(x)
  565. +#define file_swap4(x) bswap_32(x)
  566. +#define swap8(x) bswap_64(x)
  567. +#elif defined(HAVE_SYS_BSWAP_H)
  568. +#define file_swap2(x) bswap16(x)
  569. +#define file_swap4(x) bswap32(x)
  570. +#define file_swap8(x) bswap64(x)
  571. +#else
  572. +file_protected uint16_t file_swap2(uint16_t);
  573. +file_protected uint32_t file_swap4(uint32_t);
  574. +file_protected uint64_t file_swap8(uint64_t);
  575. +#endif