mirror of
https://github.com/lammertb/libhttp.git
synced 2026-01-27 08:02:47 +03:00
Moved WIN32 implementation of readdir to own file
This commit is contained in:
1
Makefile
1
Makefile
@@ -132,6 +132,7 @@ LIB_SOURCES = src/libhttp.c \
|
||||
src/httplib_read_auth_file.c \
|
||||
src/httplib_read_request.c \
|
||||
src/httplib_read_websocket.c \
|
||||
src/httplib_readdir.c \
|
||||
src/httplib_realloc2.c \
|
||||
src/httplib_redirect_to_https_port.c \
|
||||
src/httplib_refresh_trust.c \
|
||||
|
||||
@@ -41,9 +41,7 @@ unsigned mg_check_feature( unsigned feature ) {
|
||||
/* Set bits for available features according to API documentation.
|
||||
* This bit mask is created at compile time, according to the active
|
||||
* preprocessor defines. It is a single const value at runtime. */
|
||||
#if !defined(NO_FILES)
|
||||
| 0x0001u
|
||||
#endif
|
||||
#if !defined(NO_SSL)
|
||||
| 0x0002u
|
||||
#endif
|
||||
|
||||
57
src/httplib_readdir.c
Normal file
57
src/httplib_readdir.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lammert Bies
|
||||
* Copyright (c) 2013-2016 the Civetweb developers
|
||||
* Copyright (c) 2004-2013 Sergey Lyubka
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "libhttp-private.h"
|
||||
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
struct dirent * mg_readdir(DIR *dir) {
|
||||
|
||||
struct dirent *result = 0;
|
||||
|
||||
if (dir) {
|
||||
if (dir->handle != INVALID_HANDLE_VALUE) {
|
||||
result = &dir->result;
|
||||
WideCharToMultiByte(CP_UTF8, 0, dir->info.cFileName, -1, result->d_name, sizeof(result->d_name), NULL, NULL);
|
||||
|
||||
if (!FindNextFileW(dir->handle, &dir->info)) {
|
||||
|
||||
FindClose(dir->handle);
|
||||
dir->handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
} else {
|
||||
SetLastError(ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
} else SetLastError(ERROR_BAD_ARGUMENTS);
|
||||
|
||||
return result;
|
||||
|
||||
} /* mg_readdir */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
@@ -26,8 +26,6 @@
|
||||
|
||||
#include "libhttp-private.h"
|
||||
|
||||
|
||||
#if !defined(NO_FILES)
|
||||
int XX_httplib_remove_directory( struct mg_connection *conn, const char *dir ) {
|
||||
|
||||
char path[PATH_MAX];
|
||||
@@ -86,4 +84,3 @@ int XX_httplib_remove_directory( struct mg_connection *conn, const char *dir ) {
|
||||
return ok;
|
||||
|
||||
} /* XX_httplib_remove_directory */
|
||||
#endif
|
||||
|
||||
@@ -2035,30 +2035,7 @@ static int mg_closedir(DIR *dir) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static struct dirent * mg_readdir(DIR *dir) {
|
||||
|
||||
struct dirent *result = 0;
|
||||
|
||||
if (dir) {
|
||||
if (dir->handle != INVALID_HANDLE_VALUE) {
|
||||
result = &dir->result;
|
||||
WideCharToMultiByte(CP_UTF8, 0, dir->info.cFileName, -1, result->d_name, sizeof(result->d_name), NULL, NULL);
|
||||
|
||||
if (!FindNextFileW(dir->handle, &dir->info)) {
|
||||
|
||||
FindClose(dir->handle);
|
||||
dir->handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
} else {
|
||||
SetLastError(ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
} else SetLastError(ERROR_BAD_ARGUMENTS);
|
||||
|
||||
return result;
|
||||
}
|
||||
} /* mg_closedir */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
Reference in New Issue
Block a user