Fossil SCM

previous commit fixed the MSVC build, but broke the mingw build. Now fix both of them.

jan.nijtmans 2012-09-24 07:00 trunk
Commit 1ef58e524675c7ae990e4a8da936835fd59d604f
+7 -5
--- src/file.c
+++ src/file.c
@@ -1009,15 +1009,17 @@
10091009
** Portable unicode implementation of opendir()
10101010
*/
10111011
#if INTERFACE
10121012
10131013
#include <dirent.h>
1014
-#define FOSSIL_DIR DIR
1015
-#define fossil_dirent dirent
1016
-#define fossil_opendir opendir
1017
-#define fossil_readdir readdir
1018
-#define fossil_closedir closedir
1014
+#if defined(_WIN32)
1015
+# define DIR _WDIR
1016
+# define dirent _wdirent
1017
+# define opendir _wopendir
1018
+# define readdir _wreaddir
1019
+# define closedir _wclosedir
1020
+#endif /* _WIN32 */
10191021
10201022
#endif /* INTERFACE */
10211023
10221024
10231025
10241026
--- src/file.c
+++ src/file.c
@@ -1009,15 +1009,17 @@
1009 ** Portable unicode implementation of opendir()
1010 */
1011 #if INTERFACE
1012
1013 #include <dirent.h>
1014 #define FOSSIL_DIR DIR
1015 #define fossil_dirent dirent
1016 #define fossil_opendir opendir
1017 #define fossil_readdir readdir
1018 #define fossil_closedir closedir
 
 
1019
1020 #endif /* INTERFACE */
1021
1022
1023
1024
--- src/file.c
+++ src/file.c
@@ -1009,15 +1009,17 @@
1009 ** Portable unicode implementation of opendir()
1010 */
1011 #if INTERFACE
1012
1013 #include <dirent.h>
1014 #if defined(_WIN32)
1015 # define DIR _WDIR
1016 # define dirent _wdirent
1017 # define opendir _wopendir
1018 # define readdir _wreaddir
1019 # define closedir _wclosedir
1020 #endif /* _WIN32 */
1021
1022 #endif /* INTERFACE */
1023
1024
1025
1026
+5 -5
--- src/rebuild.c
+++ src/rebuild.c
@@ -817,21 +817,21 @@
817817
/*
818818
** Recursively read all files from the directory zPath and install
819819
** every file read as a new artifact in the repository.
820820
*/
821821
void recon_read_dir(char *zPath){
822
- FOSSIL_DIR *d;
823
- struct fossil_dirent *pEntry;
822
+ DIR *d;
823
+ struct dirent *pEntry;
824824
Blob aContent; /* content of the just read artifact */
825825
static int nFileRead = 0;
826826
void *zUnicodePath;
827827
char *zUtf8Name;
828828
829829
zUnicodePath = fossil_utf8_to_unicode(zPath);
830
- d = fossil_opendir(zUnicodePath);
830
+ d = opendir(zUnicodePath);
831831
if( d ){
832
- while( (pEntry=fossil_readdir(d))!=0 ){
832
+ while( (pEntry=readdir(d))!=0 ){
833833
Blob path;
834834
char *zSubpath;
835835
836836
if( pEntry->d_name[0]=='.' ){
837837
continue;
@@ -853,11 +853,11 @@
853853
blob_reset(&aContent);
854854
free(zSubpath);
855855
fossil_print("\r%d", ++nFileRead);
856856
fflush(stdout);
857857
}
858
- fossil_closedir(d);
858
+ closedir(d);
859859
}else {
860860
fossil_panic("encountered error %d while trying to open \"%s\".",
861861
errno, g.argv[3]);
862862
}
863863
fossil_mbcs_free(zUnicodePath);
864864
--- src/rebuild.c
+++ src/rebuild.c
@@ -817,21 +817,21 @@
817 /*
818 ** Recursively read all files from the directory zPath and install
819 ** every file read as a new artifact in the repository.
820 */
821 void recon_read_dir(char *zPath){
822 FOSSIL_DIR *d;
823 struct fossil_dirent *pEntry;
824 Blob aContent; /* content of the just read artifact */
825 static int nFileRead = 0;
826 void *zUnicodePath;
827 char *zUtf8Name;
828
829 zUnicodePath = fossil_utf8_to_unicode(zPath);
830 d = fossil_opendir(zUnicodePath);
831 if( d ){
832 while( (pEntry=fossil_readdir(d))!=0 ){
833 Blob path;
834 char *zSubpath;
835
836 if( pEntry->d_name[0]=='.' ){
837 continue;
@@ -853,11 +853,11 @@
853 blob_reset(&aContent);
854 free(zSubpath);
855 fossil_print("\r%d", ++nFileRead);
856 fflush(stdout);
857 }
858 fossil_closedir(d);
859 }else {
860 fossil_panic("encountered error %d while trying to open \"%s\".",
861 errno, g.argv[3]);
862 }
863 fossil_mbcs_free(zUnicodePath);
864
--- src/rebuild.c
+++ src/rebuild.c
@@ -817,21 +817,21 @@
817 /*
818 ** Recursively read all files from the directory zPath and install
819 ** every file read as a new artifact in the repository.
820 */
821 void recon_read_dir(char *zPath){
822 DIR *d;
823 struct dirent *pEntry;
824 Blob aContent; /* content of the just read artifact */
825 static int nFileRead = 0;
826 void *zUnicodePath;
827 char *zUtf8Name;
828
829 zUnicodePath = fossil_utf8_to_unicode(zPath);
830 d = opendir(zUnicodePath);
831 if( d ){
832 while( (pEntry=readdir(d))!=0 ){
833 Blob path;
834 char *zSubpath;
835
836 if( pEntry->d_name[0]=='.' ){
837 continue;
@@ -853,11 +853,11 @@
853 blob_reset(&aContent);
854 free(zSubpath);
855 fossil_print("\r%d", ++nFileRead);
856 fflush(stdout);
857 }
858 closedir(d);
859 }else {
860 fossil_panic("encountered error %d while trying to open \"%s\".",
861 errno, g.argv[3]);
862 }
863 fossil_mbcs_free(zUnicodePath);
864
+5 -5
--- src/vfile.c
+++ src/vfile.c
@@ -376,14 +376,14 @@
376376
** Any files or directories that match the glob pattern pIgnore are
377377
** excluded from the scan. Name matching occurs after the first
378378
** nPrefix characters are elided from the filename.
379379
*/
380380
void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
381
- FOSSIL_DIR *d;
381
+ DIR *d;
382382
int origSize;
383383
const char *zDir;
384
- struct fossil_dirent *pEntry;
384
+ struct dirent *pEntry;
385385
int skipAll = 0;
386386
static Stmt ins;
387387
static int depth = 0;
388388
void *zMbcs;
389389
@@ -403,13 +403,13 @@
403403
}
404404
depth++;
405405
406406
zDir = blob_str(pPath);
407407
zMbcs = fossil_utf8_to_unicode(zDir);
408
- d = fossil_opendir(zMbcs);
408
+ d = opendir(zMbcs);
409409
if( d ){
410
- while( (pEntry=fossil_readdir(d))!=0 ){
410
+ while( (pEntry=readdir(d))!=0 ){
411411
char *zPath;
412412
char *zUtf8;
413413
if( pEntry->d_name[0]=='.' ){
414414
if( !allFlag ) continue;
415415
if( pEntry->d_name[1]==0 ) continue;
@@ -430,11 +430,11 @@
430430
db_step(&ins);
431431
db_reset(&ins);
432432
}
433433
blob_resize(pPath, origSize);
434434
}
435
- fossil_closedir(d);
435
+ closedir(d);
436436
}
437437
fossil_mbcs_free(zMbcs);
438438
439439
depth--;
440440
if( depth==0 ){
441441
--- src/vfile.c
+++ src/vfile.c
@@ -376,14 +376,14 @@
376 ** Any files or directories that match the glob pattern pIgnore are
377 ** excluded from the scan. Name matching occurs after the first
378 ** nPrefix characters are elided from the filename.
379 */
380 void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
381 FOSSIL_DIR *d;
382 int origSize;
383 const char *zDir;
384 struct fossil_dirent *pEntry;
385 int skipAll = 0;
386 static Stmt ins;
387 static int depth = 0;
388 void *zMbcs;
389
@@ -403,13 +403,13 @@
403 }
404 depth++;
405
406 zDir = blob_str(pPath);
407 zMbcs = fossil_utf8_to_unicode(zDir);
408 d = fossil_opendir(zMbcs);
409 if( d ){
410 while( (pEntry=fossil_readdir(d))!=0 ){
411 char *zPath;
412 char *zUtf8;
413 if( pEntry->d_name[0]=='.' ){
414 if( !allFlag ) continue;
415 if( pEntry->d_name[1]==0 ) continue;
@@ -430,11 +430,11 @@
430 db_step(&ins);
431 db_reset(&ins);
432 }
433 blob_resize(pPath, origSize);
434 }
435 fossil_closedir(d);
436 }
437 fossil_mbcs_free(zMbcs);
438
439 depth--;
440 if( depth==0 ){
441
--- src/vfile.c
+++ src/vfile.c
@@ -376,14 +376,14 @@
376 ** Any files or directories that match the glob pattern pIgnore are
377 ** excluded from the scan. Name matching occurs after the first
378 ** nPrefix characters are elided from the filename.
379 */
380 void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
381 DIR *d;
382 int origSize;
383 const char *zDir;
384 struct dirent *pEntry;
385 int skipAll = 0;
386 static Stmt ins;
387 static int depth = 0;
388 void *zMbcs;
389
@@ -403,13 +403,13 @@
403 }
404 depth++;
405
406 zDir = blob_str(pPath);
407 zMbcs = fossil_utf8_to_unicode(zDir);
408 d = opendir(zMbcs);
409 if( d ){
410 while( (pEntry=readdir(d))!=0 ){
411 char *zPath;
412 char *zUtf8;
413 if( pEntry->d_name[0]=='.' ){
414 if( !allFlag ) continue;
415 if( pEntry->d_name[1]==0 ) continue;
@@ -430,11 +430,11 @@
430 db_step(&ins);
431 db_reset(&ins);
432 }
433 blob_resize(pPath, origSize);
434 }
435 closedir(d);
436 }
437 fossil_mbcs_free(zMbcs);
438
439 depth--;
440 if( depth==0 ){
441
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -154,37 +154,38 @@
154154
155155
#ifdef __cplusplus
156156
extern "C" {
157157
#endif
158158
159
-typedef struct dirent
159
+typedef struct _wdirent
160160
{
161161
WCHAR d_name[MAX_PATH + 1]; /* File name */
162162
size_t d_namlen; /* Length of name without \0 */
163163
int d_type; /* File type */
164
-} dirent;
164
+} _wdirent;
165165
166166
167
-typedef struct DIR
167
+typedef struct _WDIR
168168
{
169
- dirent curentry; /* Current directory entry */
169
+ _wdirent curentry; /* Current directory entry */
170170
WIN32_FIND_DATAW find_data; /* Private file data */
171171
int cached; /* True if data is valid */
172172
HANDLE search_handle; /* Win32 search handle */
173173
WCHAR patt[MAX_PATH + 3]; /* Initial directory name */
174
-} DIR;
174
+} _WDIR;
175175
176176
177177
/* Forward declarations */
178
-static DIR *opendir(const WCHAR *dirname);
179
-static struct dirent *readdir(DIR *dirp);
180
-static int closedir(DIR *dirp);
181
-static void rewinddir(DIR* dirp);
178
+static _WDIR *_wopendir(const WCHAR *dirname);
179
+static struct _wdirent *_wreaddir(_WDIR *dirp);
180
+static int _wclosedir(_WDIR *dirp);
181
+static void _wrewinddir(_WDIR* dirp);
182182
183183
184184
/* Use the new safe string functions introduced in Visual Studio 2005 */
185185
#if defined(_MSC_VER) && _MSC_VER >= 1400
186
+
186187
# define DIRENT_STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE)
187188
#else
188189
# define DIRENT_STRNCPY(dest,src,size) wcsncpy((dest),(src),(size))
189190
#endif
190191
@@ -199,13 +200,13 @@
199200
/*****************************************************************************
200201
* Open directory stream DIRNAME for read and return a pointer to the
201202
* internal working area that is used to retrieve individual directory
202203
* entries.
203204
*/
204
-static DIR *opendir(const WCHAR *dirname)
205
+static _WDIR *_wopendir(const WCHAR *dirname)
205206
{
206
- DIR *dirp;
207
+ _WDIR *dirp;
207208
208209
/* ensure that the resulting search pattern will be a valid file name */
209210
if (dirname == NULL) {
210211
DIRENT_SET_ERRNO (ENOENT);
211212
return NULL;
@@ -213,12 +214,12 @@
213214
if (wcslen (dirname) + 3 >= MAX_PATH) {
214215
DIRENT_SET_ERRNO (ENAMETOOLONG);
215216
return NULL;
216217
}
217218
218
- /* construct new DIR structure */
219
- dirp = (DIR*) malloc (sizeof (struct DIR));
219
+ /* construct new _WDIR structure */
220
+ dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
220221
if (dirp != NULL) {
221222
int error;
222223
223224
/*
224225
* Convert relative directory name to an absolute one. This
@@ -262,17 +263,17 @@
262263
return dirp;
263264
}
264265
265266
266267
/*****************************************************************************
267
- * Read a directory entry, and return a pointer to a dirent structure
268
+ * Read a directory entry, and return a pointer to a _wdirent structure
268269
* containing the name of the entry in d_name field. Individual directory
269270
* entries returned by this very function include regular files,
270271
* sub-directories, pseudo-directories "." and "..", but also volume labels,
271272
* hidden files and system files may be returned.
272273
*/
273
-static struct dirent *readdir(DIR *dirp)
274
+static struct _wdirent *_wreaddir(_WDIR *dirp)
274275
{
275276
DWORD attr;
276277
if (dirp == NULL) {
277278
/* directory stream did not open */
278279
DIRENT_SET_ERRNO (EBADF);
@@ -318,14 +319,14 @@
318319
}
319320
320321
321322
/*****************************************************************************
322323
* Close directory stream opened by opendir() function. Close of the
323
- * directory stream invalidates the DIR structure as well as any previously
324
+ * directory stream invalidates the _WDIR structure as well as any previously
324325
* read directory entry.
325326
*/
326
-static int closedir(DIR *dirp)
327
+static int _wclosedir(_WDIR *dirp)
327328
{
328329
if (dirp == NULL) {
329330
/* invalid directory stream */
330331
DIRENT_SET_ERRNO (EBADF);
331332
return -1;
@@ -347,11 +348,11 @@
347348
* beginning of the directory. It also causes the directory stream to refer
348349
* to the current state of the corresponding directory, as a call to opendir()
349350
* would have done. If dirp does not refer to a directory stream, the effect
350351
* is undefined.
351352
*/
352
-static void rewinddir(DIR* dirp)
353
+static void _wrewinddir(_WDIR* dirp)
353354
{
354355
if (dirp != NULL) {
355356
/* release search handle */
356357
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
357358
FindClose (dirp->search_handle);
358359
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -154,37 +154,38 @@
154
155 #ifdef __cplusplus
156 extern "C" {
157 #endif
158
159 typedef struct dirent
160 {
161 WCHAR d_name[MAX_PATH + 1]; /* File name */
162 size_t d_namlen; /* Length of name without \0 */
163 int d_type; /* File type */
164 } dirent;
165
166
167 typedef struct DIR
168 {
169 dirent curentry; /* Current directory entry */
170 WIN32_FIND_DATAW find_data; /* Private file data */
171 int cached; /* True if data is valid */
172 HANDLE search_handle; /* Win32 search handle */
173 WCHAR patt[MAX_PATH + 3]; /* Initial directory name */
174 } DIR;
175
176
177 /* Forward declarations */
178 static DIR *opendir(const WCHAR *dirname);
179 static struct dirent *readdir(DIR *dirp);
180 static int closedir(DIR *dirp);
181 static void rewinddir(DIR* dirp);
182
183
184 /* Use the new safe string functions introduced in Visual Studio 2005 */
185 #if defined(_MSC_VER) && _MSC_VER >= 1400
 
186 # define DIRENT_STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE)
187 #else
188 # define DIRENT_STRNCPY(dest,src,size) wcsncpy((dest),(src),(size))
189 #endif
190
@@ -199,13 +200,13 @@
199 /*****************************************************************************
200 * Open directory stream DIRNAME for read and return a pointer to the
201 * internal working area that is used to retrieve individual directory
202 * entries.
203 */
204 static DIR *opendir(const WCHAR *dirname)
205 {
206 DIR *dirp;
207
208 /* ensure that the resulting search pattern will be a valid file name */
209 if (dirname == NULL) {
210 DIRENT_SET_ERRNO (ENOENT);
211 return NULL;
@@ -213,12 +214,12 @@
213 if (wcslen (dirname) + 3 >= MAX_PATH) {
214 DIRENT_SET_ERRNO (ENAMETOOLONG);
215 return NULL;
216 }
217
218 /* construct new DIR structure */
219 dirp = (DIR*) malloc (sizeof (struct DIR));
220 if (dirp != NULL) {
221 int error;
222
223 /*
224 * Convert relative directory name to an absolute one. This
@@ -262,17 +263,17 @@
262 return dirp;
263 }
264
265
266 /*****************************************************************************
267 * Read a directory entry, and return a pointer to a dirent structure
268 * containing the name of the entry in d_name field. Individual directory
269 * entries returned by this very function include regular files,
270 * sub-directories, pseudo-directories "." and "..", but also volume labels,
271 * hidden files and system files may be returned.
272 */
273 static struct dirent *readdir(DIR *dirp)
274 {
275 DWORD attr;
276 if (dirp == NULL) {
277 /* directory stream did not open */
278 DIRENT_SET_ERRNO (EBADF);
@@ -318,14 +319,14 @@
318 }
319
320
321 /*****************************************************************************
322 * Close directory stream opened by opendir() function. Close of the
323 * directory stream invalidates the DIR structure as well as any previously
324 * read directory entry.
325 */
326 static int closedir(DIR *dirp)
327 {
328 if (dirp == NULL) {
329 /* invalid directory stream */
330 DIRENT_SET_ERRNO (EBADF);
331 return -1;
@@ -347,11 +348,11 @@
347 * beginning of the directory. It also causes the directory stream to refer
348 * to the current state of the corresponding directory, as a call to opendir()
349 * would have done. If dirp does not refer to a directory stream, the effect
350 * is undefined.
351 */
352 static void rewinddir(DIR* dirp)
353 {
354 if (dirp != NULL) {
355 /* release search handle */
356 if (dirp->search_handle != INVALID_HANDLE_VALUE) {
357 FindClose (dirp->search_handle);
358
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -154,37 +154,38 @@
154
155 #ifdef __cplusplus
156 extern "C" {
157 #endif
158
159 typedef struct _wdirent
160 {
161 WCHAR d_name[MAX_PATH + 1]; /* File name */
162 size_t d_namlen; /* Length of name without \0 */
163 int d_type; /* File type */
164 } _wdirent;
165
166
167 typedef struct _WDIR
168 {
169 _wdirent curentry; /* Current directory entry */
170 WIN32_FIND_DATAW find_data; /* Private file data */
171 int cached; /* True if data is valid */
172 HANDLE search_handle; /* Win32 search handle */
173 WCHAR patt[MAX_PATH + 3]; /* Initial directory name */
174 } _WDIR;
175
176
177 /* Forward declarations */
178 static _WDIR *_wopendir(const WCHAR *dirname);
179 static struct _wdirent *_wreaddir(_WDIR *dirp);
180 static int _wclosedir(_WDIR *dirp);
181 static void _wrewinddir(_WDIR* dirp);
182
183
184 /* Use the new safe string functions introduced in Visual Studio 2005 */
185 #if defined(_MSC_VER) && _MSC_VER >= 1400
186
187 # define DIRENT_STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE)
188 #else
189 # define DIRENT_STRNCPY(dest,src,size) wcsncpy((dest),(src),(size))
190 #endif
191
@@ -199,13 +200,13 @@
200 /*****************************************************************************
201 * Open directory stream DIRNAME for read and return a pointer to the
202 * internal working area that is used to retrieve individual directory
203 * entries.
204 */
205 static _WDIR *_wopendir(const WCHAR *dirname)
206 {
207 _WDIR *dirp;
208
209 /* ensure that the resulting search pattern will be a valid file name */
210 if (dirname == NULL) {
211 DIRENT_SET_ERRNO (ENOENT);
212 return NULL;
@@ -213,12 +214,12 @@
214 if (wcslen (dirname) + 3 >= MAX_PATH) {
215 DIRENT_SET_ERRNO (ENAMETOOLONG);
216 return NULL;
217 }
218
219 /* construct new _WDIR structure */
220 dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
221 if (dirp != NULL) {
222 int error;
223
224 /*
225 * Convert relative directory name to an absolute one. This
@@ -262,17 +263,17 @@
263 return dirp;
264 }
265
266
267 /*****************************************************************************
268 * Read a directory entry, and return a pointer to a _wdirent structure
269 * containing the name of the entry in d_name field. Individual directory
270 * entries returned by this very function include regular files,
271 * sub-directories, pseudo-directories "." and "..", but also volume labels,
272 * hidden files and system files may be returned.
273 */
274 static struct _wdirent *_wreaddir(_WDIR *dirp)
275 {
276 DWORD attr;
277 if (dirp == NULL) {
278 /* directory stream did not open */
279 DIRENT_SET_ERRNO (EBADF);
@@ -318,14 +319,14 @@
319 }
320
321
322 /*****************************************************************************
323 * Close directory stream opened by opendir() function. Close of the
324 * directory stream invalidates the _WDIR structure as well as any previously
325 * read directory entry.
326 */
327 static int _wclosedir(_WDIR *dirp)
328 {
329 if (dirp == NULL) {
330 /* invalid directory stream */
331 DIRENT_SET_ERRNO (EBADF);
332 return -1;
@@ -347,11 +348,11 @@
348 * beginning of the directory. It also causes the directory stream to refer
349 * to the current state of the corresponding directory, as a call to opendir()
350 * would have done. If dirp does not refer to a directory stream, the effect
351 * is undefined.
352 */
353 static void _wrewinddir(_WDIR* dirp)
354 {
355 if (dirp != NULL) {
356 /* release search handle */
357 if (dirp->search_handle != INVALID_HANDLE_VALUE) {
358 FindClose (dirp->search_handle);
359

Keyboard Shortcuts

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