| 1 |
/* |
| 2 |
* This file is part of libbdplus |
| 3 |
* Copyright (C) 2015 VideoLAN |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library. If not, see |
| 17 |
* <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef FILE_H_ |
| 21 |
#define FILE_H_ |
| 22 |
|
| 23 |
#include "util/attributes.h" |
| 24 |
|
| 25 |
#include "filesystem.h" |
| 26 |
|
| 27 |
#include <stdint.h> |
| 28 |
#include <stddef.h> |
| 29 |
|
| 30 |
#ifdef _WIN32 |
| 31 |
# define DIR_SEP "\\" |
| 32 |
# define DIR_SEP_CHAR '\\' |
| 33 |
#else |
| 34 |
# define DIR_SEP "/" |
| 35 |
# define DIR_SEP_CHAR '/' |
| 36 |
#endif |
| 37 |
|
| 38 |
typedef BDPLUS_FILE_H BD_FILE_H; |
| 39 |
typedef BDPLUS_FILE_OPEN BD_FILE_OPEN; |
| 40 |
|
| 41 |
/* |
| 42 |
* file access |
| 43 |
*/ |
| 44 |
|
| 45 |
static inline void file_close(BD_FILE_H *fp) |
| 46 |
{ |
| 47 |
fp->close(fp); |
| 48 |
} |
| 49 |
|
| 50 |
static inline int64_t file_tell(BD_FILE_H *fp) |
| 51 |
{ |
| 52 |
return fp->tell(fp); |
| 53 |
} |
| 54 |
|
| 55 |
static inline BD_USED int64_t file_seek(BD_FILE_H *fp, int64_t offset, int32_t origin) |
| 56 |
{ |
| 57 |
return fp->seek(fp, offset, origin); |
| 58 |
} |
| 59 |
|
| 60 |
static inline BD_USED size_t file_read(BD_FILE_H *fp, uint8_t *buf, size_t size) |
| 61 |
{ |
| 62 |
return (size_t)fp->read(fp, buf, (int64_t)size); |
| 63 |
} |
| 64 |
|
| 65 |
#define file_open(cfg, fname) (cfg->fopen(cfg->fopen_handle, fname)) |
| 66 |
|
| 67 |
BD_PRIVATE int64_t file_size(BD_FILE_H *fp); |
| 68 |
|
| 69 |
BD_PRIVATE BDPLUS_FILE_OPEN file_open_default(void); |
| 70 |
|
| 71 |
/* |
| 72 |
* directory access |
| 73 |
*/ |
| 74 |
|
| 75 |
typedef struct |
| 76 |
{ |
| 77 |
char d_name[256]; |
| 78 |
} BD_DIRENT; |
| 79 |
|
| 80 |
typedef struct bdplus_dir_s BD_DIR_H; |
| 81 |
struct bdplus_dir_s |
| 82 |
{ |
| 83 |
void* internal; |
| 84 |
void (*close)(BD_DIR_H *dir); |
| 85 |
int (*read)(BD_DIR_H *dir, BD_DIRENT *entry); |
| 86 |
}; |
| 87 |
|
| 88 |
typedef BD_DIR_H* (*BD_DIR_OPEN) (const char* dirname); |
| 89 |
|
| 90 |
#define dir_close(X) X->close(X) |
| 91 |
#define dir_read(X,Y) X->read(X,Y) |
| 92 |
|
| 93 |
BD_PRIVATE BD_DIR_OPEN dir_open_default(void); |
| 94 |
|
| 95 |
/* |
| 96 |
* local filesystem |
| 97 |
*/ |
| 98 |
|
| 99 |
BD_PRIVATE int file_path_exists(const char *path); |
| 100 |
BD_PRIVATE int file_mkdir(const char *dir); |
| 101 |
BD_PRIVATE int file_mkdirs(const char *path); |
| 102 |
|
| 103 |
#endif /* FILE_H_ */ |