-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHexView.c
More file actions
59 lines (52 loc) · 1.33 KB
/
HexView.c
File metadata and controls
59 lines (52 loc) · 1.33 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* HexView.c
* Hex View
*
* Created by Aaron Spiteri on 6/03/11.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include "HexView.h"
/*
*======================================================
* getFileAsLong
*
* Take each character of a file and return it as
* a long value.
*======================================================
*
*/
int getFileAsInt(const char *fileName, int **lary, int *count) {
int fildes = open(fileName, O_RDONLY|O_SHLOCK), err = 0, i = 0, *buffer = calloc(1,sizeof(int)),tmp;
ssize_t rv = 0;
if(fildes == -1){
err = errno;
}
if(err == 0){
do{
tmp = 0;
rv = read(fildes, &tmp, BYTESZ);
if(rv == -1){
err = errno;
}
/* Add new number to array */
else if(rv != 0){
buffer[i ++] = tmp;
buffer = realloc(buffer, (1 + i * sizeof(int)));
/* break loop an error has occurred */
if(buffer == NULL){
err = errno;
rv = 0;
}
}
}
while(rv && rv != -1);
close(fildes);
}
/* return our new pointers */
if(! err){
*(lary) = buffer;
*(count) = i;
}
return err;
}