Created
January 12, 2013 17:45
-
-
Save panzi/4519534 to your computer and use it in GitHub Desktop.
fourcc as uint32_t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <endian.h> | |
#define _MAGIC_FROM_CHARS(C1,C2,C3,C4) (uint32_t)(((C1) << 24) | ((C2) << 16) | ((C3) << 8) | (C4)) | |
#if __BYTE_ORDER == __LITTLE_ENDIAN | |
# define MAGIC_FROM_CHARS(C1,C2,C3,C4) _MAGIC_FROM_CHARS(C4,C3,C2,C1) | |
#elif __BYTE_ORDER == __BIG_ENDIAN | |
# define MAGIC_FROM_CHARS(C1,C2,C3,C4) _MAGIC_FROM_CHARS(C1,C2,C3,C4) | |
#elif __BYTE_ORDER == __PDP_ENDIAN | |
# define MAGIC_FROM_CHARS(C1,C2,C3,C4) _MAGIC_FROM_CHARS(C3,C4,C1,C2) | |
#else | |
# error unsupported byte order | |
#endif | |
#define MAGIC(S) MAGIC_FROM_CHARS((S)[0], (S)[1], (S)[2], (S)[3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment