-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsepolicy_data.c
More file actions
50 lines (46 loc) · 974 Bytes
/
sepolicy_data.c
File metadata and controls
50 lines (46 loc) · 974 Bytes
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
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int ret;
int fd;
int size;
unsigned char *buf;
unsigned char *ch;
int i;
if (argc < 2)
return -1;
fd = open(argv[1], O_RDONLY);
if (fd == -1) {
error(-1, errno, "%s open failed.", argv[1]);
}
size = lseek(fd, 0, SEEK_END);
buf = (unsigned char *)malloc(size);
if (!buf)
error(-1, errno, "malloc faild.");
ret = lseek(fd, 0, SEEK_SET);
if (ret == -1)
error(-1, errno, "%s lseek failed.", argv[1]);
ret = read(fd, buf, size);
if (ret != size)
error(-1, errno, "%s read failed.", argv[1]);
printf("unsigned char zte_sepolicy_data[] = {\n");
ch = buf;
for (i = 0; i < size - 1; i++) {
printf("0x%02x,", *ch);
ch++;
if ((i + 1) % 20 == 0)
printf("\n");
}
printf("0x%02x", *ch);
printf("};");
free(buf);
return 0;
}