summaryrefslogtreecommitdiffstats
path: root/compat/zlib
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-04-14 14:23:15 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-04-14 14:23:15 (GMT)
commitafc472854643657015d03437e75c87f10bc2d0eb (patch)
tree4f61914e482502aaf71345446836f69a4da4a2e8 /compat/zlib
parentc89ef9ea024c6edbc2ced2f4d00d63cdc66f9e8e (diff)
downloadtcl-afc472854643657015d03437e75c87f10bc2d0eb.zip
tcl-afc472854643657015d03437e75c87f10bc2d0eb.tar.gz
tcl-afc472854643657015d03437e75c87f10bc2d0eb.tar.bz2
Update to latest version of tinydir
Diffstat (limited to 'compat/zlib')
-rw-r--r--compat/zlib/contrib/minizip/tinydir.h120
1 files changed, 71 insertions, 49 deletions
diff --git a/compat/zlib/contrib/minizip/tinydir.h b/compat/zlib/contrib/minizip/tinydir.h
index eb34399..ba20c3e 100644
--- a/compat/zlib/contrib/minizip/tinydir.h
+++ b/compat/zlib/contrib/minizip/tinydir.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2013-2017, tinydir authors:
+Copyright (c) 2013-2021, tinydir authors:
- Cong Xu
- Lautis Sun
- Baudouin Feildel
@@ -45,7 +45,9 @@ extern "C" {
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
-# define WIN32_LEAN_AND_MEAN
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
# include <windows.h>
# include <tchar.h>
# pragma warning(push)
@@ -89,12 +91,16 @@ extern "C" {
# define _TINYDIR_PATH_MAX MAX_PATH
#elif defined __linux__
# include <limits.h>
-# define _TINYDIR_PATH_MAX PATH_MAX
+# ifdef PATH_MAX
+# define _TINYDIR_PATH_MAX PATH_MAX
+# endif
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
# include <sys/param.h>
# if defined(BSD)
# include <limits.h>
-# define _TINYDIR_PATH_MAX PATH_MAX
+# ifdef PATH_MAX
+# define _TINYDIR_PATH_MAX PATH_MAX
+# endif
# endif
#endif
@@ -119,8 +125,13 @@ extern "C" {
# define _TINYDIR_FUNC static __inline
#elif !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
# define _TINYDIR_FUNC static __inline__
-#else
+#elif defined(__cplusplus)
# define _TINYDIR_FUNC static inline
+#elif defined(__GNUC__)
+/* Suppress unused function warning */
+# define _TINYDIR_FUNC __attribute__((unused)) static
+#else
+# define _TINYDIR_FUNC static
#endif
/* readdir_r usage; define TINYDIR_USE_READDIR_R to use it (if supported) */
@@ -365,7 +376,7 @@ int tinydir_open_sorted(tinydir_dir *dir, const _tinydir_char_t *path)
}
tinydir_close(dir);
- if (tinydir_open(dir, path) == -1)
+ if (n_files == 0 || tinydir_open(dir, path) == -1)
{
return -1;
}
@@ -492,6 +503,7 @@ int tinydir_next(tinydir_dir *dir)
_TINYDIR_FUNC
int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
{
+ const _tinydir_char_t *filename;
if (dir == NULL || file == NULL)
{
errno = EINVAL;
@@ -506,45 +518,40 @@ int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
errno = ENOENT;
return -1;
}
- if (_tinydir_strlen(dir->path) +
- _tinydir_strlen(
+ filename =
#ifdef _MSC_VER
- dir->_f.cFileName
+ dir->_f.cFileName;
#else
- dir->_e->d_name
+ dir->_e->d_name;
#endif
- ) + 1 + _TINYDIR_PATH_EXTRA >=
+ if (_tinydir_strlen(dir->path) +
+ _tinydir_strlen(filename) + 1 + _TINYDIR_PATH_EXTRA >=
_TINYDIR_PATH_MAX)
{
/* the path for the file will be too long */
errno = ENAMETOOLONG;
return -1;
}
- if (_tinydir_strlen(
-#ifdef _MSC_VER
- dir->_f.cFileName
-#else
- dir->_e->d_name
-#endif
- ) >= _TINYDIR_FILENAME_MAX)
+ if (_tinydir_strlen(filename) >= _TINYDIR_FILENAME_MAX)
{
errno = ENAMETOOLONG;
return -1;
}
_tinydir_strcpy(file->path, dir->path);
- _tinydir_strcat(file->path, TINYDIR_STRING("/"));
- _tinydir_strcpy(file->name,
-#ifdef _MSC_VER
- dir->_f.cFileName
-#else
- dir->_e->d_name
-#endif
- );
- _tinydir_strcat(file->path, file->name);
+ if (_tinydir_strcmp(dir->path, TINYDIR_STRING("/")) != 0)
+ _tinydir_strcat(file->path, TINYDIR_STRING("/"));
+ _tinydir_strcpy(file->name, filename);
+ _tinydir_strcat(file->path, filename);
#ifndef _MSC_VER
#ifdef __MINGW32__
if (_tstat(
+#elif (defined _BSD_SOURCE) || (defined _DEFAULT_SOURCE) \
+ || ((defined _XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)) \
+ || ((defined _POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) \
+ || ((defined __APPLE__) && (defined __MACH__)) \
+ || (defined BSD)
+ if (lstat(
#else
if (stat(
#endif
@@ -658,34 +665,34 @@ int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path)
/* Get the parent path */
#if (defined _MSC_VER || defined __MINGW32__)
#if ((defined _MSC_VER) && (_MSC_VER >= 1400))
- _tsplitpath_s(
- path,
- drive_buf, _TINYDIR_DRIVE_MAX,
- dir_name_buf, _TINYDIR_FILENAME_MAX,
- file_name_buf, _TINYDIR_FILENAME_MAX,
- ext_buf, _TINYDIR_FILENAME_MAX);
+ errno = _tsplitpath_s(
+ path,
+ drive_buf, _TINYDIR_DRIVE_MAX,
+ dir_name_buf, _TINYDIR_FILENAME_MAX,
+ file_name_buf, _TINYDIR_FILENAME_MAX,
+ ext_buf, _TINYDIR_FILENAME_MAX);
#else
- _tsplitpath(
- path,
- drive_buf,
- dir_name_buf,
- file_name_buf,
- ext_buf);
-#endif
-
-/* _splitpath_s not work fine with only filename and widechar support */
-#ifdef _UNICODE
- if (drive_buf[0] == L'\xFEFE')
- drive_buf[0] = '\0';
- if (dir_name_buf[0] == L'\xFEFE')
- dir_name_buf[0] = '\0';
+ _tsplitpath(
+ path,
+ drive_buf,
+ dir_name_buf,
+ file_name_buf,
+ ext_buf);
#endif
if (errno)
{
- errno = EINVAL;
return -1;
}
+
+/* _splitpath_s not work fine with only filename and widechar support */
+#ifdef _UNICODE
+ if (drive_buf[0] == L'\xFEFE')
+ drive_buf[0] = '\0';
+ if (dir_name_buf[0] == L'\xFEFE')
+ dir_name_buf[0] = '\0';
+#endif
+
/* Emulate the behavior of dirname by returning "." for dir name if it's
empty */
if (drive_buf[0] == '\0' && dir_name_buf[0] == '\0')
@@ -702,9 +709,24 @@ int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path)
_tinydir_strcpy(dir_name_buf, path);
dir_name = dirname(dir_name_buf);
_tinydir_strcpy(file_name_buf, path);
- base_name =basename(file_name_buf);
+ base_name = basename(file_name_buf);
#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 */
if (tinydir_open(&dir, dir_name) == -1)
{