Fossil SCM

Update <dirent.h> for Visual Studio to latest version 1.20.1 (April 1024). See: [http://softagalleria.net/dirent.php].

jan.nijtmans 2014-08-13 07:21 trunk
Commit a374824d923b2cef454a2dd0af923449c58d015b
1 file changed +34 -90
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -20,84 +20,24 @@
2020
* IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
2121
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2222
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2323
* OTHER DEALINGS IN THE SOFTWARE.
2424
*
25
- *
26
- * Version 1.13, Dec 12 2012, Toni Ronkko
27
- * Use traditional 8+3 file name if the name cannot be represented in the
28
- * default ANSI code page. Now compiles again with MSVC 6.0. Thanks to
29
- * Konstantin Khomoutov for testing.
30
- *
31
- * Version 1.12.1, Oct 1 2012, Toni Ronkko
32
- * Bug fix: renamed wide-character DIR structure _wDIR to _WDIR (with
33
- * capital W) in order to maintain compatibility with MingW.
34
- *
35
- * Version 1.12, Sep 30 2012, Toni Ronkko
36
- * Define PATH_MAX and NAME_MAX. Added wide-character variants _wDIR,
37
- * _wdirent, _wopendir(), _wreaddir(), _wclosedir() and _wrewinddir().
38
- * Thanks to Edgar Buerkle and Jan Nijtmans for ideas and code.
39
- *
40
- * Do not include windows.h. This allows dirent.h to be integrated more
41
- * easily into programs using winsock. Thanks to Fernando Azaldegui.
42
- *
43
- * Version 1.11, Mar 15, 2011, Toni Ronkko
44
- * Defined FILE_ATTRIBUTE_DEVICE for MSVC 6.0.
45
- *
46
- * Version 1.10, Aug 11, 2010, Toni Ronkko
47
- * Added d_type and d_namlen fields to dirent structure. The former is
48
- * especially useful for determining whether directory entry represents a
49
- * file or a directory. For more information, see
50
- * http://www.delorie.com/gnu/docs/glibc/libc_270.html
51
- *
52
- * Improved conformance to the standards. For example, errno is now set
53
- * properly on failure and assert() is never used. Thanks to Peter Brockam
54
- * for suggestions.
55
- *
56
- * Fixed a bug in rewinddir(): when using relative directory names, change
57
- * of working directory no longer causes rewinddir() to fail.
58
- *
59
- * Version 1.9, Dec 15, 2009, John Cunningham
60
- * Added rewinddir member function
61
- *
62
- * Version 1.8, Jan 18, 2008, Toni Ronkko
63
- * Using FindFirstFileA and WIN32_FIND_DATAA to avoid converting string
64
- * between multi-byte and unicode representations. This makes the
65
- * code simpler and also allows the code to be compiled under MingW. Thanks
66
- * to Azriel Fasten for the suggestion.
67
- *
68
- * Mar 4, 2007, Toni Ronkko
69
- * Bug fix: due to the strncpy_s() function this file only compiled in
70
- * Visual Studio 2005. Using the new string functions only when the
71
- * compiler version allows.
72
- *
73
- * Nov 2, 2006, Toni Ronkko
74
- * Major update: removed support for Watcom C, MS-DOS and Turbo C to
75
- * simplify the file, updated the code to compile cleanly on Visual
76
- * Studio 2005 with both unicode and multi-byte character strings,
77
- * removed rewinddir() as it had a bug.
78
- *
79
- * Aug 20, 2006, Toni Ronkko
80
- * Removed all remarks about MSVC 1.0, which is antiqued now. Simplified
81
- * comments by removing SGML tags.
82
- *
83
- * May 14 2002, Toni Ronkko
84
- * Embedded the function definitions directly to the header so that no
85
- * source modules need to be included in the Visual Studio project. Removed
86
- * all the dependencies to other projects so that this header file can be
87
- * used independently.
88
- *
89
- * May 28 1998, Toni Ronkko
90
- * First version.
91
- *****************************************************************************/
25
+ * $Id: dirent.h,v 1.20 2014/03/19 17:52:23 tronkko Exp $
26
+ */
9227
#ifndef DIRENT_H
9328
#define DIRENT_H
9429
95
-#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && defined(_M_IX86)
30
+/*
31
+ * Define architecture flags so we don't need to include windows.h.
32
+ * Avoiding windows.h makes it simpler to use windows sockets in conjunction
33
+ * with dirent.h.
34
+ */
35
+#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86)
9636
# define _X86_
9737
#endif
98
-#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && defined(_M_AMD64)
38
+#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64)
9939
#define _AMD64_
10040
#endif
10141
10242
#include <stdio.h>
10343
#include <stdarg.h>
@@ -213,11 +153,11 @@
213153
214154
/* Return the exact length of d_namlen without zero terminator */
215155
#define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
216156
217157
/* Return number of bytes needed to store d_namlen */
218
-#define _D_ALLOC_NAMLEN(p) (PATH_MAX + 1)
158
+#define _D_ALLOC_NAMLEN(p) (PATH_MAX)
219159
220160
221161
#ifdef __cplusplus
222162
extern "C" {
223163
#endif
@@ -227,11 +167,11 @@
227167
struct _wdirent {
228168
long d_ino; /* Always zero */
229169
unsigned short d_reclen; /* Structure size */
230170
size_t d_namlen; /* Length of name without \0 */
231171
int d_type; /* File type */
232
- wchar_t d_name[PATH_MAX + 1]; /* File name */
172
+ wchar_t d_name[PATH_MAX]; /* File name */
233173
};
234174
typedef struct _wdirent _wdirent;
235175
236176
struct _WDIR {
237177
struct _wdirent ent; /* Current directory entry */
@@ -261,11 +201,11 @@
261201
struct dirent {
262202
long d_ino; /* Always zero */
263203
unsigned short d_reclen; /* Structure size */
264204
size_t d_namlen; /* Length of name without \0 */
265205
int d_type; /* File type */
266
- char d_name[PATH_MAX + 1]; /* File name */
206
+ char d_name[PATH_MAX]; /* File name */
267207
};
268208
typedef struct dirent dirent;
269209
270210
struct DIR {
271211
struct dirent ent;
@@ -423,11 +363,11 @@
423363
* Copy file name as wide-character string. If the file name is too
424364
* long to fit in to the destination buffer, then truncate file name
425365
* to PATH_MAX characters and zero-terminate the buffer.
426366
*/
427367
n = 0;
428
- while (n < PATH_MAX && datap->cFileName[n] != 0) {
368
+ while (n + 1 < PATH_MAX && datap->cFileName[n] != 0) {
429369
entp->d_name[n] = datap->cFileName[n];
430370
n++;
431371
}
432372
dirp->ent.d_name[n] = 0;
433373
@@ -592,16 +532,15 @@
592532
}
593533
594534
/* Allocate memory for DIR structure */
595535
dirp = (DIR*) malloc (sizeof (struct DIR));
596536
if (dirp) {
597
- wchar_t wname[PATH_MAX + 1];
537
+ wchar_t wname[PATH_MAX];
598538
size_t n;
599539
600540
/* Convert directory name to wide-character string */
601
- error = dirent_mbstowcs_s(
602
- &n, wname, PATH_MAX + 1, dirname, PATH_MAX);
541
+ error = dirent_mbstowcs_s (&n, wname, PATH_MAX, dirname, PATH_MAX);
603542
if (!error) {
604543
605544
/* Open directory stream using wide-character name */
606545
dirp->wdirp = _wopendir (wname);
607546
if (dirp->wdirp) {
@@ -662,11 +601,11 @@
662601
size_t n;
663602
int error;
664603
665604
/* Attempt to convert file name to multi-byte string */
666605
error = dirent_wcstombs_s(
667
- &n, dirp->ent.d_name, MAX_PATH + 1, datap->cFileName, MAX_PATH);
606
+ &n, dirp->ent.d_name, PATH_MAX, datap->cFileName, PATH_MAX);
668607
669608
/*
670609
* If the file name cannot be represented by a multi-byte string,
671610
* then attempt to use old 8+3 file name. This allows traditional
672611
* Unix-code to access some file names despite of unicode
@@ -676,13 +615,12 @@
676615
* name unless the file system provides one. At least
677616
* VirtualBox shared folders fail to do this.
678617
*/
679618
if (error && datap->cAlternateFileName[0] != '\0') {
680619
error = dirent_wcstombs_s(
681
- &n, dirp->ent.d_name, MAX_PATH + 1, datap->cAlternateFileName,
682
- sizeof (datap->cAlternateFileName) /
683
- sizeof (datap->cAlternateFileName[0]));
620
+ &n, dirp->ent.d_name, PATH_MAX,
621
+ datap->cAlternateFileName, PATH_MAX);
684622
}
685623
686624
if (!error) {
687625
DWORD attr;
688626
@@ -787,16 +725,19 @@
787725
#else
788726
789727
/* Older Visual Studio or non-Microsoft compiler */
790728
size_t n;
791729
792
- /* Convert to wide-character string */
793
- n = mbstowcs (wcstr, mbstr, count);
794
- if (n < sizeInWords) {
730
+ /* Convert to wide-character string (or count characters) */
731
+ n = mbstowcs (wcstr, mbstr, sizeInWords);
732
+ if (!wcstr || n < count) {
795733
796734
/* Zero-terminate output buffer */
797
- if (wcstr) {
735
+ if (wcstr && sizeInWords) {
736
+ if (n >= sizeInWords) {
737
+ n = sizeInWords - 1;
738
+ }
798739
wcstr[n] = 0;
799740
}
800741
801742
/* Length of resuting multi-byte string WITH zero terminator */
802743
if (pReturnValue) {
@@ -821,11 +762,11 @@
821762
/* Convert wide-character string to multi-byte string */
822763
static int
823764
dirent_wcstombs_s(
824765
size_t *pReturnValue,
825766
char *mbstr,
826
- size_t sizeInBytes,
767
+ size_t sizeInBytes, /* max size of mbstr */
827768
const wchar_t *wcstr,
828769
size_t count)
829770
{
830771
int error;
831772
@@ -837,16 +778,19 @@
837778
#else
838779
839780
/* Older Visual Studio or non-Microsoft compiler */
840781
size_t n;
841782
842
- /* Convert to multi-byte string */
843
- n = wcstombs (mbstr, wcstr, count);
844
- if (n < sizeInBytes) {
783
+ /* Convert to multi-byte string (or count the number of bytes needed) */
784
+ n = wcstombs (mbstr, wcstr, sizeInBytes);
785
+ if (!mbstr || n < count) {
845786
846787
/* Zero-terminate output buffer */
847
- if (mbstr) {
788
+ if (mbstr && sizeInBytes) {
789
+ if (n >= sizeInBytes) {
790
+ n = sizeInBytes - 1;
791
+ }
848792
mbstr[n] = '\0';
849793
}
850794
851795
/* Lenght of resulting multi-bytes string WITH zero-terminator */
852796
if (pReturnValue) {
@@ -871,11 +815,11 @@
871815
/* Set errno variable */
872816
static void
873817
dirent_set_errno(
874818
int error)
875819
{
876
-#if defined(_MSC_VER) && _MSC_VER >= 1400
820
+#if defined(_MSC_VER) && _MSC_VER >= 1400
877821
878822
/* Microsoft Visual Studio 2005 and later */
879823
_set_errno (error);
880824
881825
#else
882826
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -20,84 +20,24 @@
20 * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Version 1.13, Dec 12 2012, Toni Ronkko
27 * Use traditional 8+3 file name if the name cannot be represented in the
28 * default ANSI code page. Now compiles again with MSVC 6.0. Thanks to
29 * Konstantin Khomoutov for testing.
30 *
31 * Version 1.12.1, Oct 1 2012, Toni Ronkko
32 * Bug fix: renamed wide-character DIR structure _wDIR to _WDIR (with
33 * capital W) in order to maintain compatibility with MingW.
34 *
35 * Version 1.12, Sep 30 2012, Toni Ronkko
36 * Define PATH_MAX and NAME_MAX. Added wide-character variants _wDIR,
37 * _wdirent, _wopendir(), _wreaddir(), _wclosedir() and _wrewinddir().
38 * Thanks to Edgar Buerkle and Jan Nijtmans for ideas and code.
39 *
40 * Do not include windows.h. This allows dirent.h to be integrated more
41 * easily into programs using winsock. Thanks to Fernando Azaldegui.
42 *
43 * Version 1.11, Mar 15, 2011, Toni Ronkko
44 * Defined FILE_ATTRIBUTE_DEVICE for MSVC 6.0.
45 *
46 * Version 1.10, Aug 11, 2010, Toni Ronkko
47 * Added d_type and d_namlen fields to dirent structure. The former is
48 * especially useful for determining whether directory entry represents a
49 * file or a directory. For more information, see
50 * http://www.delorie.com/gnu/docs/glibc/libc_270.html
51 *
52 * Improved conformance to the standards. For example, errno is now set
53 * properly on failure and assert() is never used. Thanks to Peter Brockam
54 * for suggestions.
55 *
56 * Fixed a bug in rewinddir(): when using relative directory names, change
57 * of working directory no longer causes rewinddir() to fail.
58 *
59 * Version 1.9, Dec 15, 2009, John Cunningham
60 * Added rewinddir member function
61 *
62 * Version 1.8, Jan 18, 2008, Toni Ronkko
63 * Using FindFirstFileA and WIN32_FIND_DATAA to avoid converting string
64 * between multi-byte and unicode representations. This makes the
65 * code simpler and also allows the code to be compiled under MingW. Thanks
66 * to Azriel Fasten for the suggestion.
67 *
68 * Mar 4, 2007, Toni Ronkko
69 * Bug fix: due to the strncpy_s() function this file only compiled in
70 * Visual Studio 2005. Using the new string functions only when the
71 * compiler version allows.
72 *
73 * Nov 2, 2006, Toni Ronkko
74 * Major update: removed support for Watcom C, MS-DOS and Turbo C to
75 * simplify the file, updated the code to compile cleanly on Visual
76 * Studio 2005 with both unicode and multi-byte character strings,
77 * removed rewinddir() as it had a bug.
78 *
79 * Aug 20, 2006, Toni Ronkko
80 * Removed all remarks about MSVC 1.0, which is antiqued now. Simplified
81 * comments by removing SGML tags.
82 *
83 * May 14 2002, Toni Ronkko
84 * Embedded the function definitions directly to the header so that no
85 * source modules need to be included in the Visual Studio project. Removed
86 * all the dependencies to other projects so that this header file can be
87 * used independently.
88 *
89 * May 28 1998, Toni Ronkko
90 * First version.
91 *****************************************************************************/
92 #ifndef DIRENT_H
93 #define DIRENT_H
94
95 #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && defined(_M_IX86)
 
 
 
 
 
96 # define _X86_
97 #endif
98 #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && defined(_M_AMD64)
99 #define _AMD64_
100 #endif
101
102 #include <stdio.h>
103 #include <stdarg.h>
@@ -213,11 +153,11 @@
213
214 /* Return the exact length of d_namlen without zero terminator */
215 #define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
216
217 /* Return number of bytes needed to store d_namlen */
218 #define _D_ALLOC_NAMLEN(p) (PATH_MAX + 1)
219
220
221 #ifdef __cplusplus
222 extern "C" {
223 #endif
@@ -227,11 +167,11 @@
227 struct _wdirent {
228 long d_ino; /* Always zero */
229 unsigned short d_reclen; /* Structure size */
230 size_t d_namlen; /* Length of name without \0 */
231 int d_type; /* File type */
232 wchar_t d_name[PATH_MAX + 1]; /* File name */
233 };
234 typedef struct _wdirent _wdirent;
235
236 struct _WDIR {
237 struct _wdirent ent; /* Current directory entry */
@@ -261,11 +201,11 @@
261 struct dirent {
262 long d_ino; /* Always zero */
263 unsigned short d_reclen; /* Structure size */
264 size_t d_namlen; /* Length of name without \0 */
265 int d_type; /* File type */
266 char d_name[PATH_MAX + 1]; /* File name */
267 };
268 typedef struct dirent dirent;
269
270 struct DIR {
271 struct dirent ent;
@@ -423,11 +363,11 @@
423 * Copy file name as wide-character string. If the file name is too
424 * long to fit in to the destination buffer, then truncate file name
425 * to PATH_MAX characters and zero-terminate the buffer.
426 */
427 n = 0;
428 while (n < PATH_MAX && datap->cFileName[n] != 0) {
429 entp->d_name[n] = datap->cFileName[n];
430 n++;
431 }
432 dirp->ent.d_name[n] = 0;
433
@@ -592,16 +532,15 @@
592 }
593
594 /* Allocate memory for DIR structure */
595 dirp = (DIR*) malloc (sizeof (struct DIR));
596 if (dirp) {
597 wchar_t wname[PATH_MAX + 1];
598 size_t n;
599
600 /* Convert directory name to wide-character string */
601 error = dirent_mbstowcs_s(
602 &n, wname, PATH_MAX + 1, dirname, PATH_MAX);
603 if (!error) {
604
605 /* Open directory stream using wide-character name */
606 dirp->wdirp = _wopendir (wname);
607 if (dirp->wdirp) {
@@ -662,11 +601,11 @@
662 size_t n;
663 int error;
664
665 /* Attempt to convert file name to multi-byte string */
666 error = dirent_wcstombs_s(
667 &n, dirp->ent.d_name, MAX_PATH + 1, datap->cFileName, MAX_PATH);
668
669 /*
670 * If the file name cannot be represented by a multi-byte string,
671 * then attempt to use old 8+3 file name. This allows traditional
672 * Unix-code to access some file names despite of unicode
@@ -676,13 +615,12 @@
676 * name unless the file system provides one. At least
677 * VirtualBox shared folders fail to do this.
678 */
679 if (error && datap->cAlternateFileName[0] != '\0') {
680 error = dirent_wcstombs_s(
681 &n, dirp->ent.d_name, MAX_PATH + 1, datap->cAlternateFileName,
682 sizeof (datap->cAlternateFileName) /
683 sizeof (datap->cAlternateFileName[0]));
684 }
685
686 if (!error) {
687 DWORD attr;
688
@@ -787,16 +725,19 @@
787 #else
788
789 /* Older Visual Studio or non-Microsoft compiler */
790 size_t n;
791
792 /* Convert to wide-character string */
793 n = mbstowcs (wcstr, mbstr, count);
794 if (n < sizeInWords) {
795
796 /* Zero-terminate output buffer */
797 if (wcstr) {
 
 
 
798 wcstr[n] = 0;
799 }
800
801 /* Length of resuting multi-byte string WITH zero terminator */
802 if (pReturnValue) {
@@ -821,11 +762,11 @@
821 /* Convert wide-character string to multi-byte string */
822 static int
823 dirent_wcstombs_s(
824 size_t *pReturnValue,
825 char *mbstr,
826 size_t sizeInBytes,
827 const wchar_t *wcstr,
828 size_t count)
829 {
830 int error;
831
@@ -837,16 +778,19 @@
837 #else
838
839 /* Older Visual Studio or non-Microsoft compiler */
840 size_t n;
841
842 /* Convert to multi-byte string */
843 n = wcstombs (mbstr, wcstr, count);
844 if (n < sizeInBytes) {
845
846 /* Zero-terminate output buffer */
847 if (mbstr) {
 
 
 
848 mbstr[n] = '\0';
849 }
850
851 /* Lenght of resulting multi-bytes string WITH zero-terminator */
852 if (pReturnValue) {
@@ -871,11 +815,11 @@
871 /* Set errno variable */
872 static void
873 dirent_set_errno(
874 int error)
875 {
876 #if defined(_MSC_VER) && _MSC_VER >= 1400
877
878 /* Microsoft Visual Studio 2005 and later */
879 _set_errno (error);
880
881 #else
882
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -20,84 +20,24 @@
20 * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * $Id: dirent.h,v 1.20 2014/03/19 17:52:23 tronkko Exp $
26 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27 #ifndef DIRENT_H
28 #define DIRENT_H
29
30 /*
31 * Define architecture flags so we don't need to include windows.h.
32 * Avoiding windows.h makes it simpler to use windows sockets in conjunction
33 * with dirent.h.
34 */
35 #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86)
36 # define _X86_
37 #endif
38 #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64)
39 #define _AMD64_
40 #endif
41
42 #include <stdio.h>
43 #include <stdarg.h>
@@ -213,11 +153,11 @@
153
154 /* Return the exact length of d_namlen without zero terminator */
155 #define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
156
157 /* Return number of bytes needed to store d_namlen */
158 #define _D_ALLOC_NAMLEN(p) (PATH_MAX)
159
160
161 #ifdef __cplusplus
162 extern "C" {
163 #endif
@@ -227,11 +167,11 @@
167 struct _wdirent {
168 long d_ino; /* Always zero */
169 unsigned short d_reclen; /* Structure size */
170 size_t d_namlen; /* Length of name without \0 */
171 int d_type; /* File type */
172 wchar_t d_name[PATH_MAX]; /* File name */
173 };
174 typedef struct _wdirent _wdirent;
175
176 struct _WDIR {
177 struct _wdirent ent; /* Current directory entry */
@@ -261,11 +201,11 @@
201 struct dirent {
202 long d_ino; /* Always zero */
203 unsigned short d_reclen; /* Structure size */
204 size_t d_namlen; /* Length of name without \0 */
205 int d_type; /* File type */
206 char d_name[PATH_MAX]; /* File name */
207 };
208 typedef struct dirent dirent;
209
210 struct DIR {
211 struct dirent ent;
@@ -423,11 +363,11 @@
363 * Copy file name as wide-character string. If the file name is too
364 * long to fit in to the destination buffer, then truncate file name
365 * to PATH_MAX characters and zero-terminate the buffer.
366 */
367 n = 0;
368 while (n + 1 < PATH_MAX && datap->cFileName[n] != 0) {
369 entp->d_name[n] = datap->cFileName[n];
370 n++;
371 }
372 dirp->ent.d_name[n] = 0;
373
@@ -592,16 +532,15 @@
532 }
533
534 /* Allocate memory for DIR structure */
535 dirp = (DIR*) malloc (sizeof (struct DIR));
536 if (dirp) {
537 wchar_t wname[PATH_MAX];
538 size_t n;
539
540 /* Convert directory name to wide-character string */
541 error = dirent_mbstowcs_s (&n, wname, PATH_MAX, dirname, PATH_MAX);
 
542 if (!error) {
543
544 /* Open directory stream using wide-character name */
545 dirp->wdirp = _wopendir (wname);
546 if (dirp->wdirp) {
@@ -662,11 +601,11 @@
601 size_t n;
602 int error;
603
604 /* Attempt to convert file name to multi-byte string */
605 error = dirent_wcstombs_s(
606 &n, dirp->ent.d_name, PATH_MAX, datap->cFileName, PATH_MAX);
607
608 /*
609 * If the file name cannot be represented by a multi-byte string,
610 * then attempt to use old 8+3 file name. This allows traditional
611 * Unix-code to access some file names despite of unicode
@@ -676,13 +615,12 @@
615 * name unless the file system provides one. At least
616 * VirtualBox shared folders fail to do this.
617 */
618 if (error && datap->cAlternateFileName[0] != '\0') {
619 error = dirent_wcstombs_s(
620 &n, dirp->ent.d_name, PATH_MAX,
621 datap->cAlternateFileName, PATH_MAX);
 
622 }
623
624 if (!error) {
625 DWORD attr;
626
@@ -787,16 +725,19 @@
725 #else
726
727 /* Older Visual Studio or non-Microsoft compiler */
728 size_t n;
729
730 /* Convert to wide-character string (or count characters) */
731 n = mbstowcs (wcstr, mbstr, sizeInWords);
732 if (!wcstr || n < count) {
733
734 /* Zero-terminate output buffer */
735 if (wcstr && sizeInWords) {
736 if (n >= sizeInWords) {
737 n = sizeInWords - 1;
738 }
739 wcstr[n] = 0;
740 }
741
742 /* Length of resuting multi-byte string WITH zero terminator */
743 if (pReturnValue) {
@@ -821,11 +762,11 @@
762 /* Convert wide-character string to multi-byte string */
763 static int
764 dirent_wcstombs_s(
765 size_t *pReturnValue,
766 char *mbstr,
767 size_t sizeInBytes, /* max size of mbstr */
768 const wchar_t *wcstr,
769 size_t count)
770 {
771 int error;
772
@@ -837,16 +778,19 @@
778 #else
779
780 /* Older Visual Studio or non-Microsoft compiler */
781 size_t n;
782
783 /* Convert to multi-byte string (or count the number of bytes needed) */
784 n = wcstombs (mbstr, wcstr, sizeInBytes);
785 if (!mbstr || n < count) {
786
787 /* Zero-terminate output buffer */
788 if (mbstr && sizeInBytes) {
789 if (n >= sizeInBytes) {
790 n = sizeInBytes - 1;
791 }
792 mbstr[n] = '\0';
793 }
794
795 /* Lenght of resulting multi-bytes string WITH zero-terminator */
796 if (pReturnValue) {
@@ -871,11 +815,11 @@
815 /* Set errno variable */
816 static void
817 dirent_set_errno(
818 int error)
819 {
820 #if defined(_MSC_VER) && _MSC_VER >= 1400
821
822 /* Microsoft Visual Studio 2005 and later */
823 _set_errno (error);
824
825 #else
826

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button