mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-26 22:41:03 +08:00
Remove mg_file_size()
This commit is contained in:
parent
529faa1172
commit
328a87b02a
@ -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
|
||||
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()
|
||||
|
||||
```c
|
||||
|
15
mongoose.c
15
mongoose.c
@ -3921,21 +3921,14 @@ int mg_stat(const char *path, mg_stat_t *st) {
|
||||
#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) {
|
||||
FILE *fp;
|
||||
char *data = NULL;
|
||||
size_t size = (size_t) mg_file_size(path);
|
||||
size_t size = 0;
|
||||
if ((fp = fopen(path, "rb")) != NULL) {
|
||||
fseek(fp, 0, SEEK_END);
|
||||
size = (size_t) ftell(fp);
|
||||
rewind(fp);
|
||||
data = (char *) calloc(1, size + 1);
|
||||
if (data != NULL) {
|
||||
if (fread(data, 1, size, fp) != size) {
|
||||
|
@ -541,7 +541,6 @@ void mg_timer_poll(unsigned long uptime_ms);
|
||||
#endif
|
||||
|
||||
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_printf(const char *path, const char *fmt, ...);
|
||||
void mg_random(void *buf, size_t len) WEAK;
|
||||
|
15
src/util.c
15
src/util.c
@ -13,21 +13,14 @@ int mg_stat(const char *path, mg_stat_t *st) {
|
||||
#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) {
|
||||
FILE *fp;
|
||||
char *data = NULL;
|
||||
size_t size = (size_t) mg_file_size(path);
|
||||
size_t size = 0;
|
||||
if ((fp = fopen(path, "rb")) != NULL) {
|
||||
fseek(fp, 0, SEEK_END);
|
||||
size = (size_t) ftell(fp);
|
||||
rewind(fp);
|
||||
data = (char *) calloc(1, size + 1);
|
||||
if (data != NULL) {
|
||||
if (fread(data, 1, size, fp) != size) {
|
||||
|
@ -17,7 +17,6 @@
|
||||
#endif
|
||||
|
||||
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_printf(const char *path, const char *fmt, ...);
|
||||
void mg_random(void *buf, size_t len) WEAK;
|
||||
|
Loading…
x
Reference in New Issue
Block a user