forked from ncruces/go-sqlite3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrap_env.go
More file actions
107 lines (94 loc) · 1.77 KB
/
wrap_env.go
File metadata and controls
107 lines (94 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package sqlite3
import (
"io"
"github.com/ncruces/go-sqlite3/internal/testenv"
)
func (e *env) Xexit(c int32) {
testenv.Exit(c)
}
func (e *env) Xsystem(ptr int32) int32 {
return testenv.System(e.Wrapper, ptr)
}
func (e *env) Xputs(ptr int32) int32 {
if testenv.TB == nil {
return -1
}
s := e.ReadString(ptr_t(ptr), _MAX_NAME)
testenv.WriteString(s)
testenv.WriteByte('\n')
return 0
}
func (e *env) Xfclose(h int32) int32 {
if testenv.TB == nil {
return -1
}
if e.DelHandle(ptr_t(h)) != nil {
return -1
}
return 0
}
func (e *env) Xfopen(path, mode int32) int32 {
if testenv.TB == nil {
return 0
}
p := e.ReadString(ptr_t(path), _MAX_NAME)
f, err := testenv.FS.Open(p)
if err != nil {
return 0
}
return int32(e.AddHandle(f))
}
func (e *env) Xfflush(h int32) int32 {
if testenv.TB == nil {
return -1
}
return 0
}
func (e *env) Xfputc(c, h int32) int32 {
if testenv.TB == nil {
return -1
}
if testenv.WriteByte(byte(c)) != nil {
return -1
}
return 0
}
func (e *env) Xfwrite(ptr, sz, cnt, h int32) int32 {
if testenv.TB == nil {
return 0
}
b := e.Buf[ptr:][:sz*cnt]
n, _ := testenv.Write(b)
return int32(n / int(sz))
}
func (e *env) Xfread(ptr, sz, cnt, h int32) int32 {
if testenv.TB == nil {
return 0
}
f := e.GetHandle(ptr_t(h)).(io.Reader)
b := e.Buf[ptr:][:sz*cnt]
n, _ := f.Read(b)
return int32(n / int(sz))
}
func (e *env) Xftell(h int32) int32 {
if testenv.TB == nil {
return -1
}
f := e.GetHandle(ptr_t(h)).(io.Seeker)
n, err := f.Seek(0, io.SeekCurrent)
if err != nil {
return -1
}
return int32(n)
}
func (e *env) Xfseek(h, offset, whence int32) int32 {
if testenv.TB == nil {
return -1
}
f := e.GetHandle(ptr_t(h)).(io.Seeker)
_, err := f.Seek(int64(offset), int(whence))
if err != nil {
return -1
}
return 0
}