summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2016-12-22 14:56:47 +0100
committerAnatol Belski <ab@php.net>2016-12-22 14:56:47 +0100
commit758af77e9d1c3c6e5aea365bc0d35c385278ad5a (patch)
tree31a297b9da316030aaacb5ab4382f57ba3e46cca /win32
parentafb6ca2566691a673b7e638ffd7e3181e21d80a3 (diff)
downloadphp-git-758af77e9d1c3c6e5aea365bc0d35c385278ad5a.tar.gz
Path handling related refactorings
Primarily related to the path handling datatypes, to avoid unnecessary casts, where possible. Also some rework to avoid code dup. Probably more places are to go, even not path related, primarily to have less casts and unsigned integers where possible. That way, we've not only less warnings and casts, but are also safer with regard to the integer overflows. OFC it's not a panacea, but still significantly reduces the vulnerability potential.
Diffstat (limited to 'win32')
-rw-r--r--win32/readdir.c10
-rw-r--r--win32/readdir.h19
2 files changed, 13 insertions, 16 deletions
diff --git a/win32/readdir.c b/win32/readdir.c
index 4a6d65932f..43d5deecfd 100644
--- a/win32/readdir.c
+++ b/win32/readdir.c
@@ -24,16 +24,6 @@
extern "C" {
#endif
-/* typedef DIR - not the same as Unix */
-struct DIR_W32 {
- HANDLE handle; /* _findfirst/_findnext handle */
- int offset; /* offset into directory */
- short finished; /* 1 if there are not more files */
- WIN32_FIND_DATAW fileinfo; /* from _findfirst/_findnext */
- wchar_t *dirw; /* the dir we are reading */
- struct dirent dent; /* the dirent to return */
-};
-
DIR *opendir(const char *dir)
{
DIR *dp;
diff --git a/win32/readdir.h b/win32/readdir.h
index 4158ffc84a..73058f8804 100644
--- a/win32/readdir.h
+++ b/win32/readdir.h
@@ -8,25 +8,32 @@ extern "C" {
/*
* Structures and types used to implement opendir/readdir/closedir
- * on Windows 95/NT.
+ * on Windows.
*/
#include <config.w32.h>
-#include <stdlib.h>
-#include <sys/types.h>
+#include "ioutil.h"
#define php_readdir_r readdir_r
/* struct dirent - same as Unix */
struct dirent {
long d_ino; /* inode (always 1 in WIN32) */
- off_t d_off; /* offset to this dirent */
- unsigned short d_reclen; /* length of d_name */
- char d_name[_MAX_FNAME + 1]; /* filename (null terminated) */
+ off_t d_off; /* offset to this dirent */
+ unsigned short d_reclen; /* length of d_name */
+ char d_name[PHP_WIN32_IOUTIL_MAXPATHLEN + 1]; /* filename (null terminated) */
};
/* typedef DIR - not the same as Unix */
+struct DIR_W32 {
+ HANDLE handle; /* _findfirst/_findnext handle */
+ uint16_t offset; /* offset into directory */
+ uint8_t finished; /* 1 if there are not more files */
+ WIN32_FIND_DATAW fileinfo; /* from _findfirst/_findnext */
+ wchar_t *dirw; /* the dir we are reading */
+ struct dirent dent; /* the dirent to return */
+};
typedef struct DIR_W32 DIR;
/* Function prototypes */