aboutsummaryrefslogtreecommitdiff
path: root/arch/casiowin/fxlib/include/fxlib/file.h
blob: c72d640f9fe4d5dfdaa7cf09f26d0dd18d353bc7 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* ****************************************************************************
 * fxlib/file.h -- fxlib's file management.
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of the 'casiowin/fxlib' module,
 * in libcarrot, an experimental modular libc project.
 *
 * This file is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Lesser Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
#include <fxlib/cdefs.h>
#include <filebios.h>
#define MAX_PATH 50 /* a quick estimation */
__BEGIN_NAMESPACE_FXLIB
__BEGIN_DECLS

/* ************************************************************************* */
/*  Open and close files                                                     */
/* ************************************************************************* */
/* Identify the device:
 * Tries to detect the device referenced by `filename`, skips first
 * reverse solidus if present.
 *
 * Returns the memory type (see the `DEVICE_TYPE` enumeration),
 * or the error (one of the `IML_FILEERR_*` constants). */

#if __USE_FXLIB_UNOFFICIAL
extern __nonnull(1, __filename)
int Bfile_identify_device_OS _OF((const FONTCHARACTER *__filename))
	__THROW;
#endif

/* Open a handle; for `Bfile_OpenFile_OS`, `mode2` was probably reserved for a
 * future use, and should be set to zero. */

extern __nonnull(1, __filename) __wur
int Bfile_OpenFile    _OF((const FONTCHARACTER *__filename, int __mode))
	__THROW;
#if __USE_FXLIB_UNOFFICIAL
extern __nonnull(1, __filename)
int Bfile_OpenFile_OS _OF((const FONTCHARACTER *__filename, int __mode,
	int __mode2)) __THROW;
#endif

/* Open a handle on the main memory (MCS): */

extern __nonnull(1, __name) __wur
int Bfile_OpenMainMemory _OF((const unsigned char *__name))
	__THROW;

/* Close a handle; should not be used to close a main memory handle! */

extern int Bfile_CloseFile    _OF((int __HANDLE)) __THROW;
#if __USE_FXLIB_UNOFFICIAL
extern int Bfile_CloseFile_OS _OF((int __HANDLE)) __THROW;
#endif
/* ************************************************************************* */
/*  Basic interactions on the file                                           */
/* ************************************************************************* */
/* Read, write, seek: */

extern __nonnull(2, __buf)
int Bfile_ReadFile    _OF((int __HANDLE, void *__buf, int __size,
	int __readpos)) __THROW;
#if __USE_FXLIB_UNOFFICIAL
extern __nonnull(2, __buf)
int Bfile_ReadFile_OS _OF((int __HANDLE, void *__buf, int __size,
	int __readpos)) __THROW;
#endif

extern __nonnull(2, __buf)
int Bfile_WriteFile    _OF((int __HANDLE, const void *__buf, int __size))
	__THROW;
#if __USE_FXLIB_UNOFFICIAL
extern __nonnull(2, __buf)
int Bfile_WriteFile_OS _OF((int __HANDLE, const void *__buf, int __size))
	__THROW;
#endif

extern int Bfile_SeekFile    _OF((int __HANDLE, int __pos)) __THROW;
#if __USE_FXLIB_UNOFFICIAL
extern int Bfile_SeekFile_OS _OF((int __HANDLE, int __pos)) __THROW;
#endif

/* Get the file size: */

#if __USE_FXLIB_UNOFFICIAL
extern       int Bfile_GetFileSize    _OF((int __HANDLE)) __THROW;
extern __wur int Bfile_GetFileSize_OS _OF((int __HANDLE)) __THROW;
#endif
/* ************************************************************************* */
/*  Interact with storage devices                                            */
/* ************************************************************************* */
/* Create files or directories: */

extern __nonnull(1, __filename)
int Bfile_CreateFile       _OF((const FONTCHARACTER *__filename,
	int __size)) __THROW;
extern __nonnull(1, __pathname)
int Bfile_CreateDirectory  _OF((const FONTCHARACTER *__pathname,
	int __size)) __THROW;
extern __nonnull(1, __name)
int Bfile_CreateMainMemory _OF((const unsigned char *__name))
	__THROW;

/* Rename a file: */

extern __nonnull(1, __oldname) __nonnull(2, __newname)
int Bfile_RenameEntry      _OF((const FONTCHARACTER *__oldname,
	const FONTCHARACTER *__newname)) __THROW;
extern __nonnull(1, __oldname) __nonnull(2, __newname)
int Bfile_RenameMainMemory _OF((const unsigned char *__oldname,
	const unsigned char *__newname)) __THROW;

/* Delete files: */

extern __nonnull(1, __filename)
int Bfile_DeleteEntry      _OF((const FONTCHARACTER *__filename,
	int __mode)) __THROW;
extern __nonnull(1, __filename)
int Bfile_DeleteFile       _OF((const FONTCHARACTER *__filename)) __THROW;
extern __nonnull(1, __pathname)
int Bfile_DeleteDirectory  _OF((const FONTCHARACTER *__pathname)) __THROW;
extern __nonnull(1, __name)
int Bfile_DeleteMainMemory _OF((const unsigned char *__name)) __THROW;

/* Get the free space on a media */

extern __nonnull(2, __freebytes)
int Bfile_GetMediaFree    _OF((enum DEVICE_TYPE __devicetype,
	int *__freebytes)) __THROW;
extern __nonnull(1, __media) __nonnull(2, __freebytes)
int Bfile_GetMediaFree_OS _OF((FONTCHARACTER *__media, int *__freebytes))
	__THROW;

/* Find elements on a storage device: */

extern __nonnull(1, __pathname) __nonnull(2, __FindHandle)
	__nonnull(3, __foundfile) __nonnull(4, __fileinfo)
int Bfile_FindFirst _OF((const FONTCHARACTER *__pathname,
	int *__FindHandle, FONTCHARACTER *__foundfile, FILE_INFO *__fileinfo))
	__THROW;
extern __nonnull(2, __foundfile) __nonnull(3, __fileinfo)
int Bfile_FindNext  _OF((int __FindHandle, FONTCHARACTER *__foundfile,
	FILE_INFO *__fileinfo)) __THROW;
extern int Bfile_FindClose _OF((int __FindHandle)) __THROW;

__END_DECLS
__END_NAMESPACE_FXLIB