summaryrefslogtreecommitdiffstats
path: root/common/unqlite/os.c
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2014-12-07 10:08:07 +0100
committerAaron Seigo <aseigo@kde.org>2014-12-11 01:07:08 +0100
commit9ee8378d393778ac67314be7ea8d5bcbaeee9ee0 (patch)
treecf93471a69f9f4bbb4940de55ae134106fcd8380 /common/unqlite/os.c
parentee6f068dff6b15441e553ffbfb2bf8aa97b26f57 (diff)
downloadsink-9ee8378d393778ac67314be7ea8d5bcbaeee9ee0.tar.gz
sink-9ee8378d393778ac67314be7ea8d5bcbaeee9ee0.zip
try out unqlite
Diffstat (limited to 'common/unqlite/os.c')
-rw-r--r--common/unqlite/os.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/common/unqlite/os.c b/common/unqlite/os.c
new file mode 100644
index 0000000..180c898
--- /dev/null
+++ b/common/unqlite/os.c
@@ -0,0 +1,117 @@
1/*
2 * Symisc unQLite: An Embeddable NoSQL (Post Modern) Database Engine.
3 * Copyright (C) 2012-2013, Symisc Systems http://unqlite.org/
4 * Version 1.1.6
5 * For information on licensing, redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES
6 * please contact Symisc Systems via:
7 * legal@symisc.net
8 * licensing@symisc.net
9 * contact@symisc.net
10 * or visit:
11 * http://unqlite.org/licensing.html
12 */
13 /* $SymiscID: os.c v1.0 FreeBSD 2012-11-12 21:27 devel <chm@symisc.net> $ */
14#ifndef UNQLITE_AMALGAMATION
15#include "unqliteInt.h"
16#endif
17/* OS interfaces abstraction layers: Mostly SQLite3 source tree */
18/*
19** The following routines are convenience wrappers around methods
20** of the unqlite_file object. This is mostly just syntactic sugar. All
21** of this would be completely automatic if UnQLite were coded using
22** C++ instead of plain old C.
23*/
24UNQLITE_PRIVATE int unqliteOsRead(unqlite_file *id, void *pBuf, unqlite_int64 amt, unqlite_int64 offset)
25{
26 return id->pMethods->xRead(id, pBuf, amt, offset);
27}
28UNQLITE_PRIVATE int unqliteOsWrite(unqlite_file *id, const void *pBuf, unqlite_int64 amt, unqlite_int64 offset)
29{
30 return id->pMethods->xWrite(id, pBuf, amt, offset);
31}
32UNQLITE_PRIVATE int unqliteOsTruncate(unqlite_file *id, unqlite_int64 size)
33{
34 return id->pMethods->xTruncate(id, size);
35}
36UNQLITE_PRIVATE int unqliteOsSync(unqlite_file *id, int flags)
37{
38 return id->pMethods->xSync(id, flags);
39}
40UNQLITE_PRIVATE int unqliteOsFileSize(unqlite_file *id, unqlite_int64 *pSize)
41{
42 return id->pMethods->xFileSize(id, pSize);
43}
44UNQLITE_PRIVATE int unqliteOsLock(unqlite_file *id, int lockType)
45{
46 return id->pMethods->xLock(id, lockType);
47}
48UNQLITE_PRIVATE int unqliteOsUnlock(unqlite_file *id, int lockType)
49{
50 return id->pMethods->xUnlock(id, lockType);
51}
52UNQLITE_PRIVATE int unqliteOsCheckReservedLock(unqlite_file *id, int *pResOut)
53{
54 return id->pMethods->xCheckReservedLock(id, pResOut);
55}
56UNQLITE_PRIVATE int unqliteOsSectorSize(unqlite_file *id)
57{
58 if( id->pMethods->xSectorSize ){
59 return id->pMethods->xSectorSize(id);
60 }
61 return UNQLITE_DEFAULT_SECTOR_SIZE;
62}
63/*
64** The next group of routines are convenience wrappers around the
65** VFS methods.
66*/
67UNQLITE_PRIVATE int unqliteOsOpen(
68 unqlite_vfs *pVfs,
69 SyMemBackend *pAlloc,
70 const char *zPath,
71 unqlite_file **ppOut,
72 unsigned int flags
73)
74{
75 unqlite_file *pFile;
76 int rc;
77 *ppOut = 0;
78 if( zPath == 0 ){
79 /* May happen if dealing with an in-memory database */
80 return SXERR_EMPTY;
81 }
82 /* Allocate a new instance */
83 pFile = (unqlite_file *)SyMemBackendAlloc(pAlloc,sizeof(unqlite_file)+pVfs->szOsFile);
84 if( pFile == 0 ){
85 return UNQLITE_NOMEM;
86 }
87 /* Zero the structure */
88 SyZero(pFile,sizeof(unqlite_file)+pVfs->szOsFile);
89 /* Invoke the xOpen method of the underlying VFS */
90 rc = pVfs->xOpen(pVfs, zPath, pFile, flags);
91 if( rc != UNQLITE_OK ){
92 SyMemBackendFree(pAlloc,pFile);
93 pFile = 0;
94 }
95 *ppOut = pFile;
96 return rc;
97}
98UNQLITE_PRIVATE int unqliteOsCloseFree(SyMemBackend *pAlloc,unqlite_file *pId)
99{
100 int rc = UNQLITE_OK;
101 if( pId ){
102 rc = pId->pMethods->xClose(pId);
103 SyMemBackendFree(pAlloc,pId);
104 }
105 return rc;
106}
107UNQLITE_PRIVATE int unqliteOsDelete(unqlite_vfs *pVfs, const char *zPath, int dirSync){
108 return pVfs->xDelete(pVfs, zPath, dirSync);
109}
110UNQLITE_PRIVATE int unqliteOsAccess(
111 unqlite_vfs *pVfs,
112 const char *zPath,
113 int flags,
114 int *pResOut
115){
116 return pVfs->xAccess(pVfs, zPath, flags, pResOut);
117}