1 /*
2  *      Small C+ Library
3  *
4  *      fnctl.h - low level file routines
5  *
6  *      djm 27/4/99
7  *
8  *	$Id: fcntl.h,v 1.21 2016-07-14 17:44:17 pauloscustodio Exp $
9  */
10 
11 
12 #ifndef __FCNTL_H__
13 #define __FCNTL_H__
14 
15 #include <sys/compiler.h>
16 #include <sys/types.h>
17 
18 
19 #define O_RDONLY  0
20 #define O_WRONLY  1
21 #define O_RDWR    2
22 #define O_APPEND  256
23 #define O_TRUNC   512
24 #define O_CREAT   1024
25 
26 #define SEEK_SET 0
27 #define SEEK_CUR 1
28 #define SEEK_END 2
29 
30 
31 /* O_BINARY has no significence */
32 #define O_BINARY  0
33 
34 typedef int mode_t;
35 
36 
37 extern int __LIB__ open(const char *name, int flags, mode_t mode) __smallc;
38 extern int __LIB__ creat(const char *name, mode_t mode) __smallc;
39 extern int __LIB__ close(int fd);
40 extern ssize_t __LIB__ read(int fd, void *ptr, size_t len) __smallc;
41 extern ssize_t __LIB__ write(int fd, const void *ptr, size_t len) __smallc;
42 extern long __LIB__ __SAVEFRAME__ lseek(int fd,long posn, int whence) __smallc;
43 
44 extern int __LIB__ readbyte(int fd) __z88dk_fastcall;
45 extern int __LIB__ writebyte(int fd, int c) __smallc;
46 
47 
48 /* mkdir is defined in sys/stat.h */
49 /* extern int __LIB__ mkdir(char *, int mode); */
50 
51 extern char __LIB__ *getcwd(char *buf, size_t maxlen) __smallc;
52 extern int __LIB__ chdir(const char *dir) __smallc;
53 extern char __LIB__ *getwd(char *buf);
54 
55 /* Following two only implemented for Sprinter ATM (20.11.2002) */
56 extern int  __LIB__ rmdir(const char *);
57 
58 
59 
60 
61 /* ********************************************************* */
62 
63 /*
64 * Default block size for "gendos.lib"
65 * every single block (up to 36) is written in a separate file
66 * the bigger RND_BLOCKSIZE, bigger can be the output file size,
67 * but this comes at the cost of the malloc'd space for the internal buffer.
68 * The current block size is kept in a control block (just the RND_FILE structure saved in a separate file),
69 * so changing this value at runtime before creating a file is perfectly legal.
70 
71 In the target's CRT0 stubs the following lines must exist:
72 
73 PUBLIC _RND_BLOCKSIZE
74 _RND_BLOCKSIZE:	defw	1000
75 
76 */
77 
78 extern unsigned int   RND_BLOCKSIZE;
79 
80 /* Used in the generic random file access library only */
81 /* file will be split into blocks */
82 
83 struct RND_FILE {
84 	char    name_prefix;   /* block name, including prefix char */
85 	char    name[15];         /* file name */
86 	i16_t	blocksize;
87 	unsigned char *blockptr;
88 	long    size;             /* file size */
89 	long    position;         /* current position in file */
90 	i16_t	pos_in_block;
91 	mode_t  mode;
92 };
93 
94 
95 /* The following three functions are target specific */
96 extern int  __LIB__ rnd_loadblock(char *name, void *loadstart, size_t len) __smallc;
97 extern int  __LIB__ rnd_saveblock(char *name, void *loadstart, size_t len) __smallc;
98 extern int  __LIB__  rnd_erase(char *name) __z88dk_fastcall;
99 
100 /* ********************************************************* */
101 
102 #endif /* _FCNTL_H */
103