Tizen 2.1 base
[platform/core/uifw/ise-engine-sunpinyin.git] / src / slm / tslmendian / writer.cpp
1 #include <arpa/inet.h>
2 #include <cassert>
3 #include <cstring>
4
5 #include "writer.h"
6
7 int
8 get_host_endian()
9 {
10     return htons(0x0001) == 0x0100 ? LITTLE_ENDIAN : BIG_ENDIAN;
11 }
12
13 int
14 parse_endian(const char* arg)
15 {
16     if (!strcmp(arg, "le")) {
17         return LITTLE_ENDIAN;
18     } else if (!strcmp(arg, "be")) {
19         return BIG_ENDIAN;
20     } else {
21         return -1;
22     }
23 }
24
25 const char*
26 endian2str(int endian)
27 {
28     static const char le[] = "little-endian";
29     static const char be[] = "big-endian";
30
31     switch (endian) {
32     case LITTLE_ENDIAN:
33         return le;
34     case BIG_ENDIAN:
35         return be;
36     default:
37         assert(0);
38     }
39     return NULL;
40 }