kfile.h
Go to the documentation of this file.00001
00097 #ifndef KERN_KFILE_H
00098 #define KERN_KFILE_H
00099
00100 #include <cfg/compiler.h>
00101 #include <cfg/debug.h>
00102 #include <cfg/macros.h>
00103
00104
00105 struct KFile;
00106
00107 typedef int32_t kfile_off_t;
00108
00114 typedef enum KSeekMode
00115 {
00116 KSM_SEEK_SET,
00117 KSM_SEEK_CUR,
00118 KSM_SEEK_END,
00119 } KSeekMode;
00120
00133 typedef size_t (*ReadFunc_t) (struct KFile *fd, void *buf, size_t size);
00134
00139 typedef size_t (*WriteFunc_t) (struct KFile *fd, const void *buf, size_t size);
00140
00145 typedef kfile_off_t (*SeekFunc_t) (struct KFile *fd, kfile_off_t offset, KSeekMode whence);
00146
00151 typedef struct KFile * (*ReOpenFunc_t) (struct KFile *fd);
00152
00157 typedef int (*CloseFunc_t) (struct KFile *fd);
00158
00163 typedef int (*FlushFunc_t) (struct KFile *fd);
00164
00169 typedef int (*ErrorFunc_t) (struct KFile *fd);
00170
00174 typedef void (*ClearErrFunc_t) (struct KFile *fd);
00175
00176
00184 typedef struct KFile
00185 {
00186 ReadFunc_t read;
00187 WriteFunc_t write;
00188 ReOpenFunc_t reopen;
00189 CloseFunc_t close;
00190 SeekFunc_t seek;
00191 FlushFunc_t flush;
00192 ErrorFunc_t error;
00193 ClearErrFunc_t clearerr;
00194 DB(id_t _type);
00195
00196
00197 kfile_off_t seek_pos;
00198 kfile_off_t size;
00199 } KFile;
00200
00204 kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence);
00205
00209 struct KFile * kfile_genericReopen(struct KFile *fd);
00210
00211 int kfile_genericClose(struct KFile *fd);
00212
00213 int kfile_putc(int c, struct KFile *fd);
00214 int kfile_getc(struct KFile *fd);
00215 int kfile_printf(struct KFile *fd, const char *format, ...);
00216 int kfile_print(struct KFile *fd, const char *s);
00217 int kfile_gets(struct KFile *fd, char *buf, int size);
00218 int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo);
00219
00225 INLINE size_t kfile_read(struct KFile *fd, void *buf, size_t size)
00226 {
00227 ASSERT(fd->read);
00228 return fd->read(fd, buf, size);
00229 }
00230
00231 INLINE size_t kfile_write(struct KFile *fd, const void *buf, size_t size)
00232 {
00233 ASSERT(fd->write);
00234 return fd->write(fd, buf, size);
00235 }
00236
00237 INLINE KFile * kfile_reopen(struct KFile *fd)
00238 {
00239 ASSERT(fd->reopen);
00240 return fd->reopen(fd);
00241 }
00242
00243 INLINE int kfile_close(struct KFile *fd)
00244 {
00245 ASSERT(fd->close);
00246 return fd->close(fd);
00247 }
00248
00249 INLINE kfile_off_t kfile_seek(struct KFile *fd, kfile_off_t offset, KSeekMode whence)
00250 {
00251 ASSERT(fd->seek);
00252 return fd->seek(fd, offset, whence);
00253 }
00254
00255 INLINE int kfile_flush(struct KFile *fd)
00256 {
00257 ASSERT(fd->flush);
00258 return fd->flush(fd);
00259 }
00260
00261 INLINE int kfile_error(struct KFile *fd)
00262 {
00263 ASSERT(fd->error);
00264 return fd->error(fd);
00265 }
00266
00267 INLINE void kfile_clearerr(struct KFile *fd)
00268 {
00269 ASSERT(fd->clearerr);
00270 fd->clearerr(fd);
00271 }
00272
00273
00277 int kfile_testSetUp(void);
00278 int kfile_testRun(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size);
00279 int kfile_testTearDown(void);
00280
00281 #endif