Remove MG_ENABLE_STDIO and cleanup

This commit is contained in:
Sergey Lyubka committed 2021-07-24 03:44:00 +01:00
1 parent d130c6f42d
commit 2a2c17a232
15 files changed
+59 -89

No files matched your search

+1 -4
View File
@@ -8,6 +8,7 @@
#include <stdint.h>
#if defined(__GNUC__)
#include <sys/stat.h>
#include <sys/time.h>
#else
typedef long suseconds_t;
@@ -17,10 +18,6 @@ struct timeval {
};
#endif
#if MG_ENABLE_STDIO
#include <sys/stat.h>
#endif
#include <FreeRTOS.h>
#include <task.h>
+2 -4
View File
@@ -11,11 +11,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if MG_ENABLE_STDIO
#include <sys/stat.h>
#endif
#include <time.h>
#include <FreeRTOS.h>
#include <FreeRTOS_IP.h>
@@ -51,6 +48,7 @@
FreeRTOS_recvfrom((a), (b), (c), (d), (e), (f))
#define closesocket(x) FreeRTOS_closesocket(x)
#define gethostbyname(x) FreeRTOS_gethostbyname(x)
#define getsockname(a, b, c) (-1)
// Re-route calloc/free to the FreeRTOS's functions, don't use stdlib
static inline void *mg_calloc(int cnt, size_t size) {
-8
View File
@@ -12,14 +12,6 @@
#define MG_ENABLE_OPENSSL 0
#endif
#ifndef MG_ENABLE_PACKED_FS
#define MG_ENABLE_PACKED_FS 0
#endif
#ifndef MG_ENABLE_STDIO
#define MG_ENABLE_STDIO 1
#endif
#ifndef MG_ENABLE_SSI
#define MG_ENABLE_SSI 0
#endif
+11
View File
@@ -0,0 +1,11 @@
#include "fs.h"
int mg_stat(const char *path, mg_stat_t *st) {
#ifdef _WIN32
wchar_t tmp[MG_PATH_MAX];
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
return _wstati64(tmp, st);
#else
return stat(path, st);
#endif
}
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#include "arch.h"
#ifdef _WIN32
typedef struct _stati64 mg_stat_t;
#else
typedef struct stat mg_stat_t;
#endif
int mg_stat(const char *path, mg_stat_t *);
-2
View File
@@ -364,7 +364,6 @@ void mg_http_reply(struct mg_connection *c, int code, const char *headers,
if (buf != mem) free(buf);
}
#if MG_ENABLE_STDIO
static void http_cb(struct mg_connection *, int, void *, void *);
static void restore_http_cb(struct mg_connection *c) {
if (c->pfn_data != NULL) fclose((FILE *) c->pfn_data);
@@ -887,7 +886,6 @@ void mg_http_serve_dir(struct mg_connection *c, struct mg_http_message *hm,
}
}
}
#endif
static bool mg_is_url_safe(int c) {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
+1
View File
@@ -23,6 +23,7 @@ struct mg_http_serve_opts {
const char *root_dir; // Web root directory, must be non-NULL
const char *ssi_pattern; // SSI file name pattern, e.g. #.shtml
const char *extra_headers; // Extra HTTP headers to add in responses
bool use_packed_fs; // Serve files embedded into binary
};
// Parameter for mg_http_next_multipart
+1 -13
View File
@@ -2,17 +2,6 @@
#include "util.h"
#if MG_ENABLE_STDIO
int mg_stat(const char *path, mg_stat_t *st) {
#ifdef _WIN32
wchar_t tmp[MG_PATH_MAX];
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
return _wstati64(tmp, st);
#else
return stat(path, st);
#endif
}
char *mg_file_read(const char *path, size_t *sizep) {
FILE *fp;
char *data = NULL;
@@ -67,7 +56,6 @@ bool mg_file_printf(const char *path, const char *fmt, ...) {
if (buf != tmp) free(buf);
return result;
}
#endif // MG_ENABLE_STDIO
void mg_random(void *buf, size_t len) {
bool done = false;
@@ -75,7 +63,7 @@ void mg_random(void *buf, size_t len) {
#if MG_ARCH == MG_ARCH_ESP32
while (len--) *p++ = (unsigned char) (esp_random() & 255);
#elif MG_ARCH == MG_ARCH_WIN32
#elif MG_ARCH_UNIX && MG_ENABLE_STDIO
#elif MG_ARCH_UNIX
FILE *fp = fopen("/dev/urandom", "rb");
if (fp != NULL) {
if (fread(buf, 1, len, fp) == len) done = true;
-9
View File
@@ -36,15 +36,6 @@ double mg_time(void);
unsigned long mg_millis(void);
void mg_usleep(unsigned long usecs);
#if MG_ENABLE_STDIO
#ifdef _WIN32
typedef struct _stati64 mg_stat_t;
#else
typedef struct stat mg_stat_t;
#endif
int mg_stat(const char *path, mg_stat_t *);
#endif
#define mg_htons(x) mg_ntohs(x)
#define mg_htonl(x) mg_ntohl(x)