File: endian.c

package info (click to toggle)
dbf2mysql 1.14a-3.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 176 kB
  • ctags: 173
  • sloc: ansic: 1,972; sh: 297; makefile: 93
file content (45 lines) | stat: -rw-r--r-- 824 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* Maarten Boekhold (boekhold@cindy.et.tudelft.nl) oktober 1995 */

#include <sys/types.h>
#include "dbf.h"
/*
 * routine to change little endian long to host long
 */
long get_long(u_char *cp)
{
        long ret;

        ret = *cp++;
        ret += ((*cp++)<<8);
        ret += ((*cp++)<<16);
        ret += ((*cp++)<<24);

        return ret;
}

void put_long(u_char *cp, long lval)
{
        cp[0] = lval & 0xff;
        cp[1] = (lval >> 8) & 0xff;
        cp[2] = (lval >> 16) & 0xff;
        cp[3] = (lval >> 24) & 0xff;
}

/*
 * routine to change little endian short to host short
 */
short get_short(u_char *cp)
{
        short ret;

        ret = *cp++;
        ret += ((*cp++)<<8);

        return ret;
}

void put_short(u_char *cp, short sval)
{
        cp[0] = sval & 0xff;
        cp[1] = (sval >> 8) & 0xff;
}