Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | make it link on msvc. Doesn't run yet. |
|---|---|
| Timelines: | family | ancestors | descendants | both | msvc-broken |
| Files: | files | file ages | folders |
| SHA1: |
bd43f1c2499a5e1fcae3d23ea6e2b7a8 |
| User & Date: | jan.nijtmans 2012-08-29 20:27:10.983 |
Context
|
2012-08-29
| ||
| 20:51 | merge-mark (in order to make merging back msvc-broken to trunk easier) check-in: 2b5d693495 user: jan.nijtmans tags: msvc-broken | |
| 20:27 | make it link on msvc. Doesn't run yet. check-in: bd43f1c249 user: jan.nijtmans tags: msvc-broken | |
| 16:51 | 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. check-in: 8d8e529aa9 user: drh tags: msvc-broken | |
Changes
Changes to src/file.c.
| ︙ | ︙ | |||
1007 1008 1009 1010 1011 1012 1013 | /* ** Portable unicode implementation of opendir() */ #if INTERFACE #if defined(_WIN32) | | | | | | | | 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | /* ** Portable unicode implementation of opendir() */ #if INTERFACE #if defined(_WIN32) # include <dirent.h> # define FOSSIL_DIR _WDIR # define fossil_dirent _wdirent # define fossil_opendir _wopendir # define fossil_readdir _wreaddir # define fossil_closedir _wclosedir #else # include <dirent.h> # define FOSSIL_DIR DIR # define fossil_dirent dirent # define fossil_opendir opendir # define fossil_readdir readdir # define fossil_closedir closedir |
| ︙ | ︙ |
Changes to win/include/dirent.h.
| ︙ | ︙ | |||
59 60 61 62 63 64 65 | #define DIRENT_H #include <windows.h> #include <string.h> #include <assert.h> | | | | | | | | | | | | < | | | | | | | | | | | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
#define DIRENT_H
#include <windows.h>
#include <string.h>
#include <assert.h>
typedef struct _wdirent
{
wchar_t d_name[MAX_PATH + 1]; /* current dir entry (unicode char string) */
WIN32_FIND_DATAW data; /* file attributes */
} _wdirent;
typedef struct _WDIR
{
_wdirent current; /* Current directory entry */
int cached; /* Indicates un-processed entry in memory */
HANDLE search_handle; /* File search handle */
wchar_t patt[MAX_PATH + 3]; /* search pattern (3 = pattern + "\\*\0") */
} _WDIR;
/* Forward declarations */
static _WDIR *_wopendir (const wchar_t *dirname);
static struct _wdirent *_wreaddir (_WDIR *dirp);
static int _wclosedir (_WDIR *dirp);
/* Use the new safe string functions introduced in Visual Studio 2005 */
#if defined(_MSC_VER) && _MSC_VER >= 1400
# define STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE)
#else
# define STRNCPY(dest,src,size) wcsncpy((dest),(src),(size))
#endif
/*****************************************************************************
* Open directory stream DIRNAME for read and return a pointer to the
* internal working area that is used to retrieve individual directory
* entries.
*/
static _WDIR *_wopendir(const wchar_t *dirname)
{
_WDIR *dirp;
assert (dirname != NULL);
assert (wcslen (dirname) < MAX_PATH);
/* construct new _WDIR structure */
dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
if (dirp != NULL) {
wchar_t *p;
/* take directory name... */
STRNCPY (dirp->patt, dirname, sizeof(dirp->patt));
dirp->patt[MAX_PATH] = '\0';
/* ... and append search pattern to it */
p = wcschr (dirp->patt, '\0');
if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') {
*p++ = '\\';
}
*p++ = '*';
*p = '\0';
/* open stream and retrieve first file */
dirp->search_handle = FindFirstFileW (dirp->patt, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* invalid search pattern? */
free (dirp);
return NULL;
}
/* there is an un-processed directory entry in memory now */
|
| ︙ | ︙ | |||
141 142 143 144 145 146 147 | /***************************************************************************** * Read a directory entry, and return a pointer to a dirent structure * containing the name of the entry in d_name field. Individual directory * entries returned by this very function include regular files, * sub-directories, pseudo-directories "." and "..", but also volume labels, * hidden files and system files may be returned. */ | | | | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
/*****************************************************************************
* Read a directory entry, and return a pointer to a dirent structure
* containing the name of the entry in d_name field. Individual directory
* entries returned by this very function include regular files,
* sub-directories, pseudo-directories "." and "..", but also volume labels,
* hidden files and system files may be returned.
*/
static struct _wdirent *_wreaddir(_WDIR *dirp)
{
assert (dirp != NULL);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or ended normally */
return NULL;
}
/* get next directory entry */
if (dirp->cached != 0) {
/* a valid directory entry already in memory */
dirp->cached = 0;
} else {
/* read next directory entry from disk */
if (FindNextFileW (dirp->search_handle, &dirp->current.data) == FALSE) {
/* the very last file has been processed or an error occured */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
return NULL;
}
}
|
| ︙ | ︙ | |||
179 180 181 182 183 184 185 | /***************************************************************************** * Close directory stream opened by opendir() function. Close of the * directory stream invalidates the DIR structure as well as any previously * read directory entry. */ | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
/*****************************************************************************
* Close directory stream opened by opendir() function. Close of the
* directory stream invalidates the DIR structure as well as any previously
* read directory entry.
*/
static int _wclosedir(_WDIR *dirp)
{
assert (dirp != NULL);
/* release search handle */
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
}
/* release directory handle */
free (dirp);
return 0;
}
#endif /*DIRENT_H*/
|