mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-21 19:51:50 +00:00
Enable mg_fopen_packed in newlib
This commit is contained in:
1 parent
dfc22af10f
commit
55d102e450
5 files changed
+18
-15
No files matched your search
+5
-5
@@ -437,13 +437,13 @@ ssize_t packed_write(void *cookie, const char *buf, size_t size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int packed_seek(void *cookie, off64_t *offset, int whence) {
|
int packed_seek(void *cookie, long *offset, int whence) {
|
||||||
struct packed_file *fp = (struct packed_file *) cookie;
|
struct packed_file *fp = (struct packed_file *) cookie;
|
||||||
if (whence == SEEK_SET) fp->pos = (size_t) *offset;
|
if (whence == SEEK_SET) fp->pos = (size_t) *offset;
|
||||||
if (whence == SEEK_END) fp->pos = (size_t)((off64_t) fp->size + *offset);
|
if (whence == SEEK_END) fp->pos = (size_t)((long) fp->size + *offset);
|
||||||
if (whence == SEEK_CUR) fp->pos = (size_t)((off64_t) fp->pos + *offset);
|
if (whence == SEEK_CUR) fp->pos = (size_t)((long) fp->pos + *offset);
|
||||||
if (fp->pos > fp->size) fp->pos = fp->size;
|
if (fp->pos > fp->size) fp->pos = fp->size;
|
||||||
*offset = (off64_t) fp->pos;
|
*offset = (long) fp->pos;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,7 +461,7 @@ FILE *mg_fopen_packed(const char *path, const char *mode) {
|
|||||||
};
|
};
|
||||||
struct packed_file *cookie = NULL;
|
struct packed_file *cookie = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
const char *data = unpack(path, &size);
|
const char *data = mg_unpack(path, &size);
|
||||||
if (data == NULL) return NULL;
|
if (data == NULL) return NULL;
|
||||||
if ((cookie = calloc(1, sizeof(*cookie))) == NULL) return NULL;
|
if ((cookie = calloc(1, sizeof(*cookie))) == NULL) return NULL;
|
||||||
cookie->data = data;
|
cookie->data = data;
|
||||||
|
|||||||
+1
-1
@@ -608,7 +608,7 @@ void mg_usleep(unsigned long usecs);
|
|||||||
|
|
||||||
FILE *mg_fopen_packed(const char *path, const char *mode);
|
FILE *mg_fopen_packed(const char *path, const char *mode);
|
||||||
|
|
||||||
#if defined(__linux__) && defined(GCC)
|
#if (defined(__linux__) && defined(__GNUC__)) || defined(__NEWLIB__)
|
||||||
#define MG_ENABLE_PACKED_FS 1
|
#define MG_ENABLE_PACKED_FS 1
|
||||||
#define MG_FOPENCOOKIE
|
#define MG_FOPENCOOKIE
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ ssize_t packed_write(void *cookie, const char *buf, size_t size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int packed_seek(void *cookie, off64_t *offset, int whence) {
|
int packed_seek(void *cookie, long *offset, int whence) {
|
||||||
struct packed_file *fp = (struct packed_file *) cookie;
|
struct packed_file *fp = (struct packed_file *) cookie;
|
||||||
if (whence == SEEK_SET) fp->pos = (size_t) *offset;
|
if (whence == SEEK_SET) fp->pos = (size_t) *offset;
|
||||||
if (whence == SEEK_END) fp->pos = (size_t)((off64_t) fp->size + *offset);
|
if (whence == SEEK_END) fp->pos = (size_t)((long) fp->size + *offset);
|
||||||
if (whence == SEEK_CUR) fp->pos = (size_t)((off64_t) fp->pos + *offset);
|
if (whence == SEEK_CUR) fp->pos = (size_t)((long) fp->pos + *offset);
|
||||||
if (fp->pos > fp->size) fp->pos = fp->size;
|
if (fp->pos > fp->size) fp->pos = fp->size;
|
||||||
*offset = (off64_t) fp->pos;
|
*offset = (long) fp->pos;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ FILE *mg_fopen_packed(const char *path, const char *mode) {
|
|||||||
};
|
};
|
||||||
struct packed_file *cookie = NULL;
|
struct packed_file *cookie = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
const char *data = unpack(path, &size);
|
const char *data = mg_unpack(path, &size);
|
||||||
if (data == NULL) return NULL;
|
if (data == NULL) return NULL;
|
||||||
if ((cookie = calloc(1, sizeof(*cookie))) == NULL) return NULL;
|
if ((cookie = calloc(1, sizeof(*cookie))) == NULL) return NULL;
|
||||||
cookie->data = data;
|
cookie->data = data;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
FILE *mg_fopen_packed(const char *path, const char *mode);
|
FILE *mg_fopen_packed(const char *path, const char *mode);
|
||||||
|
|
||||||
#if defined(__linux__) && defined(GCC)
|
#if (defined(__linux__) && defined(__GNUC__)) || defined(__NEWLIB__)
|
||||||
#define MG_ENABLE_PACKED_FS 1
|
#define MG_ENABLE_PACKED_FS 1
|
||||||
#define MG_FOPENCOOKIE
|
#define MG_FOPENCOOKIE
|
||||||
#else
|
#else
|
||||||
|
|||||||
+6
-3
@@ -1336,11 +1336,14 @@ static void test_multipart(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_packed(void) {
|
static void test_packed(void) {
|
||||||
FILE *fp = mg_fopen_packed("Makefile", "r");
|
const char *path = "Makefile";
|
||||||
#if defined(__linux__) && defined(GCC)
|
FILE *fp = mg_fopen_packed(path, "r");
|
||||||
|
#if MG_ENABLE_PACKED_FS
|
||||||
|
struct stat st;
|
||||||
|
ASSERT(stat(path, &st) == 0);
|
||||||
ASSERT(fp != NULL);
|
ASSERT(fp != NULL);
|
||||||
fseek(fp, 0, SEEK_END);
|
fseek(fp, 0, SEEK_END);
|
||||||
ASSERT(ftell(fp) > 0);
|
ASSERT(ftell(fp) == st.st_size);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
#else
|
#else
|
||||||
ASSERT(fp == NULL);
|
ASSERT(fp == NULL);
|
||||||
|
|||||||
Reference in new issue
Block a user