winGetLastError support added. Consolidated getLastErrorMsg() support. Removed some more WINCE dead code similar to instance in ticket #3232. Added error return on SystemTimeToFileTime() failure. (CVS 5450)

FossilOrigin-Name: c0a5cf38eea80640e42c612ce6f4850c98f70638
This commit is contained in:
shane 2008-07-22 05:32:03 +00:00
parent 0b8d276684
commit 820800d0bf
3 changed files with 75 additions and 41 deletions

View File

@ -1,5 +1,5 @@
C Changed\sa\sfew\sloop\scounters\sto\sunsigned\sints\sto\sremove\scompiler\swarnings.\s(CVS\s5449)
D 2008-07-22T05:18:01
C winGetLastError\ssupport\sadded.\s\sConsolidated\sgetLastErrorMsg()\ssupport.\s\sRemoved\ssome\smore\sWINCE\sdead\scode\ssimilar\sto\sinstance\sin\sticket\s#3232.\s\s\sAdded\serror\sreturn\son\sSystemTimeToFileTime()\sfailure.\s(CVS\s5450)
D 2008-07-22T05:32:03
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 77ff156061bb870aa0a8b3d545c670d08070f7e6
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -133,7 +133,7 @@ F src/os.h ef8abeb9afc694b82dbd169a91c9b7e26db3c892
F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
F src/os_os2.c da14449fc210cd313eb56cf511ae05b350e323d6
F src/os_unix.c 1df6108efdb7957a9f28b9700600e58647c9c12d
F src/os_win.c 08f8678d2cce51f2366ef3579fdfad9aad745b06
F src/os_win.c 50ec783403b418ddc9e6e05d541c6027dfd41070
F src/pager.c a6ecad26297469a8a3d1fd7a7c3dc2d603955044
F src/pager.h 588c1ac195228b2da45c4e5f7ab6c2fd253d1751
F src/parse.y d1316f1b8b251412bdf4926c4c34803977958b65
@ -608,7 +608,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P e20f2b8c6a13aa826703441cf340d0ee03bf9f64
R 67e26af499bfcadbb1a16712b95d09d3
P 16f51f9b39c46659b4be4afd7f0d8ec325469e7b
R 73922393200765ca01fdc60886028f22
U shane
Z 2fcb45844f990ac9b853cdd298c7bd91
Z 22add217ca23a8af113eab5534dd74da

View File

@ -1 +1 @@
16f51f9b39c46659b4be4afd7f0d8ec325469e7b
c0a5cf38eea80640e42c612ce6f4850c98f70638

View File

@ -12,7 +12,7 @@
**
** This file contains code that is specific to windows.
**
** $Id: os_win.c,v 1.130 2008/07/18 23:47:43 drh Exp $
** $Id: os_win.c,v 1.131 2008/07/22 05:32:03 shane Exp $
*/
#include "sqliteInt.h"
#if SQLITE_OS_WIN /* This file is used for windows only */
@ -1124,6 +1124,36 @@ static int getTempname(int nBuf, char *zBuf){
return SQLITE_OK;
}
/*
** The return value of getLastErrorMsg
** is zero if the error message fits in the buffer, or non-zero
** otherwise (if the message was truncated).
*/
static int getLastErrorMsg(int nBuf, char *zBuf){
DWORD error = GetLastError();
#if SQLITE_OS_WINCE
sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error);
#else
/* FormatMessage returns 0 on failure. Otherwise it
** returns the number of TCHARs written to the output
** buffer, excluding the terminating null char.
*/
if (!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
error,
0,
zBuf,
nBuf-1,
0))
{
sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error);
}
#endif
return 0;
}
/*
** Open a file.
@ -1204,9 +1234,6 @@ static int winOpen(
NULL
);
}else{
#if SQLITE_OS_WINCE
return SQLITE_NOMEM;
#else
h = CreateFileA((char*)zConverted,
dwDesiredAccess,
dwShareMode,
@ -1215,7 +1242,6 @@ static int winOpen(
dwFlagsAndAttributes,
NULL
);
#endif
}
if( h==INVALID_HANDLE_VALUE ){
free(zConverted);
@ -1287,14 +1313,10 @@ static int winDelete(
}while( (rc = GetFileAttributesW(zConverted))!=0xffffffff
&& cnt++ < MX_DELETION_ATTEMPTS && (Sleep(100), 1) );
}else{
#if SQLITE_OS_WINCE
return SQLITE_NOMEM;
#else
do{
DeleteFileA(zConverted);
}while( (rc = GetFileAttributesA(zConverted))!=0xffffffff
&& cnt++ < MX_DELETION_ATTEMPTS && (Sleep(100), 1) );
#endif
}
free(zConverted);
OSTRACE2("DELETE \"%s\"\n", zFilename);
@ -1319,17 +1341,13 @@ static int winAccess(
if( isNT() ){
attr = GetFileAttributesW((WCHAR*)zConverted);
}else{
#if SQLITE_OS_WINCE
return SQLITE_NOMEM;
#else
attr = GetFileAttributesA((char*)zConverted);
#endif
}
free(zConverted);
switch( flags ){
case SQLITE_ACCESS_READ:
case SQLITE_ACCESS_EXISTS:
rc = attr!=0xffffffff;
rc = attr!=INVALID_FILE_ATTRIBUTES;
break;
case SQLITE_ACCESS_READWRITE:
rc = (attr & FILE_ATTRIBUTE_READONLY)==0;
@ -1429,24 +1447,7 @@ static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
return (void*)h;
}
static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
#if SQLITE_OS_WINCE
int error = GetLastError();
if( error>0x7FFFFFF ){
sqlite3_snprintf(nBuf, zBufOut, "OsError 0x%x", error);
}else{
sqlite3_snprintf(nBuf, zBufOut, "OsError %d", error);
}
#else
FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
0,
zBufOut,
nBuf-1,
0
);
#endif
getLastErrorMsg(nBuf, zBufOut);
}
void *winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol){
#if SQLITE_OS_WINCE
@ -1530,7 +1531,10 @@ int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
#if SQLITE_OS_WINCE
SYSTEMTIME time;
GetSystemTime(&time);
SystemTimeToFileTime(&time,&ft);
/* if SystemTimeToFileTime() fails, it returns zero. */
if (!SystemTimeToFileTime(&time,&ft)){
return 1;
}
#else
GetSystemTimeAsFileTime( &ft );
#endif
@ -1544,8 +1548,38 @@ int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
return 0;
}
/*
** The idea is that this function works like a combination of
** GetLastError() and FormatMessage() on windows (or errno and
** strerror_r() on unix). After an error is returned by an OS
** function, SQLite calls this function with zBuf pointing to
** a buffer of nBuf bytes. The OS layer should populate the
** buffer with a nul-terminated UTF-8 encoded error message
** describing the last IO error to have occured within the calling
** thread.
**
** If the error message is too large for the supplied buffer,
** it should be truncated. The return value of xGetLastError
** is zero if the error message fits in the buffer, or non-zero
** otherwise (if the message was truncated). If non-zero is returned,
** then it is not necessary to include the nul-terminator character
** in the output buffer.
**
** Not supplying an error message will have no adverse effect
** on SQLite. It is fine to have an implementation that never
** returns an error message:
**
** int xGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
** assert(zBuf[0]=='\0');
** return 0;
** }
**
** However if an error message is supplied, it will be incorporated
** by sqlite into the error message available to the user using
** sqlite3_errmsg(), possibly making IO errors easier to debug.
*/
static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
return 0;
return getLastErrorMsg(nBuf, zBuf);
}
/*