diff --git a/Makefile b/Makefile index a72684ec..52e3680b 100644 --- a/Makefile +++ b/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 \ diff --git a/src/httplib_check_feature.c b/src/httplib_check_feature.c index 01dac2f7..a7aa34d1 100644 --- a/src/httplib_check_feature.c +++ b/src/httplib_check_feature.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 diff --git a/src/httplib_readdir.c b/src/httplib_readdir.c new file mode 100644 index 00000000..dd535e00 --- /dev/null +++ b/src/httplib_readdir.c @@ -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 */ diff --git a/src/httplib_remove_directory.c b/src/httplib_remove_directory.c index e7128107..27774d0f 100644 --- a/src/httplib_remove_directory.c +++ b/src/httplib_remove_directory.c @@ -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 diff --git a/src/libhttp.c b/src/libhttp.c index 1acdcff5..6403cae3 100644 --- a/src/libhttp.c +++ b/src/libhttp.c @@ -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 */