mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
update tinydir.h to newest version
Update to cxong/tinydir commit 97a6032ddb ("Fix tinydir_file_open for root or subfolder of root in Linux.") This should fix bug #61106 (compiling newest source fails with "-O3" optims)
This commit is contained in:
parent
601e1bb326
commit
a72fc743ef
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2013-2017, tinydir authors:
|
Copyright (c) 2013-2019, tinydir authors:
|
||||||
- Cong Xu
|
- Cong Xu
|
||||||
- Lautis Sun
|
- Lautis Sun
|
||||||
- Baudouin Feildel
|
- Baudouin Feildel
|
||||||
@ -45,7 +45,9 @@ extern "C" {
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
# ifndef WIN32_LEAN_AND_MEAN
|
||||||
# define WIN32_LEAN_AND_MEAN
|
# define WIN32_LEAN_AND_MEAN
|
||||||
|
# endif
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# include <tchar.h>
|
# include <tchar.h>
|
||||||
# pragma warning(push)
|
# pragma warning(push)
|
||||||
@ -65,32 +67,44 @@ extern "C" {
|
|||||||
|
|
||||||
/* Windows UNICODE wide character support */
|
/* Windows UNICODE wide character support */
|
||||||
#if defined _MSC_VER || defined __MINGW32__
|
#if defined _MSC_VER || defined __MINGW32__
|
||||||
#define _tinydir_char_t TCHAR
|
# define _tinydir_char_t TCHAR
|
||||||
#define TINYDIR_STRING(s) _TEXT(s)
|
# define TINYDIR_STRING(s) _TEXT(s)
|
||||||
#define _tinydir_strlen _tcslen
|
# define _tinydir_strlen _tcslen
|
||||||
#define _tinydir_strcpy _tcscpy
|
# define _tinydir_strcpy _tcscpy
|
||||||
#define _tinydir_strcat _tcscat
|
# define _tinydir_strcat _tcscat
|
||||||
#define _tinydir_strcmp _tcscmp
|
# define _tinydir_strcmp _tcscmp
|
||||||
#define _tinydir_strrchr _tcsrchr
|
# define _tinydir_strrchr _tcsrchr
|
||||||
#define _tinydir_strncmp _tcsncmp
|
# define _tinydir_strncmp _tcsncmp
|
||||||
#else
|
#else
|
||||||
#define _tinydir_char_t char
|
# define _tinydir_char_t char
|
||||||
#define TINYDIR_STRING(s) s
|
# define TINYDIR_STRING(s) s
|
||||||
#define _tinydir_strlen strlen
|
# define _tinydir_strlen strlen
|
||||||
#define _tinydir_strcpy strcpy
|
# define _tinydir_strcpy strcpy
|
||||||
#define _tinydir_strcat strcat
|
# define _tinydir_strcat strcat
|
||||||
#define _tinydir_strcmp strcmp
|
# define _tinydir_strcmp strcmp
|
||||||
#define _tinydir_strrchr strrchr
|
# define _tinydir_strrchr strrchr
|
||||||
#define _tinydir_strncmp strncmp
|
# define _tinydir_strncmp strncmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined _MSC_VER || defined __MINGW32__)
|
#if (defined _MSC_VER || defined __MINGW32__)
|
||||||
#include <windows.h>
|
# include <windows.h>
|
||||||
#define _TINYDIR_PATH_MAX MAX_PATH
|
# define _TINYDIR_PATH_MAX MAX_PATH
|
||||||
#elif defined __linux__
|
#elif defined __linux__
|
||||||
#include <linux/limits.h>
|
# include <limits.h>
|
||||||
#define _TINYDIR_PATH_MAX PATH_MAX
|
# ifdef PATH_MAX
|
||||||
#else
|
# define _TINYDIR_PATH_MAX PATH_MAX
|
||||||
|
# endif
|
||||||
|
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||||
|
# include <sys/param.h>
|
||||||
|
# if defined(BSD)
|
||||||
|
# include <limits.h>
|
||||||
|
# ifdef PATH_MAX
|
||||||
|
# define _TINYDIR_PATH_MAX PATH_MAX
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _TINYDIR_PATH_MAX
|
||||||
#define _TINYDIR_PATH_MAX 4096
|
#define _TINYDIR_PATH_MAX 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -357,7 +371,7 @@ int tinydir_open_sorted(tinydir_dir *dir, const _tinydir_char_t *path)
|
|||||||
}
|
}
|
||||||
tinydir_close(dir);
|
tinydir_close(dir);
|
||||||
|
|
||||||
if (tinydir_open(dir, path) == -1)
|
if (n_files == 0 || tinydir_open(dir, path) == -1)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -484,6 +498,7 @@ int tinydir_next(tinydir_dir *dir)
|
|||||||
_TINYDIR_FUNC
|
_TINYDIR_FUNC
|
||||||
int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
|
int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
|
||||||
{
|
{
|
||||||
|
const _tinydir_char_t *filename;
|
||||||
if (dir == NULL || file == NULL)
|
if (dir == NULL || file == NULL)
|
||||||
{
|
{
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
@ -498,45 +513,38 @@ int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
|
|||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (_tinydir_strlen(dir->path) +
|
filename =
|
||||||
_tinydir_strlen(
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
dir->_f.cFileName
|
dir->_f.cFileName;
|
||||||
#else
|
#else
|
||||||
dir->_e->d_name
|
dir->_e->d_name;
|
||||||
#endif
|
#endif
|
||||||
) + 1 + _TINYDIR_PATH_EXTRA >=
|
if (_tinydir_strlen(dir->path) +
|
||||||
|
_tinydir_strlen(filename) + 1 + _TINYDIR_PATH_EXTRA >=
|
||||||
_TINYDIR_PATH_MAX)
|
_TINYDIR_PATH_MAX)
|
||||||
{
|
{
|
||||||
/* the path for the file will be too long */
|
/* the path for the file will be too long */
|
||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (_tinydir_strlen(
|
if (_tinydir_strlen(filename) >= _TINYDIR_FILENAME_MAX)
|
||||||
#ifdef _MSC_VER
|
|
||||||
dir->_f.cFileName
|
|
||||||
#else
|
|
||||||
dir->_e->d_name
|
|
||||||
#endif
|
|
||||||
) >= _TINYDIR_FILENAME_MAX)
|
|
||||||
{
|
{
|
||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tinydir_strcpy(file->path, dir->path);
|
_tinydir_strcpy(file->path, dir->path);
|
||||||
|
if (_tinydir_strcmp(dir->path, TINYDIR_STRING("/")) != 0)
|
||||||
_tinydir_strcat(file->path, TINYDIR_STRING("/"));
|
_tinydir_strcat(file->path, TINYDIR_STRING("/"));
|
||||||
_tinydir_strcpy(file->name,
|
_tinydir_strcpy(file->name, filename);
|
||||||
#ifdef _MSC_VER
|
_tinydir_strcat(file->path, filename);
|
||||||
dir->_f.cFileName
|
|
||||||
#else
|
|
||||||
dir->_e->d_name
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
_tinydir_strcat(file->path, file->name);
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
if (_tstat(
|
if (_tstat(
|
||||||
|
#elif (defined _BSD_SOURCE) || (defined _DEFAULT_SOURCE) \
|
||||||
|
|| ((defined _XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)) \
|
||||||
|
|| ((defined _POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L))
|
||||||
|
if (lstat(
|
||||||
#else
|
#else
|
||||||
if (stat(
|
if (stat(
|
||||||
#endif
|
#endif
|
||||||
@ -650,7 +658,7 @@ int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path)
|
|||||||
/* Get the parent path */
|
/* Get the parent path */
|
||||||
#if (defined _MSC_VER || defined __MINGW32__)
|
#if (defined _MSC_VER || defined __MINGW32__)
|
||||||
#if ((defined _MSC_VER) && (_MSC_VER >= 1400))
|
#if ((defined _MSC_VER) && (_MSC_VER >= 1400))
|
||||||
_tsplitpath_s(
|
errno = _tsplitpath_s(
|
||||||
path,
|
path,
|
||||||
drive_buf, _TINYDIR_DRIVE_MAX,
|
drive_buf, _TINYDIR_DRIVE_MAX,
|
||||||
dir_name_buf, _TINYDIR_FILENAME_MAX,
|
dir_name_buf, _TINYDIR_FILENAME_MAX,
|
||||||
@ -665,6 +673,11 @@ int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path)
|
|||||||
ext_buf);
|
ext_buf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (errno)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* _splitpath_s not work fine with only filename and widechar support */
|
/* _splitpath_s not work fine with only filename and widechar support */
|
||||||
#ifdef _UNICODE
|
#ifdef _UNICODE
|
||||||
if (drive_buf[0] == L'\xFEFE')
|
if (drive_buf[0] == L'\xFEFE')
|
||||||
@ -673,11 +686,6 @@ int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path)
|
|||||||
dir_name_buf[0] = '\0';
|
dir_name_buf[0] = '\0';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (errno)
|
|
||||||
{
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/* Emulate the behavior of dirname by returning "." for dir name if it's
|
/* Emulate the behavior of dirname by returning "." for dir name if it's
|
||||||
empty */
|
empty */
|
||||||
if (drive_buf[0] == '\0' && dir_name_buf[0] == '\0')
|
if (drive_buf[0] == '\0' && dir_name_buf[0] == '\0')
|
||||||
@ -694,9 +702,24 @@ int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path)
|
|||||||
_tinydir_strcpy(dir_name_buf, path);
|
_tinydir_strcpy(dir_name_buf, path);
|
||||||
dir_name = dirname(dir_name_buf);
|
dir_name = dirname(dir_name_buf);
|
||||||
_tinydir_strcpy(file_name_buf, path);
|
_tinydir_strcpy(file_name_buf, path);
|
||||||
base_name =basename(file_name_buf);
|
base_name = basename(file_name_buf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Special case: if the path is a root dir, open the parent dir as the file */
|
||||||
|
#if (defined _MSC_VER || defined __MINGW32__)
|
||||||
|
if (_tinydir_strlen(base_name) == 0)
|
||||||
|
#else
|
||||||
|
if ((_tinydir_strcmp(base_name, TINYDIR_STRING("/"))) == 0)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
memset(file, 0, sizeof * file);
|
||||||
|
file->is_dir = 1;
|
||||||
|
file->is_reg = 0;
|
||||||
|
_tinydir_strcpy(file->path, dir_name);
|
||||||
|
file->extension = file->path + _tinydir_strlen(file->path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Open the parent directory */
|
/* Open the parent directory */
|
||||||
if (tinydir_open(&dir, dir_name) == -1)
|
if (tinydir_open(&dir, dir_name) == -1)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user