blob: e671a69847e505110a726d22a4c2c164c8d16da0 (
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
|
#ifndef __STANDALONE__
#include <sys/types.h>
#include <sys/stat.h>
#include "readfs.h"
static int fd = -1;
open_file(fname)
char * fname;
{
if( fd >= 0 ) close(fd);
fd = open(fname, 0);
if( fd >= 0 ) return 0;
return -1;
}
rewind_file()
{
if( fd == -1 ) return -1;
lseek(fd, 0L, 0);
return 0;
}
close_file()
{
if( fd >= 0 ) close(fd);
fd = -1;
}
long
file_length()
{
struct stat st;
if( fd == -1 ) return -1;
if( fstat(fd, &st) < 0 ) return -1;
return st.st_size;
}
read_block(buffer)
char * buffer;
{
int rv;
if( fd == -1 ) return -1;
rv = read(fd, buffer, 1024);
if( rv <= 0 ) return -1;
if( rv < 1024 )
memset(buffer+rv, '\0', 1024-rv);
return 0;
}
#endif
|