Remove mg_file_size()

This commit is contained in:
Sergey Lyubka 2021-07-23 20:18:34 +01:00
parent 529faa1172
commit 328a87b02a
5 changed files with 8 additions and 32 deletions

View File

@ -1115,14 +1115,6 @@ Read file contents into a nul-terminated malloc-ed string. It is a caller's
responsibility to free() a returned pointer. If `sizep` is not NULL, it will responsibility to free() a returned pointer. If `sizep` is not NULL, it will
return a file size in bytes. return a file size in bytes.
### mg\_file\_size()
```c
size_t mg_file_size(const char *path);
```
Return file size, or 0 on failure. Empty files also report 0 length.
### mg\_file\_write() ### mg\_file\_write()
```c ```c

View File

@ -3921,21 +3921,14 @@ int mg_stat(const char *path, mg_stat_t *st) {
#endif #endif
} }
int64_t mg_file_size(const char *path) {
#if MG_ARCH == MG_ARCH_FREERTOS_TCP && defined(MG_ENABLE_FF)
struct FF_STAT st;
return ff_stat(path, &st) == 0 ? st.st_size : 0;
#else
mg_stat_t st;
return mg_stat(path, &st) == 0 ? st.st_size : 0;
#endif
}
char *mg_file_read(const char *path, size_t *sizep) { char *mg_file_read(const char *path, size_t *sizep) {
FILE *fp; FILE *fp;
char *data = NULL; char *data = NULL;
size_t size = (size_t) mg_file_size(path); size_t size = 0;
if ((fp = fopen(path, "rb")) != NULL) { if ((fp = fopen(path, "rb")) != NULL) {
fseek(fp, 0, SEEK_END);
size = (size_t) ftell(fp);
rewind(fp);
data = (char *) calloc(1, size + 1); data = (char *) calloc(1, size + 1);
if (data != NULL) { if (data != NULL) {
if (fread(data, 1, size, fp) != size) { if (fread(data, 1, size, fp) != size) {

View File

@ -541,7 +541,6 @@ void mg_timer_poll(unsigned long uptime_ms);
#endif #endif
char *mg_file_read(const char *path, size_t *size); char *mg_file_read(const char *path, size_t *size);
int64_t mg_file_size(const char *path);
bool mg_file_write(const char *path, const void *buf, size_t len); bool mg_file_write(const char *path, const void *buf, size_t len);
bool mg_file_printf(const char *path, const char *fmt, ...); bool mg_file_printf(const char *path, const char *fmt, ...);
void mg_random(void *buf, size_t len) WEAK; void mg_random(void *buf, size_t len) WEAK;

View File

@ -13,21 +13,14 @@ int mg_stat(const char *path, mg_stat_t *st) {
#endif #endif
} }
int64_t mg_file_size(const char *path) {
#if MG_ARCH == MG_ARCH_FREERTOS_TCP && defined(MG_ENABLE_FF)
struct FF_STAT st;
return ff_stat(path, &st) == 0 ? st.st_size : 0;
#else
mg_stat_t st;
return mg_stat(path, &st) == 0 ? st.st_size : 0;
#endif
}
char *mg_file_read(const char *path, size_t *sizep) { char *mg_file_read(const char *path, size_t *sizep) {
FILE *fp; FILE *fp;
char *data = NULL; char *data = NULL;
size_t size = (size_t) mg_file_size(path); size_t size = 0;
if ((fp = fopen(path, "rb")) != NULL) { if ((fp = fopen(path, "rb")) != NULL) {
fseek(fp, 0, SEEK_END);
size = (size_t) ftell(fp);
rewind(fp);
data = (char *) calloc(1, size + 1); data = (char *) calloc(1, size + 1);
if (data != NULL) { if (data != NULL) {
if (fread(data, 1, size, fp) != size) { if (fread(data, 1, size, fp) != size) {

View File

@ -17,7 +17,6 @@
#endif #endif
char *mg_file_read(const char *path, size_t *size); char *mg_file_read(const char *path, size_t *size);
int64_t mg_file_size(const char *path);
bool mg_file_write(const char *path, const void *buf, size_t len); bool mg_file_write(const char *path, const void *buf, size_t len);
bool mg_file_printf(const char *path, const char *fmt, ...); bool mg_file_printf(const char *path, const char *fmt, ...);
void mg_random(void *buf, size_t len) WEAK; void mg_random(void *buf, size_t len) WEAK;