From 47224c438732d021e5aef74af30c7fd5801621d2 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Sun, 12 Jan 2014 15:50:35 -0700 Subject: Mock syscall. --- db.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'db.go') diff --git a/db.go b/db.go index d9a6274..67c1b46 100644 --- a/db.go +++ b/db.go @@ -27,6 +27,7 @@ type DB struct { opened bool os _os + syscall _syscall file file metafile file data []byte @@ -71,6 +72,9 @@ func (db *DB) Open(path string, mode os.FileMode) error { if db.os == nil { db.os = &sysos{} } + if db.syscall == nil { + db.syscall = &syssyscall{} + } // Exit if the database is currently open. if db.opened { @@ -145,7 +149,7 @@ func (db *DB) mmap() error { // Determine the map size based on the file size. var size int - if info, err := db.os.Stat(db.file.Name()); err != nil { + if info, err := db.os.Stat(db.path); err != nil { return err } else if info.Size() < int64(db.pageSize*2) { return &Error{"file size too small", nil} @@ -154,7 +158,7 @@ func (db *DB) mmap() error { } // Memory-map the data file as a byte slice. - if db.data, err = syscall.Mmap(int(db.file.Fd()), 0, size, syscall.PROT_READ, syscall.MAP_SHARED); err != nil { + if db.data, err = db.syscall.Mmap(int(db.file.Fd()), 0, size, syscall.PROT_READ, syscall.MAP_SHARED); err != nil { return err } -- cgit v1.2.3