mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-14 01:38:01 +08:00
Enable mg_fopen_packed in newlib
This commit is contained in:
parent
dfc22af10f
commit
55d102e450
10
mongoose.c
10
mongoose.c
@ -437,13 +437,13 @@ ssize_t packed_write(void *cookie, const char *buf, size_t size) {
|
||||
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;
|
||||
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_CUR) fp->pos = (size_t)((off64_t) fp->pos + *offset);
|
||||
if (whence == SEEK_END) fp->pos = (size_t)((long) fp->size + *offset);
|
||||
if (whence == SEEK_CUR) fp->pos = (size_t)((long) fp->pos + *offset);
|
||||
if (fp->pos > fp->size) fp->pos = fp->size;
|
||||
*offset = (off64_t) fp->pos;
|
||||
*offset = (long) fp->pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ FILE *mg_fopen_packed(const char *path, const char *mode) {
|
||||
};
|
||||
struct packed_file *cookie = NULL;
|
||||
size_t size = 0;
|
||||
const char *data = unpack(path, &size);
|
||||
const char *data = mg_unpack(path, &size);
|
||||
if (data == NULL) return NULL;
|
||||
if ((cookie = calloc(1, sizeof(*cookie))) == NULL) return NULL;
|
||||
cookie->data = data;
|
||||
|
@ -608,7 +608,7 @@ void mg_usleep(unsigned long usecs);
|
||||
|
||||
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_FOPENCOOKIE
|
||||
#else
|
||||
|
10
src/fs.c
10
src/fs.c
@ -26,13 +26,13 @@ ssize_t packed_write(void *cookie, const char *buf, size_t size) {
|
||||
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;
|
||||
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_CUR) fp->pos = (size_t)((off64_t) fp->pos + *offset);
|
||||
if (whence == SEEK_END) fp->pos = (size_t)((long) fp->size + *offset);
|
||||
if (whence == SEEK_CUR) fp->pos = (size_t)((long) fp->pos + *offset);
|
||||
if (fp->pos > fp->size) fp->pos = fp->size;
|
||||
*offset = (off64_t) fp->pos;
|
||||
*offset = (long) fp->pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ FILE *mg_fopen_packed(const char *path, const char *mode) {
|
||||
};
|
||||
struct packed_file *cookie = NULL;
|
||||
size_t size = 0;
|
||||
const char *data = unpack(path, &size);
|
||||
const char *data = mg_unpack(path, &size);
|
||||
if (data == NULL) return NULL;
|
||||
if ((cookie = calloc(1, sizeof(*cookie))) == NULL) return NULL;
|
||||
cookie->data = data;
|
||||
|
2
src/fs.h
2
src/fs.h
@ -4,7 +4,7 @@
|
||||
|
||||
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_FOPENCOOKIE
|
||||
#else
|
||||
|
@ -1336,11 +1336,14 @@ static void test_multipart(void) {
|
||||
}
|
||||
|
||||
static void test_packed(void) {
|
||||
FILE *fp = mg_fopen_packed("Makefile", "r");
|
||||
#if defined(__linux__) && defined(GCC)
|
||||
const char *path = "Makefile";
|
||||
FILE *fp = mg_fopen_packed(path, "r");
|
||||
#if MG_ENABLE_PACKED_FS
|
||||
struct stat st;
|
||||
ASSERT(stat(path, &st) == 0);
|
||||
ASSERT(fp != NULL);
|
||||
fseek(fp, 0, SEEK_END);
|
||||
ASSERT(ftell(fp) > 0);
|
||||
ASSERT(ftell(fp) == st.st_size);
|
||||
fclose(fp);
|
||||
#else
|
||||
ASSERT(fp == NULL);
|
||||
|
Loading…
x
Reference in New Issue
Block a user