Skip to content
Snippets Groups Projects
Verified Commit 8ea2dbd4 authored by rahix's avatar rahix
Browse files

feat(api): Rename file functions to epic_file_*


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 03994ea7
No related branches found
No related tags found
No related merge requests found
...@@ -451,8 +451,8 @@ API(API_LIGHT_SENSOR_STOP, int epic_light_sensor_stop()); ...@@ -451,8 +451,8 @@ API(API_LIGHT_SENSOR_STOP, int epic_light_sensor_stop());
/** /**
* File * File
* ==== * ====
* Except for :c:func:`epic_open`, which models C stdio's ``fopen`` function, * Except for :c:func:`epic_file_open`, which models C stdio's ``fopen``
* ``close``, ``read`` and ``write`` model `close(2)`_, `read(2)`_ and * function, ``close``, ``read`` and ``write`` model `close(2)`_, `read(2)`_ and
* `write(2)`_. All file-related functions return >= ``0`` on success and * `write(2)`_. All file-related functions return >= ``0`` on success and
* ``-Exyz`` on failure, with error codes from errno.h (``EIO``, ``EINVAL`` * ``-Exyz`` on failure, with error codes from errno.h (``EIO``, ``EINVAL``
* etc.) * etc.)
...@@ -465,23 +465,23 @@ API(API_LIGHT_SENSOR_STOP, int epic_light_sensor_stop()); ...@@ -465,23 +465,23 @@ API(API_LIGHT_SENSOR_STOP, int epic_light_sensor_stop());
/** */ /** */
API( API(
API_FILE_OPEN, API_FILE_OPEN,
int32_t epic_open(const char* filename, const char* modeString) int32_t epic_file_open(const char* filename, const char* modeString)
); );
/** */ /** */
API(API_FILE_CLOSE, int32_t epic_close(int32_t fd)); API(API_FILE_CLOSE, int32_t epic_file_close(int32_t fd));
/** */ /** */
API(API_FILE_READ, int32_t epic_read(int32_t fd, void* buf, uint32_t nbytes)); API(API_FILE_READ, int32_t epic_file_read(int32_t fd, void* buf, uint32_t nbytes));
/** */ /** */
API( API(
API_FILE_WRITE, API_FILE_WRITE,
int32_t epic_write(int32_t fd, const void* buf, uint32_t nbytes) int32_t epic_file_write(int32_t fd, const void* buf, uint32_t nbytes)
); );
/** */ /** */
API(API_FILE_FLUSH, int32_t epic_flush(int32_t fd)); API(API_FILE_FLUSH, int32_t epic_file_flush(int32_t fd));
/** */ /** */
enum epic_stat_type { enum epic_stat_type {
...@@ -510,6 +510,6 @@ typedef struct epic_stat_t { ...@@ -510,6 +510,6 @@ typedef struct epic_stat_t {
* *
* :return: `0` on success, negative on error * :return: `0` on success, negative on error
*/ */
API(API_FILE_STAT, int32_t epic_stat(const char* path, epic_stat_t* stat)); API(API_FILE_STAT, int32_t epic_file_stat(const char* path, epic_stat_t* stat));
#endif /* _EPICARDIUM_H */ #endif /* _EPICARDIUM_H */
...@@ -203,7 +203,7 @@ int get_fat_object(int i, enum FatObjectType expected, struct FatObject **res) ...@@ -203,7 +203,7 @@ int get_fat_object(int i, enum FatObjectType expected, struct FatObject **res)
return 0; return 0;
} }
int32_t epic_open(const char *filename, const char *modeString) int32_t epic_file_open(const char *filename, const char *modeString)
{ {
struct FatObject *o = NULL; struct FatObject *o = NULL;
const char *mode_s = modeString; const char *mode_s = modeString;
...@@ -255,7 +255,7 @@ int32_t epic_open(const char *filename, const char *modeString) ...@@ -255,7 +255,7 @@ int32_t epic_open(const char *filename, const char *modeString)
return i; return i;
} }
int32_t epic_close(int32_t fd) int32_t epic_file_close(int32_t fd)
{ {
int res; int res;
struct FatObject *o; struct FatObject *o;
...@@ -273,7 +273,7 @@ int32_t epic_close(int32_t fd) ...@@ -273,7 +273,7 @@ int32_t epic_close(int32_t fd)
return 0; return 0;
} }
int32_t epic_read(int32_t fd, void *buf, uint32_t nbytes) int32_t epic_file_read(int32_t fd, void *buf, uint32_t nbytes)
{ {
unsigned int nread = 0; unsigned int nread = 0;
...@@ -292,7 +292,7 @@ int32_t epic_read(int32_t fd, void *buf, uint32_t nbytes) ...@@ -292,7 +292,7 @@ int32_t epic_read(int32_t fd, void *buf, uint32_t nbytes)
return nread; return nread;
} }
int32_t epic_write(int32_t fd, const void *buf, uint32_t nbytes) int32_t epic_file_write(int32_t fd, const void *buf, uint32_t nbytes)
{ {
unsigned int nwritten = 0; unsigned int nwritten = 0;
...@@ -310,7 +310,7 @@ int32_t epic_write(int32_t fd, const void *buf, uint32_t nbytes) ...@@ -310,7 +310,7 @@ int32_t epic_write(int32_t fd, const void *buf, uint32_t nbytes)
return nwritten; return nwritten;
} }
int32_t epic_flush(int32_t fd) int32_t epic_file_flush(int32_t fd)
{ {
int res; int res;
struct FatObject *o; struct FatObject *o;
...@@ -326,7 +326,7 @@ int32_t epic_flush(int32_t fd) ...@@ -326,7 +326,7 @@ int32_t epic_flush(int32_t fd)
return 0; return 0;
} }
int32_t epic_stat(const char *filename, epic_stat_t *stat) int32_t epic_file_stat(const char *filename, epic_stat_t *stat)
{ {
int res; int res;
FILINFO finfo; FILINFO finfo;
......
...@@ -60,7 +60,7 @@ STATIC mp_uint_t ...@@ -60,7 +60,7 @@ STATIC mp_uint_t
file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode)
{ {
pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in); pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
int res = epic_read(self->fd, buf, size); int res = epic_file_read(self->fd, buf, size);
if (res < 0) { if (res < 0) {
*errcode = -res; *errcode = -res;
return MP_STREAM_ERROR; return MP_STREAM_ERROR;
...@@ -72,7 +72,7 @@ STATIC mp_uint_t ...@@ -72,7 +72,7 @@ STATIC mp_uint_t
file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode)
{ {
pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in); pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
int res = epic_write(self->fd, buf, size); int res = epic_file_write(self->fd, buf, size);
if (res < 0) { if (res < 0) {
*errcode = -res; *errcode = -res;
return MP_STREAM_ERROR; return MP_STREAM_ERROR;
...@@ -96,14 +96,14 @@ file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) ...@@ -96,14 +96,14 @@ file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode)
int res; int res;
switch (request) { switch (request) {
case MP_STREAM_FLUSH: case MP_STREAM_FLUSH:
res = epic_flush(self->fd); res = epic_file_flush(self->fd);
if (res < 0) { if (res < 0) {
*errcode = -res; *errcode = -res;
return MP_STREAM_ERROR; return MP_STREAM_ERROR;
} }
return 0; return 0;
case MP_STREAM_CLOSE: case MP_STREAM_CLOSE:
res = epic_close(self->fd); res = epic_file_close(self->fd);
if (res < 0) { if (res < 0) {
*errcode = -res; *errcode = -res;
return MP_STREAM_ERROR; return MP_STREAM_ERROR;
...@@ -170,7 +170,7 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args) ...@@ -170,7 +170,7 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args)
o->base.type = type; o->base.type = type;
const char *fname = mp_obj_str_get_str(args[0].u_obj); const char *fname = mp_obj_str_get_str(args[0].u_obj);
int res = epic_open(fname, modeString); int res = epic_file_open(fname, modeString);
if (res < 0) { if (res < 0) {
m_del_obj(pyb_file_obj_t, o); m_del_obj(pyb_file_obj_t, o);
mp_raise_OSError(-res); mp_raise_OSError(-res);
......
...@@ -21,7 +21,7 @@ STATIC mp_uint_t mp_reader_epicfat_readbyte(void *data) ...@@ -21,7 +21,7 @@ STATIC mp_uint_t mp_reader_epicfat_readbyte(void *data)
if (reader->len == 0) { if (reader->len == 0) {
return MP_READER_EOF; return MP_READER_EOF;
} else { } else {
int n = epic_read( int n = epic_file_read(
reader->fd, reader->buf, sizeof(reader->buf) reader->fd, reader->buf, sizeof(reader->buf)
); );
if (n <= 0) { if (n <= 0) {
...@@ -38,21 +38,21 @@ STATIC mp_uint_t mp_reader_epicfat_readbyte(void *data) ...@@ -38,21 +38,21 @@ STATIC mp_uint_t mp_reader_epicfat_readbyte(void *data)
STATIC void mp_reader_epicfat_close(void *data) STATIC void mp_reader_epicfat_close(void *data)
{ {
mp_reader_epicfat_t *reader = (mp_reader_epicfat_t *)data; mp_reader_epicfat_t *reader = (mp_reader_epicfat_t *)data;
epic_close(reader->fd); epic_file_close(reader->fd);
m_del_obj(mp_reader_epicfat_t, reader); m_del_obj(mp_reader_epicfat_t, reader);
} }
void mp_reader_new_file(mp_reader_t *reader, const char *filename) void mp_reader_new_file(mp_reader_t *reader, const char *filename)
{ {
int fd = epic_open(filename, "r"); int fd = epic_file_open(filename, "r");
if (fd < 0) { if (fd < 0) {
mp_raise_OSError(-fd); mp_raise_OSError(-fd);
} }
mp_reader_epicfat_t *rp = m_new_obj(mp_reader_epicfat_t); mp_reader_epicfat_t *rp = m_new_obj(mp_reader_epicfat_t);
rp->fd = fd; rp->fd = fd;
int n = epic_read(rp->fd, rp->buf, sizeof(rp->buf)); int n = epic_file_read(rp->fd, rp->buf, sizeof(rp->buf));
if (n < 0) { if (n < 0) {
epic_close(fd); epic_file_close(fd);
} }
rp->len = n; rp->len = n;
rp->pos = 0; rp->pos = 0;
...@@ -72,7 +72,7 @@ mp_import_stat_t mp_import_stat(const char *path) ...@@ -72,7 +72,7 @@ mp_import_stat_t mp_import_stat(const char *path)
{ {
struct epic_stat_t stat; struct epic_stat_t stat;
if (epic_stat(path, &stat) == 0) { if (epic_file_stat(path, &stat) == 0) {
if (stat.type == EPICSTAT_FILE) { if (stat.type == EPICSTAT_FILE) {
return MP_IMPORT_STAT_FILE; return MP_IMPORT_STAT_FILE;
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment