mirror of
https://github.com/lammertb/libhttp.git
synced 2025-12-22 04:02:04 +03:00
Rewrite is_file_in_memory
This commit is contained in:
@@ -910,6 +910,7 @@ struct file {
|
|||||||
int gzipped; /* set to 1 if the content is gzipped
|
int gzipped; /* set to 1 if the content is gzipped
|
||||||
* in which case we need a content-encoding: gzip header */
|
* in which case we need a content-encoding: gzip header */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define STRUCT_FILE_INITIALIZER \
|
#define STRUCT_FILE_INITIALIZER \
|
||||||
{ \
|
{ \
|
||||||
(uint64_t)0, (time_t)0, (FILE *)NULL, (const char *)NULL, 0, 0 \
|
(uint64_t)0, (time_t)0, (FILE *)NULL, (const char *)NULL, 0, 0 \
|
||||||
@@ -1314,16 +1315,15 @@ static int is_file_in_memory(struct mg_connection *conn,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
filep->last_modified = (time_t)0;
|
if (conn->ctx->callbacks.open_file) {
|
||||||
|
filep->membuf = conn->ctx->callbacks.open_file(conn, path, &size);
|
||||||
if ((filep->membuf =
|
if (filep->membuf != NULL) {
|
||||||
conn->ctx->callbacks.open_file == NULL
|
/* NOTE: override filep->size only on success. Otherwise, it might
|
||||||
? NULL
|
* break constructs like if (!mg_stat() || !mg_fopen()) ... */
|
||||||
: conn->ctx->callbacks.open_file(conn, path, &size)) != NULL) {
|
filep->size = size;
|
||||||
/* NOTE: override filep->size only on success. Otherwise, it might
|
}
|
||||||
* break constructs like if (!mg_stat() || !mg_fopen()) ... */
|
|
||||||
filep->size = size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return filep->membuf != NULL;
|
return filep->membuf != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1347,6 +1347,8 @@ static int mg_fopen(struct mg_connection *conn,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(filep, 0, sizeof(*filep));
|
||||||
|
|
||||||
if (!is_file_in_memory(conn, path, filep)) {
|
if (!is_file_in_memory(conn, path, filep)) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
wchar_t wbuf[PATH_MAX], wmode[20];
|
wchar_t wbuf[PATH_MAX], wmode[20];
|
||||||
|
|||||||
Reference in New Issue
Block a user