1 |
/* |
2 |
* include needed system headers |
3 |
*/ |
4 |
#include <stdio.h> /* include standard i/o library */ |
5 |
#include <stdlib.h> /* include standard library */ |
6 |
#include <string.h> /* include string library */ |
7 |
#include <unistd.h> /* include unix standard library */ |
8 |
#include <sys/types.h> /* */ |
9 |
#include <sys/stat.h> /* */ |
10 |
#include <fcntl.h> /* */ |
11 |
#include <errno.h> /* error simbol definitions */ |
12 |
#include <time.h> /* system time definitions */ |
13 |
#include <math.h> /* math library */ |
14 |
|
15 |
|
16 |
/** |
17 |
* Read nbytes at position p of buffer, and fill value |
18 |
*/ |
19 |
|
20 |
void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value) |
21 |
|
22 |
{ |
23 |
char bytes[4]; |
24 |
int i; |
25 |
|
26 |
for(i=0; i<*nbytes; i++) { |
27 |
bytes[i] = *(buffer+(*p)-1+i); |
28 |
} |
29 |
if(*nbytes == 1) |
30 |
*value = 0x000000ff & bytes[0]; |
31 |
if(*nbytes == 2) |
32 |
*value = ((bytes[0]<<8)&0x0000ff00) | |
33 |
(bytes[1]&0x000000ff); |
34 |
if(*nbytes == 4) |
35 |
*value = ((bytes[0]<<24)&0xff000000) | |
36 |
((bytes[1]<<16)&0x00ff0000) | |
37 |
((bytes[2]<<8)&0x0000ff00) | |
38 |
(bytes[3]&0x000000ff); |
39 |
|
40 |
*p += *nbytes; |
41 |
|
42 |
return; |
43 |
} |