Fossil SCM

An attempt to factor out the opendir() family of routines and provide portable alternatives, fossil_opendir(). This simplistic first attempt works on non-windows platforms, but the build fails on windows.

drh 2012-08-29 16:51 UTC msvc-broken
Commit 8d8e529aa9a6295ee138cf510b94b4878aacb0e1
3 files changed +24 +8 -18 +6 -20
+24
--- src/file.c
+++ src/file.c
@@ -1002,10 +1002,34 @@
10021002
}
10031003
rc = blob_compare(&onDisk, pContent);
10041004
blob_reset(&onDisk);
10051005
return rc==0;
10061006
}
1007
+
1008
+/*
1009
+** Portable unicode implementation of opendir()
1010
+*/
1011
+#if INTERFACE
1012
+
1013
+#if defined(_WIN32)
1014
+# include <wdirent.h>
1015
+# define FOSSIL_DIR WDIR
1016
+# define fossil_dirent wdirent
1017
+# define fossil_opendir wopendir
1018
+# define fossil_readdir wreaddir
1019
+# define fossil_closedir wclosedir
1020
+#else
1021
+# include <dirent.h>
1022
+# define FOSSIL_DIR DIR
1023
+# define fossil_dirent dirent
1024
+# define fossil_opendir opendir
1025
+# define fossil_readdir readdir
1026
+# define fossil_closedir closedir
1027
+#endif
1028
+
1029
+#endif /* INTERFACE */
1030
+
10071031
10081032
10091033
/**************************************************************************
10101034
** The following routines translate between MBCS and UTF8 on windows.
10111035
** Since everything is always UTF8 on unix, these routines are no-ops
10121036
--- src/file.c
+++ src/file.c
@@ -1002,10 +1002,34 @@
1002 }
1003 rc = blob_compare(&onDisk, pContent);
1004 blob_reset(&onDisk);
1005 return rc==0;
1006 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1007
1008
1009 /**************************************************************************
1010 ** The following routines translate between MBCS and UTF8 on windows.
1011 ** Since everything is always UTF8 on unix, these routines are no-ops
1012
--- src/file.c
+++ src/file.c
@@ -1002,10 +1002,34 @@
1002 }
1003 rc = blob_compare(&onDisk, pContent);
1004 blob_reset(&onDisk);
1005 return rc==0;
1006 }
1007
1008 /*
1009 ** Portable unicode implementation of opendir()
1010 */
1011 #if INTERFACE
1012
1013 #if defined(_WIN32)
1014 # include <wdirent.h>
1015 # define FOSSIL_DIR WDIR
1016 # define fossil_dirent wdirent
1017 # define fossil_opendir wopendir
1018 # define fossil_readdir wreaddir
1019 # define fossil_closedir wclosedir
1020 #else
1021 # include <dirent.h>
1022 # define FOSSIL_DIR DIR
1023 # define fossil_dirent dirent
1024 # define fossil_opendir opendir
1025 # define fossil_readdir readdir
1026 # define fossil_closedir closedir
1027 #endif
1028
1029 #endif /* INTERFACE */
1030
1031
1032
1033 /**************************************************************************
1034 ** The following routines translate between MBCS and UTF8 on windows.
1035 ** Since everything is always UTF8 on unix, these routines are no-ops
1036
+8 -18
--- src/rebuild.c
+++ src/rebuild.c
@@ -18,22 +18,12 @@
1818
** This file contains code used to rebuild the database.
1919
*/
2020
#include "config.h"
2121
#include "rebuild.h"
2222
#include <assert.h>
23
-#include <dirent.h>
2423
#include <errno.h>
2524
26
-#ifndef _WIN32
27
-#define _WDIR DIR
28
-#define _wdirent dirent
29
-#define _wopendir opendir
30
-#define _wreaddir readdir
31
-#define _wclosedir closedir
32
-#define wchar_t char
33
-#endif
34
-
3525
/*
3626
** Make changes to the stable part of the schema (the part that is not
3727
** simply deleted and reconstructed on a rebuild) to bring the schema
3828
** up to the latest.
3929
*/
@@ -827,21 +817,21 @@
827817
/*
828818
** Recursively read all files from the directory zPath and install
829819
** every file read as a new artifact in the repository.
830820
*/
831821
void recon_read_dir(char *zPath){
832
- _WDIR *d;
833
- struct _wdirent *pEntry;
822
+ FOSSIL_DIR *d;
823
+ struct fossil_dirent *pEntry;
834824
Blob aContent; /* content of the just read artifact */
835825
static int nFileRead = 0;
836
- wchar_t *zMbcsPath;
826
+ void *zUnicodePath;
837827
char *zUtf8Name;
838828
839
- zMbcsPath = fossil_utf8_to_unicode(zPath);
840
- d = _wopendir(zMbcsPath);
829
+ zUnicodePath = fossil_utf8_to_unicode(zPath);
830
+ d = fossil_opendir(zUnicodePath);
841831
if( d ){
842
- while( (pEntry=_wreaddir(d))!=0 ){
832
+ while( (pEntry=fossil_readdir(d))!=0 ){
843833
Blob path;
844834
char *zSubpath;
845835
846836
if( pEntry->d_name[0]=='.' ){
847837
continue;
@@ -863,16 +853,16 @@
863853
blob_reset(&aContent);
864854
free(zSubpath);
865855
fossil_print("\r%d", ++nFileRead);
866856
fflush(stdout);
867857
}
868
- _wclosedir(d);
858
+ fossil_closedir(d);
869859
}else {
870860
fossil_panic("encountered error %d while trying to open \"%s\".",
871861
errno, g.argv[3]);
872862
}
873
- fossil_mbcs_free(zMbcsPath);
863
+ fossil_mbcs_free(zUnicodePath);
874864
}
875865
876866
/*
877867
** COMMAND: reconstruct*
878868
**
879869
--- src/rebuild.c
+++ src/rebuild.c
@@ -18,22 +18,12 @@
18 ** This file contains code used to rebuild the database.
19 */
20 #include "config.h"
21 #include "rebuild.h"
22 #include <assert.h>
23 #include <dirent.h>
24 #include <errno.h>
25
26 #ifndef _WIN32
27 #define _WDIR DIR
28 #define _wdirent dirent
29 #define _wopendir opendir
30 #define _wreaddir readdir
31 #define _wclosedir closedir
32 #define wchar_t char
33 #endif
34
35 /*
36 ** Make changes to the stable part of the schema (the part that is not
37 ** simply deleted and reconstructed on a rebuild) to bring the schema
38 ** up to the latest.
39 */
@@ -827,21 +817,21 @@
827 /*
828 ** Recursively read all files from the directory zPath and install
829 ** every file read as a new artifact in the repository.
830 */
831 void recon_read_dir(char *zPath){
832 _WDIR *d;
833 struct _wdirent *pEntry;
834 Blob aContent; /* content of the just read artifact */
835 static int nFileRead = 0;
836 wchar_t *zMbcsPath;
837 char *zUtf8Name;
838
839 zMbcsPath = fossil_utf8_to_unicode(zPath);
840 d = _wopendir(zMbcsPath);
841 if( d ){
842 while( (pEntry=_wreaddir(d))!=0 ){
843 Blob path;
844 char *zSubpath;
845
846 if( pEntry->d_name[0]=='.' ){
847 continue;
@@ -863,16 +853,16 @@
863 blob_reset(&aContent);
864 free(zSubpath);
865 fossil_print("\r%d", ++nFileRead);
866 fflush(stdout);
867 }
868 _wclosedir(d);
869 }else {
870 fossil_panic("encountered error %d while trying to open \"%s\".",
871 errno, g.argv[3]);
872 }
873 fossil_mbcs_free(zMbcsPath);
874 }
875
876 /*
877 ** COMMAND: reconstruct*
878 **
879
--- src/rebuild.c
+++ src/rebuild.c
@@ -18,22 +18,12 @@
18 ** This file contains code used to rebuild the database.
19 */
20 #include "config.h"
21 #include "rebuild.h"
22 #include <assert.h>
 
23 #include <errno.h>
24
 
 
 
 
 
 
 
 
 
25 /*
26 ** Make changes to the stable part of the schema (the part that is not
27 ** simply deleted and reconstructed on a rebuild) to bring the schema
28 ** up to the latest.
29 */
@@ -827,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;
@@ -863,16 +853,16 @@
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 }
865
866 /*
867 ** COMMAND: reconstruct*
868 **
869
+6 -20
--- src/vfile.c
+++ src/vfile.c
@@ -19,24 +19,10 @@
1919
*/
2020
#include "config.h"
2121
#include "vfile.h"
2222
#include <assert.h>
2323
#include <sys/types.h>
24
-#if defined(__DMC__)
25
-#include "dirent.h"
26
-#else
27
-#include <dirent.h>
28
-#endif
29
-
30
-#ifndef _WIN32
31
-#define _WDIR DIR
32
-#define _wdirent dirent
33
-#define _wopendir opendir
34
-#define _wreaddir readdir
35
-#define _wclosedir closedir
36
-#define wchar_t char
37
-#endif
3824
3925
/*
4026
** The input is guaranteed to be a 40-character well-formed UUID.
4127
** Find its rid.
4228
*/
@@ -390,18 +376,18 @@
390376
** Any files or directories that match the glob pattern pIgnore are
391377
** excluded from the scan. Name matching occurs after the first
392378
** nPrefix characters are elided from the filename.
393379
*/
394380
void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
395
- _WDIR *d;
381
+ FOSSIL_DIR *d;
396382
int origSize;
397383
const char *zDir;
398
- struct _wdirent *pEntry;
384
+ struct fossil_dirent *pEntry;
399385
int skipAll = 0;
400386
static Stmt ins;
401387
static int depth = 0;
402
- wchar_t *zMbcs;
388
+ void *zMbcs;
403389
404390
origSize = blob_size(pPath);
405391
if( pIgnore ){
406392
blob_appendf(pPath, "/");
407393
if( glob_match(pIgnore, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
@@ -417,13 +403,13 @@
417403
}
418404
depth++;
419405
420406
zDir = blob_str(pPath);
421407
zMbcs = fossil_utf8_to_unicode(zDir);
422
- d = _wopendir(zMbcs);
408
+ d = fossil_opendir(zMbcs);
423409
if( d ){
424
- while( (pEntry=_wreaddir(d))!=0 ){
410
+ while( (pEntry=fossil_readdir(d))!=0 ){
425411
char *zPath;
426412
char *zUtf8;
427413
if( pEntry->d_name[0]=='.' ){
428414
if( !allFlag ) continue;
429415
if( pEntry->d_name[1]==0 ) continue;
@@ -444,11 +430,11 @@
444430
db_step(&ins);
445431
db_reset(&ins);
446432
}
447433
blob_resize(pPath, origSize);
448434
}
449
- _wclosedir(d);
435
+ fossil_closedir(d);
450436
}
451437
fossil_mbcs_free(zMbcs);
452438
453439
depth--;
454440
if( depth==0 ){
455441
--- src/vfile.c
+++ src/vfile.c
@@ -19,24 +19,10 @@
19 */
20 #include "config.h"
21 #include "vfile.h"
22 #include <assert.h>
23 #include <sys/types.h>
24 #if defined(__DMC__)
25 #include "dirent.h"
26 #else
27 #include <dirent.h>
28 #endif
29
30 #ifndef _WIN32
31 #define _WDIR DIR
32 #define _wdirent dirent
33 #define _wopendir opendir
34 #define _wreaddir readdir
35 #define _wclosedir closedir
36 #define wchar_t char
37 #endif
38
39 /*
40 ** The input is guaranteed to be a 40-character well-formed UUID.
41 ** Find its rid.
42 */
@@ -390,18 +376,18 @@
390 ** Any files or directories that match the glob pattern pIgnore are
391 ** excluded from the scan. Name matching occurs after the first
392 ** nPrefix characters are elided from the filename.
393 */
394 void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
395 _WDIR *d;
396 int origSize;
397 const char *zDir;
398 struct _wdirent *pEntry;
399 int skipAll = 0;
400 static Stmt ins;
401 static int depth = 0;
402 wchar_t *zMbcs;
403
404 origSize = blob_size(pPath);
405 if( pIgnore ){
406 blob_appendf(pPath, "/");
407 if( glob_match(pIgnore, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
@@ -417,13 +403,13 @@
417 }
418 depth++;
419
420 zDir = blob_str(pPath);
421 zMbcs = fossil_utf8_to_unicode(zDir);
422 d = _wopendir(zMbcs);
423 if( d ){
424 while( (pEntry=_wreaddir(d))!=0 ){
425 char *zPath;
426 char *zUtf8;
427 if( pEntry->d_name[0]=='.' ){
428 if( !allFlag ) continue;
429 if( pEntry->d_name[1]==0 ) continue;
@@ -444,11 +430,11 @@
444 db_step(&ins);
445 db_reset(&ins);
446 }
447 blob_resize(pPath, origSize);
448 }
449 _wclosedir(d);
450 }
451 fossil_mbcs_free(zMbcs);
452
453 depth--;
454 if( depth==0 ){
455
--- src/vfile.c
+++ src/vfile.c
@@ -19,24 +19,10 @@
19 */
20 #include "config.h"
21 #include "vfile.h"
22 #include <assert.h>
23 #include <sys/types.h>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
25 /*
26 ** The input is guaranteed to be a 40-character well-formed UUID.
27 ** Find its rid.
28 */
@@ -390,18 +376,18 @@
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
390 origSize = blob_size(pPath);
391 if( pIgnore ){
392 blob_appendf(pPath, "/");
393 if( glob_match(pIgnore, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
@@ -417,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;
@@ -444,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

Keyboard Shortcuts

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