Rename posix_* -> p_* to avoid build conflict on linux

This commit is contained in:
Sergey Lyubka 2021-09-16 11:16:10 +01:00
parent 894a168833
commit 409fdaec59
3 changed files with 45 additions and 56 deletions

View File

@ -518,7 +518,7 @@ struct mg_fs mg_fs_packed = {packed_stat, packed_list, packed_open,
#if defined(FOPEN_MAX) #if defined(FOPEN_MAX)
static int posix_stat(const char *path, size_t *size, time_t *mtime) { static int p_stat(const char *path, size_t *size, time_t *mtime) {
#ifdef _WIN32 #ifdef _WIN32
struct _stati64 st; struct _stati64 st;
wchar_t tmp[PATH_MAX]; wchar_t tmp[PATH_MAX];
@ -642,8 +642,8 @@ struct dirent *readdir(DIR *d) {
} }
#endif #endif
static void posix_list(const char *dir, void (*fn)(const char *, void *), static void p_list(const char *dir, void (*fn)(const char *, void *),
void *userdata) { void *userdata) {
#if MG_ENABLE_DIRLIST #if MG_ENABLE_DIRLIST
struct dirent *dp; struct dirent *dp;
DIR *dirp; DIR *dirp;
@ -658,7 +658,7 @@ static void posix_list(const char *dir, void (*fn)(const char *, void *),
#endif #endif
} }
static struct mg_fd *posix_open(const char *path, int flags) { static struct mg_fd *p_open(const char *path, int flags) {
const char *mode = flags == (MG_FS_READ | MG_FS_WRITE) ? "r+b" const char *mode = flags == (MG_FS_READ | MG_FS_WRITE) ? "r+b"
: flags & MG_FS_READ ? "rb" : flags & MG_FS_READ ? "rb"
: flags & MG_FS_WRITE ? "wb" : flags & MG_FS_WRITE ? "wb"
@ -680,19 +680,19 @@ static struct mg_fd *posix_open(const char *path, int flags) {
return fd; return fd;
} }
static void posix_close(struct mg_fd *fd) { static void p_close(struct mg_fd *fd) {
if (fd != NULL) fclose((FILE *) fd->fd), free(fd); if (fd != NULL) fclose((FILE *) fd->fd), free(fd);
} }
static size_t posix_read(void *fp, void *buf, size_t len) { static size_t p_read(void *fp, void *buf, size_t len) {
return fread(buf, 1, len, (FILE *) fp); return fread(buf, 1, len, (FILE *) fp);
} }
static size_t posix_write(void *fp, const void *buf, size_t len) { static size_t p_write(void *fp, const void *buf, size_t len) {
return fwrite(buf, 1, len, (FILE *) fp); return fwrite(buf, 1, len, (FILE *) fp);
} }
static size_t posix_seek(void *fp, size_t offset) { static size_t p_seek(void *fp, size_t offset) {
#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \ #if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \
_XOPEN_SOURCE >= 600 _XOPEN_SOURCE >= 600
fseeko((FILE *) fp, (off_t) offset, SEEK_SET); fseeko((FILE *) fp, (off_t) offset, SEEK_SET);
@ -702,48 +702,48 @@ static size_t posix_seek(void *fp, size_t offset) {
return (size_t) ftell((FILE *) fp); return (size_t) ftell((FILE *) fp);
} }
#else #else
static char *posix_realpath(const char *path, char *resolved_path) { static char *p_realpath(const char *path, char *resolved_path) {
(void) path, (void) resolved_path; (void) path, (void) resolved_path;
return NULL; return NULL;
} }
static int posix_stat(const char *path, size_t *size, time_t *mtime) { static int p_stat(const char *path, size_t *size, time_t *mtime) {
(void) path, (void) size, (void) mtime; (void) path, (void) size, (void) mtime;
return 0; return 0;
} }
static void posix_list(const char *path, void (*fn)(const char *, void *), static void p_list(const char *path, void (*fn)(const char *, void *),
void *userdata) { void *userdata) {
(void) path, (void) fn, (void) userdata; (void) path, (void) fn, (void) userdata;
} }
static struct mg_fd *posix_open(const char *path, int flags) { static struct mg_fd *p_open(const char *path, int flags) {
(void) path, (void) flags; (void) path, (void) flags;
return NULL; return NULL;
} }
static void posix_close(struct mg_fd *fd) { static void p_close(struct mg_fd *fd) {
(void) fd; (void) fd;
} }
static size_t posix_read(void *fd, void *buf, size_t len) { static size_t p_read(void *fd, void *buf, size_t len) {
(void) fd, (void) buf, (void) len; (void) fd, (void) buf, (void) len;
return 0; return 0;
} }
static size_t posix_write(void *fd, const void *buf, size_t len) { static size_t p_write(void *fd, const void *buf, size_t len) {
(void) fd, (void) buf, (void) len; (void) fd, (void) buf, (void) len;
return 0; return 0;
} }
static size_t posix_seek(void *fd, size_t offset) { static size_t p_seek(void *fd, size_t offset) {
(void) fd, (void) offset; (void) fd, (void) offset;
return (size_t) ~0; return (size_t) ~0;
} }
#endif #endif
struct mg_fs mg_fs_posix = {posix_stat, posix_list, posix_open, posix_close, struct mg_fs mg_fs_posix = {p_stat, p_list, p_open, p_close,
posix_read, posix_write, posix_seek}; p_read, p_write, p_seek};
#ifdef MG_ENABLE_LINES #ifdef MG_ENABLE_LINES
#line 1 "src/http.c" #line 1 "src/http.c"

View File

@ -596,27 +596,16 @@ void mg_usleep(unsigned long usecs);
enum { MG_FS_READ = 1, MG_FS_WRITE = 2, MG_FS_DIR = 4 }; enum { MG_FS_READ = 1, MG_FS_WRITE = 2, MG_FS_DIR = 4 };
// Filesystem API functions // Filesystem API functions
// stat() returns MG_FS_* flags and populates file size and modification time
// list() calls fn() for every directory entry, allowing to list a directory
struct mg_fs { struct mg_fs {
// Return MG_FS_* flags, and populate file size and modification time
int (*stat)(const char *path, size_t *size, time_t *mtime); int (*stat)(const char *path, size_t *size, time_t *mtime);
// Enumerates objects in directory
void (*list)(const char *path, void (*fn)(const char *, void *), void *); void (*list)(const char *path, void (*fn)(const char *, void *), void *);
struct mg_fd *(*open)(const char *path, int flags); // Open file
// Open file void (*close)(struct mg_fd *fd); // Close file
struct mg_fd *(*open)(const char *path, int flags); size_t (*read)(void *fd, void *buf, size_t len); // Read file
size_t (*write)(void *fd, const void *buf, size_t len); // Write file
// Close file size_t (*seek)(void *fd, size_t offset); // Set file position
void (*close)(struct mg_fd *fd);
// Read file
size_t (*read)(void *fd, void *buf, size_t len);
// Write file
size_t (*write)(void *fd, const void *buf, size_t len);
// Seek file
size_t (*seek)(void *fd, size_t offset);
}; };
// File descriptor // File descriptor

View File

@ -1,7 +1,7 @@
#include "fs.h" #include "fs.h"
#if defined(FOPEN_MAX) #if defined(FOPEN_MAX)
static int posix_stat(const char *path, size_t *size, time_t *mtime) { static int p_stat(const char *path, size_t *size, time_t *mtime) {
#ifdef _WIN32 #ifdef _WIN32
struct _stati64 st; struct _stati64 st;
wchar_t tmp[PATH_MAX]; wchar_t tmp[PATH_MAX];
@ -125,8 +125,8 @@ struct dirent *readdir(DIR *d) {
} }
#endif #endif
static void posix_list(const char *dir, void (*fn)(const char *, void *), static void p_list(const char *dir, void (*fn)(const char *, void *),
void *userdata) { void *userdata) {
#if MG_ENABLE_DIRLIST #if MG_ENABLE_DIRLIST
struct dirent *dp; struct dirent *dp;
DIR *dirp; DIR *dirp;
@ -141,7 +141,7 @@ static void posix_list(const char *dir, void (*fn)(const char *, void *),
#endif #endif
} }
static struct mg_fd *posix_open(const char *path, int flags) { static struct mg_fd *p_open(const char *path, int flags) {
const char *mode = flags == (MG_FS_READ | MG_FS_WRITE) ? "r+b" const char *mode = flags == (MG_FS_READ | MG_FS_WRITE) ? "r+b"
: flags & MG_FS_READ ? "rb" : flags & MG_FS_READ ? "rb"
: flags & MG_FS_WRITE ? "wb" : flags & MG_FS_WRITE ? "wb"
@ -163,19 +163,19 @@ static struct mg_fd *posix_open(const char *path, int flags) {
return fd; return fd;
} }
static void posix_close(struct mg_fd *fd) { static void p_close(struct mg_fd *fd) {
if (fd != NULL) fclose((FILE *) fd->fd), free(fd); if (fd != NULL) fclose((FILE *) fd->fd), free(fd);
} }
static size_t posix_read(void *fp, void *buf, size_t len) { static size_t p_read(void *fp, void *buf, size_t len) {
return fread(buf, 1, len, (FILE *) fp); return fread(buf, 1, len, (FILE *) fp);
} }
static size_t posix_write(void *fp, const void *buf, size_t len) { static size_t p_write(void *fp, const void *buf, size_t len) {
return fwrite(buf, 1, len, (FILE *) fp); return fwrite(buf, 1, len, (FILE *) fp);
} }
static size_t posix_seek(void *fp, size_t offset) { static size_t p_seek(void *fp, size_t offset) {
#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \ #if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \
_XOPEN_SOURCE >= 600 _XOPEN_SOURCE >= 600
fseeko((FILE *) fp, (off_t) offset, SEEK_SET); fseeko((FILE *) fp, (off_t) offset, SEEK_SET);
@ -185,45 +185,45 @@ static size_t posix_seek(void *fp, size_t offset) {
return (size_t) ftell((FILE *) fp); return (size_t) ftell((FILE *) fp);
} }
#else #else
static char *posix_realpath(const char *path, char *resolved_path) { static char *p_realpath(const char *path, char *resolved_path) {
(void) path, (void) resolved_path; (void) path, (void) resolved_path;
return NULL; return NULL;
} }
static int posix_stat(const char *path, size_t *size, time_t *mtime) { static int p_stat(const char *path, size_t *size, time_t *mtime) {
(void) path, (void) size, (void) mtime; (void) path, (void) size, (void) mtime;
return 0; return 0;
} }
static void posix_list(const char *path, void (*fn)(const char *, void *), static void p_list(const char *path, void (*fn)(const char *, void *),
void *userdata) { void *userdata) {
(void) path, (void) fn, (void) userdata; (void) path, (void) fn, (void) userdata;
} }
static struct mg_fd *posix_open(const char *path, int flags) { static struct mg_fd *p_open(const char *path, int flags) {
(void) path, (void) flags; (void) path, (void) flags;
return NULL; return NULL;
} }
static void posix_close(struct mg_fd *fd) { static void p_close(struct mg_fd *fd) {
(void) fd; (void) fd;
} }
static size_t posix_read(void *fd, void *buf, size_t len) { static size_t p_read(void *fd, void *buf, size_t len) {
(void) fd, (void) buf, (void) len; (void) fd, (void) buf, (void) len;
return 0; return 0;
} }
static size_t posix_write(void *fd, const void *buf, size_t len) { static size_t p_write(void *fd, const void *buf, size_t len) {
(void) fd, (void) buf, (void) len; (void) fd, (void) buf, (void) len;
return 0; return 0;
} }
static size_t posix_seek(void *fd, size_t offset) { static size_t p_seek(void *fd, size_t offset) {
(void) fd, (void) offset; (void) fd, (void) offset;
return (size_t) ~0; return (size_t) ~0;
} }
#endif #endif
struct mg_fs mg_fs_posix = {posix_stat, posix_list, posix_open, posix_close, struct mg_fs mg_fs_posix = {p_stat, p_list, p_open, p_close,
posix_read, posix_write, posix_seek}; p_read, p_write, p_seek};