Fossil SCM

make it link on msvc. Doesn't run yet.

jan.nijtmans 2012-08-29 20:27 UTC msvc-broken
Commit bd43f1c2499a5e1fcae3d23ea6e2b7a899ee2af4
2 files changed +6 -6 +28 -58
+6 -6
--- src/file.c
+++ src/file.c
@@ -1009,16 +1009,16 @@
10091009
** Portable unicode implementation of opendir()
10101010
*/
10111011
#if INTERFACE
10121012
10131013
#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
1014
+# include <dirent.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
10201020
#else
10211021
# include <dirent.h>
10221022
# define FOSSIL_DIR DIR
10231023
# define fossil_dirent dirent
10241024
# define fossil_opendir opendir
10251025
--- src/file.c
+++ src/file.c
@@ -1009,16 +1009,16 @@
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
--- src/file.c
+++ src/file.c
@@ -1009,16 +1009,16 @@
1009 ** Portable unicode implementation of opendir()
1010 */
1011 #if INTERFACE
1012
1013 #if defined(_WIN32)
1014 # include <dirent.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
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -61,71 +61,70 @@
6161
#include <windows.h>
6262
#include <string.h>
6363
#include <assert.h>
6464
6565
66
-typedef struct dirent
67
-{
68
- char d_name[MAX_PATH + 1]; /* current dir entry (multi-byte char string) */
69
- WIN32_FIND_DATAA data; /* file attributes */
70
-} dirent;
71
-
72
-
73
-typedef struct DIR
74
-{
75
- dirent current; /* Current directory entry */
66
+typedef struct _wdirent
67
+{
68
+ wchar_t d_name[MAX_PATH + 1]; /* current dir entry (unicode char string) */
69
+ WIN32_FIND_DATAW data; /* file attributes */
70
+} _wdirent;
71
+
72
+
73
+typedef struct _WDIR
74
+{
75
+ _wdirent current; /* Current directory entry */
7676
int cached; /* Indicates un-processed entry in memory */
7777
HANDLE search_handle; /* File search handle */
78
- char patt[MAX_PATH + 3]; /* search pattern (3 = pattern + "\\*\0") */
79
-} DIR;
78
+ wchar_t patt[MAX_PATH + 3]; /* search pattern (3 = pattern + "\\*\0") */
79
+} _WDIR;
8080
8181
8282
/* Forward declarations */
83
-static DIR *opendir (const char *dirname);
84
-static struct dirent *readdir (DIR *dirp);
85
-static int closedir (DIR *dirp);
86
-static void rewinddir(DIR* dirp);
83
+static _WDIR *_wopendir (const wchar_t *dirname);
84
+static struct _wdirent *_wreaddir (_WDIR *dirp);
85
+static int _wclosedir (_WDIR *dirp);
8786
8887
8988
/* Use the new safe string functions introduced in Visual Studio 2005 */
9089
#if defined(_MSC_VER) && _MSC_VER >= 1400
91
-# define STRNCPY(dest,src,size) strncpy_s((dest),(size),(src),_TRUNCATE)
90
+# define STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE)
9291
#else
93
-# define STRNCPY(dest,src,size) strncpy((dest),(src),(size))
92
+# define STRNCPY(dest,src,size) wcsncpy((dest),(src),(size))
9493
#endif
9594
9695
9796
/*****************************************************************************
9897
* Open directory stream DIRNAME for read and return a pointer to the
9998
* internal working area that is used to retrieve individual directory
10099
* entries.
101100
*/
102
-static DIR *opendir(const char *dirname)
101
+static _WDIR *_wopendir(const wchar_t *dirname)
103102
{
104
- DIR *dirp;
103
+ _WDIR *dirp;
105104
assert (dirname != NULL);
106
- assert (strlen (dirname) < MAX_PATH);
105
+ assert (wcslen (dirname) < MAX_PATH);
107106
108
- /* construct new DIR structure */
109
- dirp = (DIR*) malloc (sizeof (struct DIR));
107
+ /* construct new _WDIR structure */
108
+ dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
110109
if (dirp != NULL) {
111
- char *p;
110
+ wchar_t *p;
112111
113112
/* take directory name... */
114113
STRNCPY (dirp->patt, dirname, sizeof(dirp->patt));
115114
dirp->patt[MAX_PATH] = '\0';
116115
117116
/* ... and append search pattern to it */
118
- p = strchr (dirp->patt, '\0');
117
+ p = wcschr (dirp->patt, '\0');
119118
if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') {
120119
*p++ = '\\';
121120
}
122121
*p++ = '*';
123122
*p = '\0';
124123
125124
/* open stream and retrieve first file */
126
- dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->current.data);
125
+ dirp->search_handle = FindFirstFileW (dirp->patt, &dirp->current.data);
127126
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
128127
/* invalid search pattern? */
129128
free (dirp);
130129
return NULL;
131130
}
@@ -143,11 +142,11 @@
143142
* containing the name of the entry in d_name field. Individual directory
144143
* entries returned by this very function include regular files,
145144
* sub-directories, pseudo-directories "." and "..", but also volume labels,
146145
* hidden files and system files may be returned.
147146
*/
148
-static struct dirent *readdir(DIR *dirp)
147
+static struct _wdirent *_wreaddir(_WDIR *dirp)
149148
{
150149
assert (dirp != NULL);
151150
152151
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
153152
/* directory stream was opened/rewound incorrectly or ended normally */
@@ -158,11 +157,11 @@
158157
if (dirp->cached != 0) {
159158
/* a valid directory entry already in memory */
160159
dirp->cached = 0;
161160
} else {
162161
/* read next directory entry from disk */
163
- if (FindNextFileA (dirp->search_handle, &dirp->current.data) == FALSE) {
162
+ if (FindNextFileW (dirp->search_handle, &dirp->current.data) == FALSE) {
164163
/* the very last file has been processed or an error occured */
165164
FindClose (dirp->search_handle);
166165
dirp->search_handle = INVALID_HANDLE_VALUE;
167166
return NULL;
168167
}
@@ -181,11 +180,11 @@
181180
/*****************************************************************************
182181
* Close directory stream opened by opendir() function. Close of the
183182
* directory stream invalidates the DIR structure as well as any previously
184183
* read directory entry.
185184
*/
186
-static int closedir(DIR *dirp)
185
+static int _wclosedir(_WDIR *dirp)
187186
{
188187
assert (dirp != NULL);
189188
190189
/* release search handle */
191190
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
@@ -195,36 +194,7 @@
195194
196195
/* release directory handle */
197196
free (dirp);
198197
return 0;
199198
}
200
-
201
-
202
-/*****************************************************************************
203
- * Resets the position of the directory stream to which dirp refers to the
204
- * beginning of the directory. It also causes the directory stream to refer
205
- * to the current state of the corresponding directory, as a call to opendir()
206
- * would have done. If dirp does not refer to a directory stream, the effect
207
- * is undefined.
208
- */
209
-static void rewinddir(DIR* dirp)
210
-{
211
- /* release search handle */
212
- if (dirp->search_handle != INVALID_HANDLE_VALUE) {
213
- FindClose (dirp->search_handle);
214
- dirp->search_handle = INVALID_HANDLE_VALUE;
215
- }
216
-
217
- /* open new search handle and retrieve first file */
218
- dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->current.data);
219
- if (dirp->search_handle == INVALID_HANDLE_VALUE) {
220
- /* invalid search pattern? */
221
- free (dirp);
222
- return;
223
- }
224
-
225
- /* there is an un-processed directory entry in memory now */
226
- dirp->cached = 1;
227
-}
228
-
229199
230200
#endif /*DIRENT_H*/
231201
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -61,71 +61,70 @@
61 #include <windows.h>
62 #include <string.h>
63 #include <assert.h>
64
65
66 typedef struct dirent
67 {
68 char d_name[MAX_PATH + 1]; /* current dir entry (multi-byte char string) */
69 WIN32_FIND_DATAA data; /* file attributes */
70 } dirent;
71
72
73 typedef struct DIR
74 {
75 dirent current; /* Current directory entry */
76 int cached; /* Indicates un-processed entry in memory */
77 HANDLE search_handle; /* File search handle */
78 char patt[MAX_PATH + 3]; /* search pattern (3 = pattern + "\\*\0") */
79 } DIR;
80
81
82 /* Forward declarations */
83 static DIR *opendir (const char *dirname);
84 static struct dirent *readdir (DIR *dirp);
85 static int closedir (DIR *dirp);
86 static void rewinddir(DIR* dirp);
87
88
89 /* Use the new safe string functions introduced in Visual Studio 2005 */
90 #if defined(_MSC_VER) && _MSC_VER >= 1400
91 # define STRNCPY(dest,src,size) strncpy_s((dest),(size),(src),_TRUNCATE)
92 #else
93 # define STRNCPY(dest,src,size) strncpy((dest),(src),(size))
94 #endif
95
96
97 /*****************************************************************************
98 * Open directory stream DIRNAME for read and return a pointer to the
99 * internal working area that is used to retrieve individual directory
100 * entries.
101 */
102 static DIR *opendir(const char *dirname)
103 {
104 DIR *dirp;
105 assert (dirname != NULL);
106 assert (strlen (dirname) < MAX_PATH);
107
108 /* construct new DIR structure */
109 dirp = (DIR*) malloc (sizeof (struct DIR));
110 if (dirp != NULL) {
111 char *p;
112
113 /* take directory name... */
114 STRNCPY (dirp->patt, dirname, sizeof(dirp->patt));
115 dirp->patt[MAX_PATH] = '\0';
116
117 /* ... and append search pattern to it */
118 p = strchr (dirp->patt, '\0');
119 if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') {
120 *p++ = '\\';
121 }
122 *p++ = '*';
123 *p = '\0';
124
125 /* open stream and retrieve first file */
126 dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->current.data);
127 if (dirp->search_handle == INVALID_HANDLE_VALUE) {
128 /* invalid search pattern? */
129 free (dirp);
130 return NULL;
131 }
@@ -143,11 +142,11 @@
143 * containing the name of the entry in d_name field. Individual directory
144 * entries returned by this very function include regular files,
145 * sub-directories, pseudo-directories "." and "..", but also volume labels,
146 * hidden files and system files may be returned.
147 */
148 static struct dirent *readdir(DIR *dirp)
149 {
150 assert (dirp != NULL);
151
152 if (dirp->search_handle == INVALID_HANDLE_VALUE) {
153 /* directory stream was opened/rewound incorrectly or ended normally */
@@ -158,11 +157,11 @@
158 if (dirp->cached != 0) {
159 /* a valid directory entry already in memory */
160 dirp->cached = 0;
161 } else {
162 /* read next directory entry from disk */
163 if (FindNextFileA (dirp->search_handle, &dirp->current.data) == FALSE) {
164 /* the very last file has been processed or an error occured */
165 FindClose (dirp->search_handle);
166 dirp->search_handle = INVALID_HANDLE_VALUE;
167 return NULL;
168 }
@@ -181,11 +180,11 @@
181 /*****************************************************************************
182 * Close directory stream opened by opendir() function. Close of the
183 * directory stream invalidates the DIR structure as well as any previously
184 * read directory entry.
185 */
186 static int closedir(DIR *dirp)
187 {
188 assert (dirp != NULL);
189
190 /* release search handle */
191 if (dirp->search_handle != INVALID_HANDLE_VALUE) {
@@ -195,36 +194,7 @@
195
196 /* release directory handle */
197 free (dirp);
198 return 0;
199 }
200
201
202 /*****************************************************************************
203 * Resets the position of the directory stream to which dirp refers to the
204 * beginning of the directory. It also causes the directory stream to refer
205 * to the current state of the corresponding directory, as a call to opendir()
206 * would have done. If dirp does not refer to a directory stream, the effect
207 * is undefined.
208 */
209 static void rewinddir(DIR* dirp)
210 {
211 /* release search handle */
212 if (dirp->search_handle != INVALID_HANDLE_VALUE) {
213 FindClose (dirp->search_handle);
214 dirp->search_handle = INVALID_HANDLE_VALUE;
215 }
216
217 /* open new search handle and retrieve first file */
218 dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->current.data);
219 if (dirp->search_handle == INVALID_HANDLE_VALUE) {
220 /* invalid search pattern? */
221 free (dirp);
222 return;
223 }
224
225 /* there is an un-processed directory entry in memory now */
226 dirp->cached = 1;
227 }
228
229
230 #endif /*DIRENT_H*/
231
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -61,71 +61,70 @@
61 #include <windows.h>
62 #include <string.h>
63 #include <assert.h>
64
65
66 typedef struct _wdirent
67 {
68 wchar_t d_name[MAX_PATH + 1]; /* current dir entry (unicode char string) */
69 WIN32_FIND_DATAW data; /* file attributes */
70 } _wdirent;
71
72
73 typedef struct _WDIR
74 {
75 _wdirent current; /* Current directory entry */
76 int cached; /* Indicates un-processed entry in memory */
77 HANDLE search_handle; /* File search handle */
78 wchar_t patt[MAX_PATH + 3]; /* search pattern (3 = pattern + "\\*\0") */
79 } _WDIR;
80
81
82 /* Forward declarations */
83 static _WDIR *_wopendir (const wchar_t *dirname);
84 static struct _wdirent *_wreaddir (_WDIR *dirp);
85 static int _wclosedir (_WDIR *dirp);
 
86
87
88 /* Use the new safe string functions introduced in Visual Studio 2005 */
89 #if defined(_MSC_VER) && _MSC_VER >= 1400
90 # define STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE)
91 #else
92 # define STRNCPY(dest,src,size) wcsncpy((dest),(src),(size))
93 #endif
94
95
96 /*****************************************************************************
97 * Open directory stream DIRNAME for read and return a pointer to the
98 * internal working area that is used to retrieve individual directory
99 * entries.
100 */
101 static _WDIR *_wopendir(const wchar_t *dirname)
102 {
103 _WDIR *dirp;
104 assert (dirname != NULL);
105 assert (wcslen (dirname) < MAX_PATH);
106
107 /* construct new _WDIR structure */
108 dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
109 if (dirp != NULL) {
110 wchar_t *p;
111
112 /* take directory name... */
113 STRNCPY (dirp->patt, dirname, sizeof(dirp->patt));
114 dirp->patt[MAX_PATH] = '\0';
115
116 /* ... and append search pattern to it */
117 p = wcschr (dirp->patt, '\0');
118 if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') {
119 *p++ = '\\';
120 }
121 *p++ = '*';
122 *p = '\0';
123
124 /* open stream and retrieve first file */
125 dirp->search_handle = FindFirstFileW (dirp->patt, &dirp->current.data);
126 if (dirp->search_handle == INVALID_HANDLE_VALUE) {
127 /* invalid search pattern? */
128 free (dirp);
129 return NULL;
130 }
@@ -143,11 +142,11 @@
142 * containing the name of the entry in d_name field. Individual directory
143 * entries returned by this very function include regular files,
144 * sub-directories, pseudo-directories "." and "..", but also volume labels,
145 * hidden files and system files may be returned.
146 */
147 static struct _wdirent *_wreaddir(_WDIR *dirp)
148 {
149 assert (dirp != NULL);
150
151 if (dirp->search_handle == INVALID_HANDLE_VALUE) {
152 /* directory stream was opened/rewound incorrectly or ended normally */
@@ -158,11 +157,11 @@
157 if (dirp->cached != 0) {
158 /* a valid directory entry already in memory */
159 dirp->cached = 0;
160 } else {
161 /* read next directory entry from disk */
162 if (FindNextFileW (dirp->search_handle, &dirp->current.data) == FALSE) {
163 /* the very last file has been processed or an error occured */
164 FindClose (dirp->search_handle);
165 dirp->search_handle = INVALID_HANDLE_VALUE;
166 return NULL;
167 }
@@ -181,11 +180,11 @@
180 /*****************************************************************************
181 * Close directory stream opened by opendir() function. Close of the
182 * directory stream invalidates the DIR structure as well as any previously
183 * read directory entry.
184 */
185 static int _wclosedir(_WDIR *dirp)
186 {
187 assert (dirp != NULL);
188
189 /* release search handle */
190 if (dirp->search_handle != INVALID_HANDLE_VALUE) {
@@ -195,36 +194,7 @@
194
195 /* release directory handle */
196 free (dirp);
197 return 0;
198 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
200 #endif /*DIRENT_H*/
201

Keyboard Shortcuts

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