So I have a new and exciting question that I would dearly like answered. So I'm writing a file compressor, basically a tar and in all honesty, that code seems to be going quite well. What I'm getting stuck on right now is an additional feature that is required of the project. We need to be able to produce the binary files as if they were made on a little endian machine. I've created a header file that I've included into my code that should do the bit swapping for me. It follows thus:
#ifndef MYLIB_H
#define MYLIB_H
#define BITS_PER_BYTE 8
#define true 1
#define false 0
typedef unsigned char uchar;
typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned short ushort;
#ifdef LITTLE_ENDIAN
#define SwapULong(val) (val << 24 | (val << 8 & 0xFF0000) | (val >> 8 & 0xFF00) | val >> 24 & 0xFF)
#define SwapUShort(val) (val << BITS_PER_BYTE | val >> BITS_PER_BYTE)
#else
#define SwapULong(val) (val)
#define SwapUShort(val) (val)
#endif
#endif
So when I compile with gcc and run the program there are no errors. When I do a hexdump -C of the output however, the output is still in Big Endian Order!
I then tried compiling with the -E flag and I got a bunch of lines saying that
./compress line #: typedef: command not found
which became
./compress line #: __extension__ : command not found
until the final lines of the terminal output showed
./compress line 86: syntax error near unexpected '}' token
./compress line 86: __extension__ typedef struct { int __val[2]; } __fsid_t;
So any ideas what might be causing this for me?
Any help would be appreciated.