summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/rtkload/read_fd.c
blob: bf40fb30efc165b894046cbcad6b07bd89788380 (plain)
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
60
61
62
63
64
65
66
67
68
69
/* This file has not been tested for ages. */

#include "hfload.h"

#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>

void 
read_struct(void *s, ssize_t size) 
{
        ssize_t real;

        real = read(0, s, size);
        if (size != real) {
                printf("trying to read %d, got %d; dying.\n", size, real);
                exit(1);
        }
        file_offset += real;
}

void
seek_forward(int offset) {
        int dummy, i;
        ssize_t real;

        if (offset % 4 != 0) {
                printf("Can't seek by a non-word aligned amount\n");
                exit(1);
        }
        
        if (offset < file_offset) {
                printf("can't seek backwards\n");
                exit(1);
        }

        for (; offset < file_offset; file_offset += 4) {
                real = read(0, &dummy, 4);
                if (real != 4) {
                        printf("error seeking forward at offset %d\n", file_offset);
                        exit(1);
                }
        }
}

void
copy_to_region(int *addr, ssize_t size) {
        int i, dummy, real;

        printf("copying %x bytes from file offset %x to address %08x\n",
               size, file_offset, addr);

#ifdef FAKE_COPYING
        for (i = 0; i < size; i += 4) {
                read_struct(&dummy, sizeof(int));
        }
#else
        real = read(0, addr, size);
        if (real != size) {
                printf("failed to read %d bytes, exiting\n");
                exit(1);
        }
        file_offset += real;
#endif
}

void
init_read() {
}