112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
-
+
-
+
|
return getStat(zFilename, 0) ? -1 : fileStat.st_size;
}
/*
** Same as file_size(), but takes into account symlinks.
*/
i64 file_wd_size(const char *zFilename){
return getStat(zFilename, 1) ? -1 : fileStat.st_size;
return getStat(zFilename, 1) ? -1 : fileStat.st_size;
}
/*
** Return the modification time for a file. Return -1 if the file
** does not exist. If zFilename is NULL return the size of the most
** recently stat-ed file.
*/
i64 file_mtime(const char *zFilename){
return getStat(zFilename, 0) ? -1 : fileStat.st_mtime;
}
/*
** Same as file_mtime(), but takes into account symlinks.
*/
i64 file_wd_mtime(const char *zFilename){
return getStat(zFilename, 1) ? -1 : fileStat.st_mtime;
}
/*
** Return TRUE if the named file is an ordinary file or symlink
** Return TRUE if the named file is an ordinary file or symlink
** and symlinks are allowed.
** Return false for directories, devices, fifos, etc.
*/
int file_wd_isfile_or_link(const char *zFilename){
return getStat(zFilename, 1) ? 0 : S_ISREG(fileStat.st_mode) ||
S_ISLNK(fileStat.st_mode);
}
|
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
|
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
|
-
-
-
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
+
+
+
+
-
-
+
+
-
+
+
+
+
+
+
-
+
-
-
+
+
-
+
|
#else
char *zValue = getenv(zName);
#endif
return zValue;
}
/*
** Translate UTF8 to MBCS for display on the console. Return a pointer to the
** translated text.. Call fossil_mbcs_free() to deallocate any memory
** used to store the returned pointer when done.
** Display UTF8 on the console. Return the number of
** Characters written. If stdout or stderr is redirected
** to a file, -1 is returned and nothing is written
** to the console.
*/
char *fossil_utf8_to_console(const char *zUtf8){
int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
#ifdef _WIN32
int nChar, nByte;
WCHAR *zUnicode; /* Unicode version of zUtf8 */
int nChar;
wchar_t *zUnicode; /* Unicode version of zUtf8 */
#ifdef UNICODE
DWORD dummy;
#else
char *zConsole; /* Console version of zUtf8 */
int codepage; /* Console code page */
#endif
static int istty[2] = { -1, -1 };
if( istty[toStdErr] == -1 ){
istty[toStdErr] = _isatty(toStdErr + 1) != 0;
}
if( !istty[toStdErr] ){
/* stdout/stderr is not a console. */
return -1;
}
nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, NULL, 0);
zUnicode = malloc( nChar*sizeof(zUnicode[0]) );
nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, NULL, 0);
zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) );
if( zUnicode==0 ){
return 0;
}
nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nChar);
nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
if( nChar==0 ){
free(zUnicode);
return 0;
}
zUnicode[nChar] = '\0';
#ifdef UNICODE
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode, nChar, &dummy, 0);
#else /* !UNICODE */
codepage = GetConsoleCP();
nByte = WideCharToMultiByte(codepage, 0, zUnicode, -1, 0, 0, 0, 0);
zConsole = malloc( nByte );
nByte = WideCharToMultiByte(codepage, 0, zUnicode, nChar, 0, 0, 0, 0);
zConsole = malloc( nByte + 1);
if( zConsole==0 ){
free(zUnicode);
return 0;
}
nByte = WideCharToMultiByte(codepage, 0, zUnicode, -1, zConsole, nByte, 0, 0);
nByte = WideCharToMultiByte(codepage, 0, zUnicode, nChar, zConsole, nByte, 0, 0);
zConsole[nByte] = '\0';
free(zUnicode);
if( nByte == 0 ){
free(zConsole);
zConsole = 0;
return 0;
}
fwrite(zConsole, 1, nByte, toStdErr ? stderr : stdout);
fflush(toStdErr ? stderr : stdout);
#endif /* UNICODE */
return zConsole;
return nChar;
#else
return (char*)zUtf8; /* No-op on unix */
#endif
return -1; /* No-op on unix */
#endif
}
/*
** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
** to deallocate any memory used to store the returned pointer when done.
*/
void fossil_mbcs_free(void *zOld){
#ifdef _WIN32
extern void sqlite3_free(void*);
sqlite3_free(zOld);
#else
/* No-op on unix */
#endif
#endif
}
/*
** Like fopen() but always takes a UTF8 argument.
*/
FILE *fossil_fopen(const char *zName, const char *zMode){
#ifdef _WIN32
|