From bdb747f9dee48886e6064a4a714b10cedb924975 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Mon, 26 Jul 2021 09:15:17 +0100 Subject: [PATCH] Fix mg_prefix test --- Makefile | 2 +- examples/complete/pack.c | 10 +++++----- mongoose.c | 6 +++--- mongoose.h | 2 +- src/fs.c | 4 ++-- src/fs.h | 2 +- test/unit_test.c | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index fcb1c408..7283ab3c 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,7 @@ uninstall: arm: Makefile mongoose.c mongoose.h test/unit_test.c $(ARM) arm-none-eabi-gcc mongoose.c -c -Itest -DMG_ARCH=MG_ARCH_CUSTOM $(OPTS) $(WARN) $(INCS) -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES -DMG_ENABLE_DIRECTORY_LISTING=0 -DMG_ENABLE_SSI=1 -mongoose.c: Makefile +mongoose.c: Makefile $(wildcard src/*) (cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/private.h src/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@ mongoose.h: $(HDRS) Makefile diff --git a/examples/complete/pack.c b/examples/complete/pack.c index 0113484a..46775491 100644 --- a/examples/complete/pack.c +++ b/examples/complete/pack.c @@ -13,7 +13,7 @@ // ./pack file1.data file2.data > fs.c // // 3. In your application code, you can access files using this function: -// const char *unpack(const char *file_name, size_t *size); +// const char *mg_unpack(const char *file_name, size_t *size); // // 4. Build your app with fs.c: // cc -o my_app my_app.c fs.c @@ -22,9 +22,9 @@ #include static const char *code = - "const char *unpack(const char *name, size_t *size) {\n" + "const char *mg_unpack(const char *name, size_t *size) {\n" " const struct packed_file *p;\n" - " for (p = g_packed_files; p->name != NULL; p++) {\n" + " for (p = packed_files; p->name != NULL; p++) {\n" " if (strcmp(p->name, name) != 0) continue;\n" " if (size != NULL) *size = p->size - 1;\n" " return (const char *) p->data;\n" @@ -60,11 +60,11 @@ int main(int argc, char *argv[]) { fclose(fp); } - printf("%s", "\nconst struct packed_file {\n"); + printf("%s", "\nstatic const struct packed_file {\n"); printf("%s", " const char *name;\n"); printf("%s", " const unsigned char *data;\n"); printf("%s", " size_t size;\n"); - printf("%s", "} g_packed_files[] = {\n"); + printf("%s", "} packed_files[] = {\n"); for (i = 1; i < argc; i++) { printf(" {\"%s\", v%d, sizeof(v%d) },\n", argv[i], i, i); diff --git a/mongoose.c b/mongoose.c index 5bf8ff1d..41505ab0 100644 --- a/mongoose.c +++ b/mongoose.c @@ -423,7 +423,7 @@ const char *unpack(const char *path, size_t *size) { return NULL; } -#if defined(__linux__) +#if defined(__linux__) && defined(GCC) ssize_t packed_read(void *cookie, char *buf, size_t size) { struct packed_file *fp = (struct packed_file *) cookie; if (size > fp->size - fp->pos) size = fp->size - fp->pos; @@ -452,7 +452,7 @@ int packed_close(void *cookie) { return 0; } -FILE *fopen_packed(const char *path, const char *mode) { +FILE *mg_fopen_packed(const char *path, const char *mode) { cookie_io_functions_t funcs = { .read = packed_read, .write = packed_write, @@ -469,7 +469,7 @@ FILE *fopen_packed(const char *path, const char *mode) { return fopencookie(cookie, mode, funcs); } #else -FILE *fopen_packed(const char *path, const char *mode) { +FILE *mg_fopen_packed(const char *path, const char *mode) { (void) path, (void) mode; return NULL; } diff --git a/mongoose.h b/mongoose.h index 25b3a450..b5e229a2 100644 --- a/mongoose.h +++ b/mongoose.h @@ -606,7 +606,7 @@ void mg_usleep(unsigned long usecs); -FILE *fopen_packed(const char *path, const char *mode); +FILE *mg_fopen_packed(const char *path, const char *mode); diff --git a/src/fs.c b/src/fs.c index 5dac29cd..97112a84 100644 --- a/src/fs.c +++ b/src/fs.c @@ -41,7 +41,7 @@ int packed_close(void *cookie) { return 0; } -FILE *fopen_packed(const char *path, const char *mode) { +FILE *mg_fopen_packed(const char *path, const char *mode) { cookie_io_functions_t funcs = { .read = packed_read, .write = packed_write, @@ -58,7 +58,7 @@ FILE *fopen_packed(const char *path, const char *mode) { return fopencookie(cookie, mode, funcs); } #else -FILE *fopen_packed(const char *path, const char *mode) { +FILE *mg_fopen_packed(const char *path, const char *mode) { (void) path, (void) mode; return NULL; } diff --git a/src/fs.h b/src/fs.h index 71e2a8ab..c062d15c 100644 --- a/src/fs.h +++ b/src/fs.h @@ -2,4 +2,4 @@ #include "arch.h" -FILE *fopen_packed(const char *path, const char *mode); +FILE *mg_fopen_packed(const char *path, const char *mode); diff --git a/test/unit_test.c b/test/unit_test.c index 0280a4ec..3def40dd 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -1336,7 +1336,7 @@ static void test_multipart(void) { } static void test_packed(void) { - FILE *fp = fopen_packed("Makefile", "r"); + FILE *fp = mg_fopen_packed("Makefile", "r"); #if defined(__linux__) && defined(GCC) ASSERT(fp != NULL); fseek(fp, 0, SEEK_END);