diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-12-14 12:00:05 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-12-14 12:00:05 +0100 |
commit | 7cc25005b8c46d1fa783d33def2c6923e8ef8469 (patch) | |
tree | 64fa59d17af29838396cf37b912b3babd885e5dd /common/unqlite/os.c | |
parent | bfc32f265e8ad72823db960fed371d72596003b7 (diff) | |
parent | a6ed70495f9f3ecb21c26860dda16aadcdc91c3a (diff) | |
download | sink-7cc25005b8c46d1fa783d33def2c6923e8ef8469.tar.gz sink-7cc25005b8c46d1fa783d33def2c6923e8ef8469.zip |
Merge branch 'unqlite'
Diffstat (limited to 'common/unqlite/os.c')
-rw-r--r-- | common/unqlite/os.c | 117 |
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 | */ | ||
24 | UNQLITE_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 | } | ||
28 | UNQLITE_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 | } | ||
32 | UNQLITE_PRIVATE int unqliteOsTruncate(unqlite_file *id, unqlite_int64 size) | ||
33 | { | ||
34 | return id->pMethods->xTruncate(id, size); | ||
35 | } | ||
36 | UNQLITE_PRIVATE int unqliteOsSync(unqlite_file *id, int flags) | ||
37 | { | ||
38 | return id->pMethods->xSync(id, flags); | ||
39 | } | ||
40 | UNQLITE_PRIVATE int unqliteOsFileSize(unqlite_file *id, unqlite_int64 *pSize) | ||
41 | { | ||
42 | return id->pMethods->xFileSize(id, pSize); | ||
43 | } | ||
44 | UNQLITE_PRIVATE int unqliteOsLock(unqlite_file *id, int lockType) | ||
45 | { | ||
46 | return id->pMethods->xLock(id, lockType); | ||
47 | } | ||
48 | UNQLITE_PRIVATE int unqliteOsUnlock(unqlite_file *id, int lockType) | ||
49 | { | ||
50 | return id->pMethods->xUnlock(id, lockType); | ||
51 | } | ||
52 | UNQLITE_PRIVATE int unqliteOsCheckReservedLock(unqlite_file *id, int *pResOut) | ||
53 | { | ||
54 | return id->pMethods->xCheckReservedLock(id, pResOut); | ||
55 | } | ||
56 | UNQLITE_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 | */ | ||
67 | UNQLITE_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 | } | ||
98 | UNQLITE_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 | } | ||
107 | UNQLITE_PRIVATE int unqliteOsDelete(unqlite_vfs *pVfs, const char *zPath, int dirSync){ | ||
108 | return pVfs->xDelete(pVfs, zPath, dirSync); | ||
109 | } | ||
110 | UNQLITE_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 | } | ||