forked from redis/redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
183 additions
and
65 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Toggle the 16 bit unsigned integer pointed by *p from little endian to | ||
* big endian */ | ||
void memrev16(void *p) { | ||
unsigned char *x = p, t; | ||
|
||
t = x[0]; | ||
x[0] = x[1]; | ||
x[1] = t; | ||
} | ||
|
||
/* Toggle the 32 bit unsigned integer pointed by *p from little endian to | ||
* big endian */ | ||
void memrev32(void *p) { | ||
unsigned char *x = p, t; | ||
|
||
t = x[0]; | ||
x[0] = x[3]; | ||
x[3] = t; | ||
t = x[1]; | ||
x[1] = x[2]; | ||
x[2] = t; | ||
} | ||
|
||
/* Toggle the 64 bit unsigned integer pointed by *p from little endian to | ||
* big endian */ | ||
void memrev64(void *p) { | ||
unsigned char *x = p, t; | ||
|
||
t = x[0]; | ||
x[0] = x[7]; | ||
x[7] = t; | ||
t = x[1]; | ||
x[1] = x[6]; | ||
x[6] = t; | ||
t = x[2]; | ||
x[2] = x[5]; | ||
x[5] = t; | ||
t = x[3]; | ||
x[3] = x[4]; | ||
x[4] = t; | ||
} | ||
|
||
#ifdef TESTMAIN | ||
#include <stdio.h> | ||
|
||
int main(void) { | ||
char buf[32]; | ||
|
||
sprintf(buf,"ciaoroma"); | ||
memrev16(buf); | ||
printf("%s\n", buf); | ||
|
||
sprintf(buf,"ciaoroma"); | ||
memrev32(buf); | ||
printf("%s\n", buf); | ||
|
||
sprintf(buf,"ciaoroma"); | ||
memrev64(buf); | ||
printf("%s\n", buf); | ||
|
||
return 0; | ||
} | ||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef __ENDIAN_H | ||
#define __ENDIAN_H | ||
|
||
void memrev16(void *p); | ||
void memrev32(void *p); | ||
void memrev64(void *p); | ||
|
||
/* variants of the function doing the actual convertion only if the target | ||
* host is big endian */ | ||
#if (BYTE_ORDER == LITTLE_ENDIAN) | ||
#define memrev16ifbe(p) | ||
#define memrev32ifbe(p) | ||
#define memrev64ifbe(p) | ||
#else | ||
#define memrev16ifbe(p) memrev16(p) | ||
#define memrev32ifbe(p) memrev32(p) | ||
#define memrev64ifbe(p) memrev64(p) | ||
#endif | ||
|
||
#endif |
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
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
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
Oops, something went wrong.