Reverse memory bytes if arch is little endian. Given the conceptual * simplicity of the Lua build system we prefer check for endianess at runtime. * The performance difference should be acceptable. */
| 67 | * simplicity of the Lua build system we prefer check for endianess at runtime. |
| 68 | * The performance difference should be acceptable. */ |
| 69 | void memrevifle(void *ptr, size_t len) { |
| 70 | unsigned char *p = (unsigned char *)ptr, |
| 71 | *e = (unsigned char *)p+len-1, |
| 72 | aux; |
| 73 | int test = 1; |
| 74 | unsigned char *testp = (unsigned char*) &test; |
| 75 | |
| 76 | if (testp[0] == 0) return; /* Big endian, nothing to do. */ |
| 77 | len /= 2; |
| 78 | while(len--) { |
| 79 | aux = *p; |
| 80 | *p = *e; |
| 81 | *e = aux; |
| 82 | p++; |
| 83 | e--; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /* ---------------------------- String buffer ---------------------------------- |
| 88 | * This is a simple implementation of string buffers. The only operation |
no outgoing calls
no test coverage detected