sqlite: add unused file size impl

Change-Id: Ia0985ad51c716ac7a06c479655a60cc641977854
This commit is contained in:
Daniel Erat 2011-07-18 00:49:54 +00:00
parent 8d19dabe73
commit 8875ffeff0
2 changed files with 45 additions and 4 deletions

View File

@ -32,6 +32,25 @@ static int go_file_write(sqlite3_file* file, const void* src, int iAmt, sqlite3_
return 0;
}
static int go_file_truncate(sqlite3_file* file, sqlite3_int64 size) {
// TODO: implement
return SQLITE_OK;
}
static int go_file_sync(sqlite3_file* file, int flags) {
// TODO: implement
return SQLITE_OK;
}
static int go_file_file_size(sqlite3_file* file, sqlite3_int64* pSize) {
struct GoFileFileSize_return result = GoFileFileSize(((GoFile*) file)->fd);
if (result.r0 != 0)
return SQLITE_ERROR;
*pSize = result.r1;
return SQLITE_OK;
}
/* VFS methods */
static int go_vfs_open(sqlite3_vfs* vfs,
@ -70,6 +89,7 @@ static int go_vfs_full_pathname(sqlite3_vfs* vfs,
const char* zName,
int nOut,
char* zOut) {
// TODO: Actually implement this.
strncpy(zOut, zName, nOut);
zOut[nOut - 1] = '\0';
return SQLITE_OK;
@ -157,10 +177,10 @@ int sqlite3_os_init(void) {
g_file_methods.xClose = go_file_close;
g_file_methods.xRead = go_file_read;
g_file_methods.xWrite = go_file_write;
g_file_methods.xTruncate = go_file_truncate;
g_file_methods.xSync = go_file_sync;
g_file_methods.xFileSize = go_file_file_size;
#if 0
int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
int (*xSync)(sqlite3_file*, int flags);
int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
int (*xLock)(sqlite3_file*, int);
int (*xUnlock)(sqlite3_file*, int);
int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);

View File

@ -35,7 +35,7 @@ func GoFileClose(fd C.int) (int) {
//export GoFileRead
// Returns 0 on success and -1 on error.
func GoFileRead(fd C.int, dst *C.char, n C.int, offset C.int) (rv int) {
func GoFileRead(fd C.int, dst *C.char, n C.int, offset C.long) (rv int) {
println("reading", n, "bytes at offset", offset, "from fd", fd);
defer func() {
println("read returning", rv);
@ -68,6 +68,27 @@ func GoFileRead(fd C.int, dst *C.char, n C.int, offset C.int) (rv int) {
return 0
}
//export GoFileFileSize
// rv is 0 on success and -1 on error.
// TODO: size should be C.long, but cgo fails
func GoFileFileSize(fd C.int) (rv int, size C.int) {
println("getting file size for fd", fd);
defer func() {
println("returning", rv, "with size", size);
}()
file := GetFile(int(fd))
if file == nil {
return -1, 0
}
info, err := file.Stat()
if err != nil {
return -1, 0
}
return 0, C.int(info.Size)
}
//export GoVFSOpen
// fd is -1 on error.
func GoVFSOpen(filename *C.char, flags C.int) (fd int) {