From 4b4c03fd9072c3dadbc7e7378e3e0b8618f838ad Mon Sep 17 00:00:00 2001 From: liwei Date: Mon, 2 Dec 2024 23:14:10 +0800 Subject: [PATCH] fix: ffi instance be singleton --- bind/common.go | 47 +- bind/desktop/main.go | 15 +- bind/mobile/main.go | 8 +- cmd/server.go | 2 +- pkg/api/api.go | 65 +- pkg/api/api_test.go | 672 +-- pkg/api/api_test.go.bak | 669 +++ pkg/api/http.go | 17 +- pkg/base/model.go | 2 + ui/flutter/include/libgopeed.h | 27 +- .../lib/api/entry/libgopeed_boot_native.dart | 71 +- .../lib/api/entry/libgopeed_boot_web.dart | 8 +- ui/flutter/lib/api/libgopeed_boot.dart | 11 +- .../api/native/channel/libgopeed_channel.dart | 8 +- .../lib/api/native/ffi/libgopeed_bind.dart | 4530 +---------------- .../lib/api/native/ffi/libgopeed_ffi.dart | 15 +- .../lib/api/native/libgopeed_interface.dart | 10 +- ui/flutter/lib/main.dart | 3 +- 18 files changed, 844 insertions(+), 5336 deletions(-) create mode 100644 pkg/api/api_test.go.bak diff --git a/bind/common.go b/bind/common.go index a47a0e1b..a945bfd4 100644 --- a/bind/common.go +++ b/bind/common.go @@ -5,51 +5,24 @@ import ( "errors" "github.com/GopeedLab/gopeed/pkg/api" "github.com/GopeedLab/gopeed/pkg/api/model" - "sync" ) -type instanceArray struct { - mu sync.RWMutex - array []*api.Instance -} +// Global singleton instance +var instance *api.Instance -// append appends an instance to the array. -// Returns the index of the instance in the array. -func (ia *instanceArray) append(instance *api.Instance) int { - ia.mu.Lock() - defer ia.mu.Unlock() - - ia.array = append(ia.array, instance) - return len(ia.array) - 1 -} - -func (ia *instanceArray) get(index int) (*api.Instance, bool) { - ia.mu.RLock() - defer ia.mu.RUnlock() - if index < 0 || index >= len(ia.array) { - return nil, false +func Init(config *model.StartConfig) (err error) { + if instance != nil { + return nil } - return ia.array[index], true -} -var instances = &instanceArray{ - mu: sync.RWMutex{}, - array: make([]*api.Instance, 0), -} - -func Create(config *model.StartConfig) string { config.ProductionMode = true - instance, err := api.Create(config) - if err != nil { - return BuildResult(err) - } - return BuildResult(instances.append(instance)) + instance, err = api.Create(config) + return } -func Invoke(index int, request *api.Request) string { - instance, ok := instances.get(index) - if !ok { - return BuildResult(errors.New("instance not found")) +func Invoke(request *api.Request) string { + if instance == nil { + return BuildResult(errors.New("instance not initialized")) } return jsonEncode(api.Invoke(instance, request)) } diff --git a/bind/desktop/main.go b/bind/desktop/main.go index c2c1afd5..f1b12b5e 100644 --- a/bind/desktop/main.go +++ b/bind/desktop/main.go @@ -10,22 +10,25 @@ import ( func main() {} -//export Create -func Create(cfg *C.char) *C.char { +//export Init +func Init(cfg *C.char) *C.char { var config model.StartConfig if err := json.Unmarshal([]byte(C.GoString(cfg)), &config); err != nil { - return C.CString(bind.BuildResult(err)) + return C.CString(err.Error()) + } + if err := bind.Init(&config); err != nil { + return C.CString(err.Error()) } - return C.CString(bind.Create(&config)) + return nil } //export Invoke -func Invoke(index int, req *C.char) *C.char { +func Invoke(req *C.char) *C.char { var request api.Request if err := json.Unmarshal([]byte(C.GoString(req)), &request); err != nil { return C.CString(bind.BuildResult(err)) } - return C.CString(bind.Invoke(index, &request)) + return C.CString(bind.Invoke(&request)) } diff --git a/bind/mobile/main.go b/bind/mobile/main.go index 9ea1e05f..000cdc2c 100644 --- a/bind/mobile/main.go +++ b/bind/mobile/main.go @@ -8,10 +8,10 @@ import ( "github.com/GopeedLab/gopeed/pkg/api/model" ) -func Create(cfg *model.StartConfig) string { - return bind.Create(cfg) +func Init(cfg *model.StartConfig) error { + return bind.Init(cfg) } -func Invoke(index int, request *api.Request) string { - return bind.Invoke(index, request) +func Invoke(request *api.Request) string { + return bind.Invoke(request) } diff --git a/cmd/server.go b/cmd/server.go index 4e822a0f..97d391a0 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -60,7 +60,7 @@ func Start(cfg *model.StartConfig) { if err != nil { panic(err) } - fmt.Printf("Server start success on http://%s:%d\n", result.Host, result.Port) + fmt.Printf("Server start success on http://%s:%d\n", cfg.DownloadConfig.Http.Host, result) start() } diff --git a/pkg/api/api.go b/pkg/api/api.go index 2cf7514f..43fe2167 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -17,12 +17,10 @@ import ( type Instance struct { startCfg *model.StartConfig downloader *download.Downloader - running bool - httpLock sync.Mutex - srv *http.Server - listener net.Listener - runningPort int + httpLock sync.Mutex + srv *http.Server + listener net.Listener } func Create(startCfg *model.StartConfig) (*Instance, error) { @@ -51,44 +49,45 @@ func Create(startCfg *model.StartConfig) (*Instance, error) { return nil, err } i.downloader = downloader - i.running = true i.httpLock = sync.Mutex{} return i, nil } -func (i *Instance) StartHttp() *model.Result[*model.HttpListenResult] { +func (i *Instance) StartHttp() *model.Result[any] { i.httpLock.Lock() defer i.httpLock.Unlock() return i.startHttp() } -func (i *Instance) startHttp() *model.Result[*model.HttpListenResult] { +func (i *Instance) startHttp() *model.Result[any] { + httpCfg := i.getHttpConfig() + if httpCfg == nil || !httpCfg.Enable { + return model.NewErrorResult[any]("HTTP API server not enabled") + } + if i.srv != nil { + return model.NewErrorResult[any]("HTTP API server already started") + } + + port, start, err := ListenHttp(httpCfg, i) + if err != nil { + return model.NewErrorResult[any](err.Error()) + } + httpCfg.RunningPort = port + go start() + return model.NewNilResult() +} + +func (i *Instance) getHttpConfig() *base.DownloaderHttpConfig { var httpCfg *base.DownloaderHttpConfig - // if startCfg has http config, first use it if i.startCfg.DownloadConfig != nil && i.startCfg.DownloadConfig.Http != nil { httpCfg = i.startCfg.DownloadConfig.Http } else { - cfg, err := i.downloader.GetConfig() - if err != nil { - return model.NewErrorResult[*model.HttpListenResult](err.Error()) - } + cfg, _ := i.downloader.GetConfig() httpCfg = cfg.Http } - - if httpCfg == nil || !httpCfg.Enable { - return model.NewErrorResult[*model.HttpListenResult]("HTTP API server not enabled") - } - if i.srv != nil { - return model.NewErrorResult[*model.HttpListenResult]("HTTP API server already started") - } - result, start, err := ListenHttp(httpCfg, i) - if err != nil { - return model.NewErrorResult[*model.HttpListenResult](err.Error()) - } - go start() - return model.NewOkResult[*model.HttpListenResult](result) + return httpCfg } func (i *Instance) StopHttp() *model.Result[any] { @@ -105,12 +104,15 @@ func (i *Instance) stopHttp() *model.Result[any] { } i.srv = nil i.listener = nil - i.runningPort = 0 + } + httpCfg := i.getHttpConfig() + if httpCfg != nil { + httpCfg.RunningPort = 0 } return model.NewNilResult() } -func (i *Instance) RestartHttp() *model.Result[*model.HttpListenResult] { +func (i *Instance) RestartHttp() *model.Result[any] { i.httpLock.Lock() defer i.httpLock.Unlock() @@ -337,7 +339,6 @@ func (i *Instance) Close() *model.Result[any] { i.downloader.Logger.Warn().Err(err).Msg("close downloader failed") } i.downloader = nil - i.running = false } return model.NewNilResult() @@ -349,7 +350,7 @@ type Request struct { } // Invoke support dynamic call method -func Invoke(server *Instance, request *Request) (ret any) { +func Invoke(instance *Instance, request *Request) (ret any) { defer func() { if err := recover(); err != nil { ret = model.NewErrorResult[any](fmt.Sprintf("%v", err)) @@ -357,7 +358,7 @@ func Invoke(server *Instance, request *Request) (ret any) { }() method, args := request.Method, request.Params - dsType := reflect.ValueOf(server) + dsType := reflect.ValueOf(instance) fn := dsType.MethodByName(method) numIn := fn.Type().NumIn() in := make([]reflect.Value, numIn) @@ -378,5 +379,5 @@ func Invoke(server *Instance, request *Request) (ret any) { in[i] = param } retVals := fn.Call(in) - return retVals[0] + return retVals[0].Interface() } diff --git a/pkg/api/api_test.go b/pkg/api/api_test.go index 0eaa6c72..b21e2492 100644 --- a/pkg/api/api_test.go +++ b/pkg/api/api_test.go @@ -1,668 +1,44 @@ package api import ( - "bytes" - "crypto/md5" "encoding/json" - "errors" - "fmt" - "github.com/GopeedLab/gopeed/internal/test" "github.com/GopeedLab/gopeed/pkg/api/model" - "github.com/GopeedLab/gopeed/pkg/base" "github.com/GopeedLab/gopeed/pkg/download" - "io" - "net" - "net/http" - "os" - "reflect" - "sync" "testing" - "time" ) -var ( - restPort int +var instance, _ = Create(nil) - taskReq = &base.Request{ - Extra: map[string]any{ - "method": "", - "header": map[string]string{ - "Usr-Agent": "gopeed", - }, - "body": "", - }, - } - taskRes = &base.Resource{ - Size: test.BuildSize, - Range: true, - Files: []*base.FileInfo{ - { - Name: test.BuildName, - Path: "", - Size: test.BuildSize, - }, - }, - } - createOpts = &base.Options{ - Path: test.Dir, - Name: test.DownloadName, - Extra: map[string]any{ - "connections": 2, - }, - } - createReq = &model.CreateTask{ - Req: taskReq, - Opt: createOpts, - } - createResoledReq = &model.CreateTask{ - Req: taskReq, - Opt: createOpts, - } - installExtensionReq = &model.InstallExtension{ - URL: "https://github.com/GopeedLab/gopeed-extension-samples#github-contributor-avatars-sample", - } -) - -func TestInfo(t *testing.T) { - matchKeys := []string{"version", "runtime", "os", "arch", "inDocker"} - doTest(func() { - resp := httpRequestCheckOk[map[string]any](http.MethodGet, "/api/v1/info", nil) - for _, key := range matchKeys { - if _, ok := resp[key]; !ok { - t.Errorf("Info() missing key = %v", key) - } - } - }) +func TestInvoke(t *testing.T) { + doTestInvoke(t, "Info", []any{}) + doTestInvoke(t, "GetTasks", nil) + doTestInvoke(t, "GetTasks", []any{}) + doTestInvoke(t, "GetTasks", []any{nil}) + doTestInvoke(t, "GetTasks", []any{&download.TaskFilter{}}) } -func TestResolve(t *testing.T) { - doTest(func() { - resp := httpRequestCheckOk[*download.ResolveResult](http.MethodPost, "/api/v1/resolve", taskReq) - if !test.AssertResourceEqual(taskRes, resp.Res) { - t.Errorf("Resolve() got = %v, want %v", test.ToJson(resp.Res), test.ToJson(taskRes)) - } - }) -} - -func TestCreateTask(t *testing.T) { - doTest(func() { - resp := httpRequestCheckOk[*download.ResolveResult](http.MethodPost, "/api/v1/resolve", taskReq) - - var wg sync.WaitGroup - wg.Add(1) - Downloader.Listener(func(event *download.Event) { - if event.Key == download.EventKeyFinally { - wg.Done() - } - }) - - taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", &model.CreateTask{ - Rid: resp.ID, - Opt: createOpts, - }) - if taskId == "" { - t.Fatal("create task failed") - } - - wg.Wait() - want := test.FileMd5(test.BuildFile) - got := test.FileMd5(test.DownloadFile) - if want != got { - t.Errorf("CreateTask() got = %v, want %v", got, want) - } - }) -} - -func TestCreateDirectTask(t *testing.T) { - doTest(func() { - var wg sync.WaitGroup - wg.Add(1) - Downloader.Listener(func(event *download.Event) { - if event.Key == download.EventKeyFinally { - wg.Done() - } - }) - - taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) - if taskId == "" { - t.Fatal("create task failed") - } - - wg.Wait() - want := test.FileMd5(test.BuildFile) - got := test.FileMd5(test.DownloadFile) - if want != got { - t.Errorf("CreateDirectTask() got = %v, want %v", got, want) - } - }) -} - -func TestCreateDirectTaskBatch(t *testing.T) { - doTest(func() { - reqs := make([]*base.Request, 0) - for i := 0; i < 5; i++ { - reqs = append(reqs, createReq.Req) - } - taskIds := httpRequestCheckOk[[]string](http.MethodPost, "/api/v1/tasks/batch", &model.CreateTaskBatch{ - Reqs: reqs, - }) - if len(taskIds) != len(reqs) { - t.Errorf("CreateDirectTaskBatch() got = %v, want %v", len(taskIds), len(reqs)) - } - }) -} - -func TestCreateDirectTaskWithResoled(t *testing.T) { - doTest(func() { - var wg sync.WaitGroup - wg.Add(1) - Downloader.Listener(func(event *download.Event) { - if event.Key == download.EventKeyFinally { - wg.Done() - } - }) - - taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createResoledReq) - if taskId == "" { - t.Fatal("create task failed") - } - - wg.Wait() - want := test.FileMd5(test.BuildFile) - got := test.FileMd5(test.DownloadFile) - if want != got { - t.Errorf("CreateDirectTaskWithResoled() got = %v, want %v", got, want) - } - }) -} - -func TestPauseAndContinueTask(t *testing.T) { - doTest(func() { - var wg sync.WaitGroup - wg.Add(1) - Downloader.Listener(func(event *download.Event) { - switch event.Key { - case download.EventKeyFinally: - wg.Done() - } - }) - - taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) - t1 := httpRequestCheckOk[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) - if t1.Status != base.DownloadStatusRunning { - t.Errorf("CreateTask() got = %v, want %v", t1.Status, base.DownloadStatusRunning) - } - httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/"+taskId+"/pause", nil) - t2 := httpRequestCheckOk[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) - if t2.Status != base.DownloadStatusPause { - t.Errorf("PauseTask() got = %v, want %v", t2.Status, base.DownloadStatusPause) - } - httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/"+taskId+"/continue", nil) - t3 := httpRequestCheckOk[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) - if t3.Status != base.DownloadStatusRunning { - t.Errorf("ContinueTask() got = %v, want %v", t3.Status, base.DownloadStatusRunning) - } - - wg.Wait() - want := test.FileMd5(test.BuildFile) - got := test.FileMd5(test.DownloadFile) - if !reflect.DeepEqual(got, want) { - t.Errorf("PauseAndContinueTask() got = %v, want %v", got, want) - } - }) -} - -func TestPauseAllAndContinueALLTasks(t *testing.T) { - doTest(func() { - cfg, err := Downloader.GetConfig() +func doTestInvoke(t *testing.T, method string, params []any) *model.Result[any] { + reqParams := make([]string, len(params)) + for i, p := range params { + bytes, err := json.Marshal(p) if err != nil { t.Fatal(err) } - - createAndPause := func() { - taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) - httpRequestCheckOk[*download.Task](http.MethodPut, "/api/v1/tasks/"+taskId+"/pause", nil) - } - - total := cfg.MaxRunning + 2 - for i := 0; i < total; i++ { - createAndPause() - } - - // continue all - httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/continue", nil) - time.Sleep(time.Millisecond * 100) - tasks := httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s", base.DownloadStatusRunning), nil) - if len(tasks) != cfg.MaxRunning { - t.Errorf("ContinueAllTasks() got = %v, want %v", len(tasks), cfg.MaxRunning) - } - // pause all - httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/pause", nil) - time.Sleep(time.Millisecond * 100) - tasks = httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s", base.DownloadStatusPause), nil) - if len(tasks) != total { - t.Errorf("PauseAllTasks() got = %v, want %v", len(tasks), total) - } - }) -} - -func TestDeleteTask(t *testing.T) { - doTest(func() { - taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) - time.Sleep(time.Millisecond * 200) - httpRequestCheckOk[any](http.MethodDelete, "/api/v1/tasks/"+taskId, nil) - code, _ := httpRequest[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) - checkCode(code, model.CodeTaskNotFound) - }) -} - -func TestDeleteTaskForce(t *testing.T) { - doTest(func() { - taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) - time.Sleep(time.Millisecond * 200) - httpRequestCheckOk[any](http.MethodDelete, "/api/v1/tasks/"+taskId+"?force=true", nil) - code, _ := httpRequest[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) - checkCode(code, model.CodeTaskNotFound) - if _, err := os.Stat(test.DownloadFile); !errors.Is(err, os.ErrNotExist) { - t.Errorf("DeleteTaskForce() got = %v, want %v", err, os.ErrNotExist) - } - }) -} - -func TestDeleteAllTasks(t *testing.T) { - doTest(func() { - taskCount := 3 - - var wg sync.WaitGroup - wg.Add(taskCount) - Downloader.Listener(func(event *download.Event) { - if event.Key == download.EventKeyFinally { - wg.Done() - } - }) - - for i := 0; i < taskCount; i++ { - httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) - } - - wg.Wait() - - httpRequestCheckOk[any](http.MethodDelete, "/api/v1/tasks?force=true", nil) - tasks := httpRequestCheckOk[[]*download.Task](http.MethodGet, "/api/v1/tasks", nil) - if len(tasks) != 0 { - t.Errorf("DeleteTasks() got = %v, want %v", len(tasks), 0) - } - }) -} - -func TestDeleteTasksByStatues(t *testing.T) { - doTest(func() { - taskCount := 3 - - var wg sync.WaitGroup - wg.Add(taskCount) - Downloader.Listener(func(event *download.Event) { - if event.Key == download.EventKeyFinally { - wg.Done() - } - }) - - for i := 0; i < taskCount; i++ { - httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) - } - - wg.Wait() - - httpRequestCheckOk[any](http.MethodDelete, fmt.Sprintf("/api/v1/tasks?status=%s&force=true", base.DownloadStatusDone), nil) - tasks := httpRequestCheckOk[[]*download.Task](http.MethodGet, "/api/v1/tasks", nil) - if len(tasks) != 0 { - t.Errorf("DeleteTasks() got = %v, want %v", len(tasks), 0) - } - }) -} - -func TestGetTasks(t *testing.T) { - doTest(func() { - var wg sync.WaitGroup - wg.Add(1) - Downloader.Listener(func(event *download.Event) { - if event.Key == download.EventKeyFinally { - wg.Done() - } - }) - - httpRequestCheckOk[string](http.MethodPost, fmt.Sprintf("/api/v1/tasks?status=%s&status=%s", - base.DownloadStatusReady, base.DownloadStatusRunning), createReq) - httpRequestCheckOk[[]*download.Task](http.MethodGet, "/api/v1/tasks", nil) - - wg.Wait() - r := httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s", - base.DownloadStatusDone), nil) - if r[0].Status != base.DownloadStatusDone { - t.Errorf("GetTasks() got = %v, want %v", r[0].Status, base.DownloadStatusDone) - } - r = httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s,%s", - base.DownloadStatusReady, base.DownloadStatusRunning), nil) - if len(r) > 0 { - t.Errorf("GetTasks() got = %v, want %v", len(r), 0) - } - }) -} - -func TestGetAndPutConfig(t *testing.T) { - doTest(func() { - cfg := httpRequestCheckOk[*base.DownloaderStoreConfig](http.MethodGet, "/api/v1/config", nil) - cfg.DownloadDir = "./download" - cfg.Extra = map[string]any{ - "serverConfig": &struct { - Host string `json:"host"` - Port int `json:"port"` - }{ - Host: "127.0.0.1", - Port: 8080, - }, - "theme": "dark", - } - httpRequestCheckOk[any](http.MethodPut, "/api/v1/config", cfg) - - newCfg := httpRequestCheckOk[*base.DownloaderStoreConfig](http.MethodGet, "/api/v1/config", nil) - if !test.JsonEqual(cfg, newCfg) { - t.Errorf("GetAndPutConfig() got = %v, want %v", test.ToJson(newCfg), test.ToJson(cfg)) - } - }) -} - -func TestInstallExtension(t *testing.T) { - doTest(func() { - identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) - if identity == "" { - t.Errorf("InstallExtension() got = %v, want %v", identity, "not empty") - } - - // not a valid extension repository - code, _ := httpRequest[string](http.MethodPost, "/api/v1/extensions", &model.InstallExtension{ - URL: "https://github.com/GopeedLab/gopeed", - }) - checkCode(code, model.CodeError) - - // not a git repository - code, _ = httpRequest[string](http.MethodPost, "/api/v1/extensions", &model.InstallExtension{ - URL: "https://github.com", - }) - checkCode(code, model.CodeError) - }) -} - -func TestGetExtensions(t *testing.T) { - doTest(func() { - httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) - extensions := httpRequestCheckOk[[]*download.Extension](http.MethodGet, "/api/v1/extensions", nil) - if len(extensions) == 0 { - t.Errorf("GetExtensions() got = %v, want %v", len(extensions), "not empty") - } - }) -} - -func TestUpdateExtensionSettings(t *testing.T) { - doTest(func() { - identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) - - httpRequestCheckOk[any](http.MethodPut, "/api/v1/extensions/"+identity+"/settings", &model.UpdateExtensionSettings{ - Settings: map[string]any{ - "undefined": "test", - "ua": "test", - }, - }) - - settings := httpRequestCheckOk[*download.Extension](http.MethodGet, "/api/v1/extensions/"+identity, nil).Settings - if len(settings) != 1 { - t.Errorf("UpdateExtensionSettings() got = %v, want %v", len(settings), 1) - } - - if settings[0].Name != "ua" || settings[0].Value != "test" { - t.Errorf("UpdateExtensionSettings() got = %v, want %v", settings[0].Value, "test") - } - }) -} - -func TestSwitchExtension(t *testing.T) { - doTest(func() { - identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) - httpRequestCheckOk[any](http.MethodPut, "/api/v1/extensions/"+identity+"/switch", &model.SwitchExtension{ - Status: false, - }) - extensions := httpRequestCheckOk[[]*download.Extension](http.MethodGet, "/api/v1/extensions", nil) - if !extensions[0].Disabled { - t.Errorf("TestSwitchExtension() got = %v, want %v", extensions[0].Disabled, true) - } - }) -} - -func TestDeleteExtension(t *testing.T) { - doTest(func() { - identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) - httpRequestCheckOk[any](http.MethodDelete, "/api/v1/extensions/"+identity, nil) - extensions := httpRequestCheckOk[[]*download.Extension](http.MethodGet, "/api/v1/extensions", nil) - if len(extensions) != 0 { - t.Errorf("TestDeleteExtension() got = %v, want %v", len(extensions), 0) - } - }) -} - -func TestUpdateCheckExtension(t *testing.T) { - doTest(func() { - identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) - resp := httpRequestCheckOk[*model.UpgradeCheckExtensionResp](http.MethodGet, "/api/v1/extensions/"+identity+"/update", nil) - // no new version - if resp.NewVersion != "" { - t.Errorf("UpgradeCheckExtension() got = %v, want %v", resp.NewVersion, "") - } - // force update - httpRequestCheckOk[any](http.MethodPost, "/api/v1/extensions/"+identity+"/update", nil) - }) -} - -func TestFsExtension(t *testing.T) { - doTest(func() { - identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) - statusCode, _ := doHttpRequest0(http.MethodGet, "/fs/extensions/"+identity+"/icon.png", nil, nil) - if statusCode != http.StatusOK { - t.Errorf("FsExtension() got = %v, want %v", statusCode, http.StatusOK) - } - }) -} - -func TestFsExtensionFail(t *testing.T) { - doTest(func() { - statusCode, _ := doHttpRequest0(http.MethodGet, "/fs/extensions/not_exist/icon.png", nil, nil) - if statusCode != http.StatusNotFound { - t.Errorf("TestFsExtensionFail() got = %v, want %v", statusCode, http.StatusNotFound) - } - }) -} - -func TestDoProxy(t *testing.T) { - doTest(func() { - code, respBody := doHttpRequest0(http.MethodGet, "/api/v1/proxy", map[string]string{ - "X-Target-Uri": "https://github.com/GopeedLab/gopeed/raw/695da7ea87d2b455552b709d3cb4d7879484d4d1/README.md", - }, nil) - if code != http.StatusOK { - t.Errorf("DoProxy() got = %v, want %v", code, http.StatusOK) - } - want := "4ee193b676f1ebb2ad810e016350d52a" - got := fmt.Sprintf("%x", md5.Sum(respBody)) - if got != want { - t.Errorf("DoProxy() got = %v, want %v", got, want) - } - }) - - doTest(func() { - code, _ := doHttpRequest0(http.MethodGet, "/api/v1/proxy", map[string]string{ - "X-Target-Uri": "https://github.com/GopeedLab/gopeed/raw/695da7ea87d2b455552b709d3cb4d7879484d4d1/NOT_FOUND", - }, nil) - if code != http.StatusNotFound { - t.Errorf("DoProxy() got = %v, want %v", code, http.StatusNotFound) - } - }) -} - -func TestApiToken(t *testing.T) { - var cfg = &model.StartConfig{} - cfg.Init() - cfg.ApiToken = "123456" - fileListener := doStart(cfg) - defer func() { - if err := fileListener.Close(); err != nil { - panic(err) - } - Stop() - }() - - status, _ := doHttpRequest0(http.MethodGet, "/api/v1/config", nil, nil) - if status != http.StatusUnauthorized { - t.Errorf("TestApiToken() got = %v, want %v", status, http.StatusUnauthorized) + reqParams[i] = string(bytes) } - status, _ = doHttpRequest0(http.MethodGet, "/api/v1/config", map[string]string{ - "X-Api-Token": cfg.ApiToken, - }, nil) - if status != http.StatusOK { - t.Errorf("TestApiToken() got = %v, want %v", status, http.StatusOK) - } - -} - -func TestAuthorization(t *testing.T) { - var cfg = &model.StartConfig{} - cfg.Init() - cfg.ApiToken = "123456" - cfg.WebEnable = true - cfg.WebBasicAuth = &model.WebBasicAuth{ - Username: "admin", - Password: "123456", - } - fileListener := doStart(cfg) - defer func() { - if err := fileListener.Close(); err != nil { - panic(err) - } - Stop() - }() - - status, _ := doHttpRequest0(http.MethodGet, "/api/v1/config", nil, nil) - if status != http.StatusUnauthorized { - t.Errorf("TestAuthorization() got = %v, want %v", status, http.StatusUnauthorized) - } - - status, _ = doHttpRequest0(http.MethodGet, "/api/v1/config", map[string]string{ - "Authorization": cfg.WebBasicAuth.Authorization(), - }, nil) - if status != http.StatusOK { - t.Errorf("TestAuthorization() got = %v, want %v", status, http.StatusOK) - } - - status, _ = doHttpRequest0(http.MethodGet, "/api/v1/config", map[string]string{ - "X-Api-Token": cfg.ApiToken, - }, nil) - if status != http.StatusOK { - t.Errorf("TestAuthorization() got = %v, want %v", status, http.StatusOK) - } -} - -func doTest(handler func()) { - testFunc := func(storage model.Storage) { - var cfg = &model.StartConfig{} - cfg.Init() - cfg.Storage = storage - cfg.StorageDir = ".test_storage" - cfg.WebEnable = true - fileListener := doStart(cfg) - defer func() { - if err := fileListener.Close(); err != nil { - panic(err) - } - Stop() - Downloader.Clear() - }() - defer func() { - Downloader.Pause(nil) - Downloader.Delete(nil, true) - os.RemoveAll(cfg.StorageDir) - }() - taskReq.URL = "http://" + fileListener.Addr().String() + "/" + test.BuildName - handler() - } - testFunc(model.StorageMem) - testFunc(model.StorageBolt) -} - -func doStart(cfg *model.StartConfig) net.Listener { - port, err := Start(cfg) + result := Invoke(instance, &Request{ + Method: method, + Params: reqParams, + }) + buf, err := json.Marshal(result) if err != nil { - panic(err) - } - restPort = port - return test.StartTestFileServer() -} - -func doHttpRequest0(method string, path string, headers map[string]string, body any) (int, []byte) { - var reader io.Reader - if body != nil { - buf, _ := json.Marshal(body) - reader = bytes.NewBuffer(buf) - } - - request, err := http.NewRequest(method, fmt.Sprintf("http://127.0.0.1:%d%s", restPort, path), reader) - if err != nil { - panic(err) - } - if headers != nil { - for k, v := range headers { - request.Header.Set(k, v) - } - } - response, err := http.DefaultClient.Do(request) - if err != nil { - panic(err) - } - defer response.Body.Close() - respBody, err := io.ReadAll(response.Body) - if err != nil { - panic(err) - } - - return response.StatusCode, respBody -} - -func doHttpRequest[T any](method string, path string, headers map[string]string, body any) (int, *model.Result[T]) { - statusCode, respBody := doHttpRequest0(method, path, headers, body) - if statusCode != http.StatusOK { - panic(fmt.Sprintf("http request failed, status code: %d", statusCode)) - } - - var r model.Result[T] - if err := json.Unmarshal(respBody, &r); err != nil { - panic(err) - } - return int(r.Code), &r -} - -func httpRequest[T any](method string, path string, body any) (int, *model.Result[T]) { - return doHttpRequest[T](method, path, nil, body) -} - -func httpRequestCheckOk[T any](method string, path string, body any) T { - code, result := httpRequest[T](method, path, body) - checkOk(code) - return result.Data -} - -func checkOk(code int) { - checkCode(code, model.CodeOk) -} - -func checkCode(code int, exceptCode model.RespCode) { - if code != int(exceptCode) { - panic(fmt.Sprintf("code got = %d, want %d", code, exceptCode)) + t.Fatal(err) } + + var res model.Result[any] + if err := json.Unmarshal(buf, &res); err != nil { + t.Fatal(err) + } + return &res } diff --git a/pkg/api/api_test.go.bak b/pkg/api/api_test.go.bak new file mode 100644 index 00000000..645a527d --- /dev/null +++ b/pkg/api/api_test.go.bak @@ -0,0 +1,669 @@ +package api + +import ( + "bytes" + "crypto/md5" + "encoding/json" + "errors" + "fmt" + "github.com/GopeedLab/gopeed/internal/test" + "github.com/GopeedLab/gopeed/pkg/api/model" + "github.com/GopeedLab/gopeed/pkg/base" + "github.com/GopeedLab/gopeed/pkg/download" + "io" + "net" + "net/http" + "os" + "reflect" + "sync" + "testing" + "time" +) + +var ( + instance, _ = Create(nil) + restPort int + + taskReq = &base.Request{ + Extra: map[string]any{ + "method": "", + "header": map[string]string{ + "Usr-Agent": "gopeed", + }, + "body": "", + }, + } + taskRes = &base.Resource{ + Size: test.BuildSize, + Range: true, + Files: []*base.FileInfo{ + { + Name: test.BuildName, + Path: "", + Size: test.BuildSize, + }, + }, + } + createOpts = &base.Options{ + Path: test.Dir, + Name: test.DownloadName, + Extra: map[string]any{ + "connections": 2, + }, + } + createReq = &model.CreateTask{ + Req: taskReq, + Opt: createOpts, + } + createResoledReq = &model.CreateTask{ + Req: taskReq, + Opt: createOpts, + } + installExtensionReq = &model.InstallExtension{ + URL: "https://github.com/GopeedLab/gopeed-extension-samples#github-contributor-avatars-sample", + } +) + +func TestInfo(t *testing.T) { + matchKeys := []string{"version", "runtime", "os", "arch", "inDocker"} + doTest(func() { + resp := httpRequestCheckOk[map[string]any](http.MethodGet, "/api/v1/info", nil) + for _, key := range matchKeys { + if _, ok := resp[key]; !ok { + t.Errorf("Info() missing key = %v", key) + } + } + }) +} + +func TestResolve(t *testing.T) { + doTest(func() { + resp := httpRequestCheckOk[*download.ResolveResult](http.MethodPost, "/api/v1/resolve", taskReq) + if !test.AssertResourceEqual(taskRes, resp.Res) { + t.Errorf("Resolve() got = %v, want %v", test.ToJson(resp.Res), test.ToJson(taskRes)) + } + }) +} + +func TestCreateTask(t *testing.T) { + doTest(func() { + resp := httpRequestCheckOk[*download.ResolveResult](http.MethodPost, "/api/v1/resolve", taskReq) + + var wg sync.WaitGroup + wg.Add(1) + Downloader.Listener(func(event *download.Event) { + if event.Key == download.EventKeyFinally { + wg.Done() + } + }) + + taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", &model.CreateTask{ + Rid: resp.ID, + Opt: createOpts, + }) + if taskId == "" { + t.Fatal("create task failed") + } + + wg.Wait() + want := test.FileMd5(test.BuildFile) + got := test.FileMd5(test.DownloadFile) + if want != got { + t.Errorf("CreateTask() got = %v, want %v", got, want) + } + }) +} + +func TestCreateDirectTask(t *testing.T) { + doTest(func() { + var wg sync.WaitGroup + wg.Add(1) + Downloader.Listener(func(event *download.Event) { + if event.Key == download.EventKeyFinally { + wg.Done() + } + }) + + taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) + if taskId == "" { + t.Fatal("create task failed") + } + + wg.Wait() + want := test.FileMd5(test.BuildFile) + got := test.FileMd5(test.DownloadFile) + if want != got { + t.Errorf("CreateDirectTask() got = %v, want %v", got, want) + } + }) +} + +func TestCreateDirectTaskBatch(t *testing.T) { + doTest(func() { + reqs := make([]*base.Request, 0) + for i := 0; i < 5; i++ { + reqs = append(reqs, createReq.Req) + } + taskIds := httpRequestCheckOk[[]string](http.MethodPost, "/api/v1/tasks/batch", &model.CreateTaskBatch{ + Reqs: reqs, + }) + if len(taskIds) != len(reqs) { + t.Errorf("CreateDirectTaskBatch() got = %v, want %v", len(taskIds), len(reqs)) + } + }) +} + +func TestCreateDirectTaskWithResoled(t *testing.T) { + doTest(func() { + var wg sync.WaitGroup + wg.Add(1) + Downloader.Listener(func(event *download.Event) { + if event.Key == download.EventKeyFinally { + wg.Done() + } + }) + + taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createResoledReq) + if taskId == "" { + t.Fatal("create task failed") + } + + wg.Wait() + want := test.FileMd5(test.BuildFile) + got := test.FileMd5(test.DownloadFile) + if want != got { + t.Errorf("CreateDirectTaskWithResoled() got = %v, want %v", got, want) + } + }) +} + +func TestPauseAndContinueTask(t *testing.T) { + doTest(func() { + var wg sync.WaitGroup + wg.Add(1) + Downloader.Listener(func(event *download.Event) { + switch event.Key { + case download.EventKeyFinally: + wg.Done() + } + }) + + taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) + t1 := httpRequestCheckOk[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) + if t1.Status != base.DownloadStatusRunning { + t.Errorf("CreateTask() got = %v, want %v", t1.Status, base.DownloadStatusRunning) + } + httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/"+taskId+"/pause", nil) + t2 := httpRequestCheckOk[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) + if t2.Status != base.DownloadStatusPause { + t.Errorf("PauseTask() got = %v, want %v", t2.Status, base.DownloadStatusPause) + } + httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/"+taskId+"/continue", nil) + t3 := httpRequestCheckOk[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) + if t3.Status != base.DownloadStatusRunning { + t.Errorf("ContinueTask() got = %v, want %v", t3.Status, base.DownloadStatusRunning) + } + + wg.Wait() + want := test.FileMd5(test.BuildFile) + got := test.FileMd5(test.DownloadFile) + if !reflect.DeepEqual(got, want) { + t.Errorf("PauseAndContinueTask() got = %v, want %v", got, want) + } + }) +} + +func TestPauseAllAndContinueALLTasks(t *testing.T) { + doTest(func() { + cfg, err := Downloader.GetConfig() + if err != nil { + t.Fatal(err) + } + + createAndPause := func() { + taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) + httpRequestCheckOk[*download.Task](http.MethodPut, "/api/v1/tasks/"+taskId+"/pause", nil) + } + + total := cfg.MaxRunning + 2 + for i := 0; i < total; i++ { + createAndPause() + } + + // continue all + httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/continue", nil) + time.Sleep(time.Millisecond * 100) + tasks := httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s", base.DownloadStatusRunning), nil) + if len(tasks) != cfg.MaxRunning { + t.Errorf("ContinueAllTasks() got = %v, want %v", len(tasks), cfg.MaxRunning) + } + // pause all + httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/pause", nil) + time.Sleep(time.Millisecond * 100) + tasks = httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s", base.DownloadStatusPause), nil) + if len(tasks) != total { + t.Errorf("PauseAllTasks() got = %v, want %v", len(tasks), total) + } + }) +} + +func TestDeleteTask(t *testing.T) { + doTest(func() { + taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) + time.Sleep(time.Millisecond * 200) + httpRequestCheckOk[any](http.MethodDelete, "/api/v1/tasks/"+taskId, nil) + code, _ := httpRequest[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) + checkCode(code, model.CodeTaskNotFound) + }) +} + +func TestDeleteTaskForce(t *testing.T) { + doTest(func() { + taskId := httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) + time.Sleep(time.Millisecond * 200) + httpRequestCheckOk[any](http.MethodDelete, "/api/v1/tasks/"+taskId+"?force=true", nil) + code, _ := httpRequest[*download.Task](http.MethodGet, "/api/v1/tasks/"+taskId, nil) + checkCode(code, model.CodeTaskNotFound) + if _, err := os.Stat(test.DownloadFile); !errors.Is(err, os.ErrNotExist) { + t.Errorf("DeleteTaskForce() got = %v, want %v", err, os.ErrNotExist) + } + }) +} + +func TestDeleteAllTasks(t *testing.T) { + doTest(func() { + taskCount := 3 + + var wg sync.WaitGroup + wg.Add(taskCount) + Downloader.Listener(func(event *download.Event) { + if event.Key == download.EventKeyFinally { + wg.Done() + } + }) + + for i := 0; i < taskCount; i++ { + httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) + } + + wg.Wait() + + httpRequestCheckOk[any](http.MethodDelete, "/api/v1/tasks?force=true", nil) + tasks := httpRequestCheckOk[[]*download.Task](http.MethodGet, "/api/v1/tasks", nil) + if len(tasks) != 0 { + t.Errorf("DeleteTasks() got = %v, want %v", len(tasks), 0) + } + }) +} + +func TestDeleteTasksByStatues(t *testing.T) { + doTest(func() { + taskCount := 3 + + var wg sync.WaitGroup + wg.Add(taskCount) + Downloader.Listener(func(event *download.Event) { + if event.Key == download.EventKeyFinally { + wg.Done() + } + }) + + for i := 0; i < taskCount; i++ { + httpRequestCheckOk[string](http.MethodPost, "/api/v1/tasks", createReq) + } + + wg.Wait() + + httpRequestCheckOk[any](http.MethodDelete, fmt.Sprintf("/api/v1/tasks?status=%s&force=true", base.DownloadStatusDone), nil) + tasks := httpRequestCheckOk[[]*download.Task](http.MethodGet, "/api/v1/tasks", nil) + if len(tasks) != 0 { + t.Errorf("DeleteTasks() got = %v, want %v", len(tasks), 0) + } + }) +} + +func TestGetTasks(t *testing.T) { + doTest(func() { + var wg sync.WaitGroup + wg.Add(1) + Downloader.Listener(func(event *download.Event) { + if event.Key == download.EventKeyFinally { + wg.Done() + } + }) + + httpRequestCheckOk[string](http.MethodPost, fmt.Sprintf("/api/v1/tasks?status=%s&status=%s", + base.DownloadStatusReady, base.DownloadStatusRunning), createReq) + httpRequestCheckOk[[]*download.Task](http.MethodGet, "/api/v1/tasks", nil) + + wg.Wait() + r := httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s", + base.DownloadStatusDone), nil) + if r[0].Status != base.DownloadStatusDone { + t.Errorf("GetTasks() got = %v, want %v", r[0].Status, base.DownloadStatusDone) + } + r = httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s,%s", + base.DownloadStatusReady, base.DownloadStatusRunning), nil) + if len(r) > 0 { + t.Errorf("GetTasks() got = %v, want %v", len(r), 0) + } + }) +} + +func TestGetAndPutConfig(t *testing.T) { + doTest(func() { + cfg := httpRequestCheckOk[*base.DownloaderStoreConfig](http.MethodGet, "/api/v1/config", nil) + cfg.DownloadDir = "./download" + cfg.Extra = map[string]any{ + "serverConfig": &struct { + Host string `json:"host"` + Port int `json:"port"` + }{ + Host: "127.0.0.1", + Port: 8080, + }, + "theme": "dark", + } + httpRequestCheckOk[any](http.MethodPut, "/api/v1/config", cfg) + + newCfg := httpRequestCheckOk[*base.DownloaderStoreConfig](http.MethodGet, "/api/v1/config", nil) + if !test.JsonEqual(cfg, newCfg) { + t.Errorf("GetAndPutConfig() got = %v, want %v", test.ToJson(newCfg), test.ToJson(cfg)) + } + }) +} + +func TestInstallExtension(t *testing.T) { + doTest(func() { + identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) + if identity == "" { + t.Errorf("InstallExtension() got = %v, want %v", identity, "not empty") + } + + // not a valid extension repository + code, _ := httpRequest[string](http.MethodPost, "/api/v1/extensions", &model.InstallExtension{ + URL: "https://github.com/GopeedLab/gopeed", + }) + checkCode(code, model.CodeError) + + // not a git repository + code, _ = httpRequest[string](http.MethodPost, "/api/v1/extensions", &model.InstallExtension{ + URL: "https://github.com", + }) + checkCode(code, model.CodeError) + }) +} + +func TestGetExtensions(t *testing.T) { + doTest(func() { + httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) + extensions := httpRequestCheckOk[[]*download.Extension](http.MethodGet, "/api/v1/extensions", nil) + if len(extensions) == 0 { + t.Errorf("GetExtensions() got = %v, want %v", len(extensions), "not empty") + } + }) +} + +func TestUpdateExtensionSettings(t *testing.T) { + doTest(func() { + identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) + + httpRequestCheckOk[any](http.MethodPut, "/api/v1/extensions/"+identity+"/settings", &model.UpdateExtensionSettings{ + Settings: map[string]any{ + "undefined": "test", + "ua": "test", + }, + }) + + settings := httpRequestCheckOk[*download.Extension](http.MethodGet, "/api/v1/extensions/"+identity, nil).Settings + if len(settings) != 1 { + t.Errorf("UpdateExtensionSettings() got = %v, want %v", len(settings), 1) + } + + if settings[0].Name != "ua" || settings[0].Value != "test" { + t.Errorf("UpdateExtensionSettings() got = %v, want %v", settings[0].Value, "test") + } + }) +} + +func TestSwitchExtension(t *testing.T) { + doTest(func() { + identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) + httpRequestCheckOk[any](http.MethodPut, "/api/v1/extensions/"+identity+"/switch", &model.SwitchExtension{ + Status: false, + }) + extensions := httpRequestCheckOk[[]*download.Extension](http.MethodGet, "/api/v1/extensions", nil) + if !extensions[0].Disabled { + t.Errorf("TestSwitchExtension() got = %v, want %v", extensions[0].Disabled, true) + } + }) +} + +func TestDeleteExtension(t *testing.T) { + doTest(func() { + identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) + httpRequestCheckOk[any](http.MethodDelete, "/api/v1/extensions/"+identity, nil) + extensions := httpRequestCheckOk[[]*download.Extension](http.MethodGet, "/api/v1/extensions", nil) + if len(extensions) != 0 { + t.Errorf("TestDeleteExtension() got = %v, want %v", len(extensions), 0) + } + }) +} + +func TestUpdateCheckExtension(t *testing.T) { + doTest(func() { + identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) + resp := httpRequestCheckOk[*model.UpgradeCheckExtensionResp](http.MethodGet, "/api/v1/extensions/"+identity+"/update", nil) + // no new version + if resp.NewVersion != "" { + t.Errorf("UpgradeCheckExtension() got = %v, want %v", resp.NewVersion, "") + } + // force update + httpRequestCheckOk[any](http.MethodPost, "/api/v1/extensions/"+identity+"/update", nil) + }) +} + +func TestFsExtension(t *testing.T) { + doTest(func() { + identity := httpRequestCheckOk[string](http.MethodPost, "/api/v1/extensions", installExtensionReq) + statusCode, _ := doHttpRequest0(http.MethodGet, "/fs/extensions/"+identity+"/icon.png", nil, nil) + if statusCode != http.StatusOK { + t.Errorf("FsExtension() got = %v, want %v", statusCode, http.StatusOK) + } + }) +} + +func TestFsExtensionFail(t *testing.T) { + doTest(func() { + statusCode, _ := doHttpRequest0(http.MethodGet, "/fs/extensions/not_exist/icon.png", nil, nil) + if statusCode != http.StatusNotFound { + t.Errorf("TestFsExtensionFail() got = %v, want %v", statusCode, http.StatusNotFound) + } + }) +} + +func TestDoProxy(t *testing.T) { + doTest(func() { + code, respBody := doHttpRequest0(http.MethodGet, "/api/v1/proxy", map[string]string{ + "X-Target-Uri": "https://github.com/GopeedLab/gopeed/raw/695da7ea87d2b455552b709d3cb4d7879484d4d1/README.md", + }, nil) + if code != http.StatusOK { + t.Errorf("DoProxy() got = %v, want %v", code, http.StatusOK) + } + want := "4ee193b676f1ebb2ad810e016350d52a" + got := fmt.Sprintf("%x", md5.Sum(respBody)) + if got != want { + t.Errorf("DoProxy() got = %v, want %v", got, want) + } + }) + + doTest(func() { + code, _ := doHttpRequest0(http.MethodGet, "/api/v1/proxy", map[string]string{ + "X-Target-Uri": "https://github.com/GopeedLab/gopeed/raw/695da7ea87d2b455552b709d3cb4d7879484d4d1/NOT_FOUND", + }, nil) + if code != http.StatusNotFound { + t.Errorf("DoProxy() got = %v, want %v", code, http.StatusNotFound) + } + }) +} + +func TestApiToken(t *testing.T) { + var cfg = &model.StartConfig{} + cfg.Init() + cfg.ApiToken = "123456" + fileListener := doStart(cfg) + defer func() { + if err := fileListener.Close(); err != nil { + panic(err) + } + Stop() + }() + + status, _ := doHttpRequest0(http.MethodGet, "/api/v1/config", nil, nil) + if status != http.StatusUnauthorized { + t.Errorf("TestApiToken() got = %v, want %v", status, http.StatusUnauthorized) + } + + status, _ = doHttpRequest0(http.MethodGet, "/api/v1/config", map[string]string{ + "X-Api-Token": cfg.ApiToken, + }, nil) + if status != http.StatusOK { + t.Errorf("TestApiToken() got = %v, want %v", status, http.StatusOK) + } + +} + +func TestAuthorization(t *testing.T) { + var cfg = &model.StartConfig{} + cfg.Init() + cfg.ApiToken = "123456" + cfg.WebEnable = true + cfg.WebBasicAuth = &model.WebBasicAuth{ + Username: "admin", + Password: "123456", + } + fileListener := doStart(cfg) + defer func() { + if err := fileListener.Close(); err != nil { + panic(err) + } + Stop() + }() + + status, _ := doHttpRequest0(http.MethodGet, "/api/v1/config", nil, nil) + if status != http.StatusUnauthorized { + t.Errorf("TestAuthorization() got = %v, want %v", status, http.StatusUnauthorized) + } + + status, _ = doHttpRequest0(http.MethodGet, "/api/v1/config", map[string]string{ + "Authorization": cfg.WebBasicAuth.Authorization(), + }, nil) + if status != http.StatusOK { + t.Errorf("TestAuthorization() got = %v, want %v", status, http.StatusOK) + } + + status, _ = doHttpRequest0(http.MethodGet, "/api/v1/config", map[string]string{ + "X-Api-Token": cfg.ApiToken, + }, nil) + if status != http.StatusOK { + t.Errorf("TestAuthorization() got = %v, want %v", status, http.StatusOK) + } +} + +func doTest(handler func()) { + testFunc := func(storage model.Storage) { + var cfg = &model.StartConfig{} + cfg.Init() + cfg.Storage = storage + cfg.StorageDir = ".test_storage" + cfg.WebEnable = true + fileListener := doStart(cfg) + defer func() { + if err := fileListener.Close(); err != nil { + panic(err) + } + Stop() + Downloader.Clear() + }() + defer func() { + Downloader.Pause(nil) + Downloader.Delete(nil, true) + os.RemoveAll(cfg.StorageDir) + }() + taskReq.URL = "http://" + fileListener.Addr().String() + "/" + test.BuildName + handler() + } + testFunc(model.StorageMem) + testFunc(model.StorageBolt) +} + +func doStart(cfg *model.StartConfig) net.Listener { + port, err := Start(cfg) + if err != nil { + panic(err) + } + restPort = port + return test.StartTestFileServer() +} + +func doHttpRequest0(method string, path string, headers map[string]string, body any) (int, []byte) { + var reader io.Reader + if body != nil { + buf, _ := json.Marshal(body) + reader = bytes.NewBuffer(buf) + } + + request, err := http.NewRequest(method, fmt.Sprintf("http://127.0.0.1:%d%s", restPort, path), reader) + if err != nil { + panic(err) + } + if headers != nil { + for k, v := range headers { + request.Header.Set(k, v) + } + } + response, err := http.DefaultClient.Do(request) + if err != nil { + panic(err) + } + defer response.Body.Close() + respBody, err := io.ReadAll(response.Body) + if err != nil { + panic(err) + } + + return response.StatusCode, respBody +} + +func doHttpRequest[T any](method string, path string, headers map[string]string, body any) (int, *model.Result[T]) { + statusCode, respBody := doHttpRequest0(method, path, headers, body) + if statusCode != http.StatusOK { + panic(fmt.Sprintf("http request failed, status code: %d", statusCode)) + } + + var r model.Result[T] + if err := json.Unmarshal(respBody, &r); err != nil { + panic(err) + } + return int(r.Code), &r +} + +func httpRequest[T any](method string, path string, body any) (int, *model.Result[T]) { + return doHttpRequest[T](method, path, nil, body) +} + +func httpRequestCheckOk[T any](method string, path string, body any) T { + code, result := httpRequest[T](method, path, body) + checkOk(code) + return result.Data +} + +func checkOk(code int) { + checkCode(code, model.CodeOk) +} + +func checkCode(code int, exceptCode model.RespCode) { + if code != int(exceptCode) { + panic(fmt.Sprintf("code got = %d, want %d", code, exceptCode)) + } +} diff --git a/pkg/api/http.go b/pkg/api/http.go index 8fc888a9..373c938f 100644 --- a/pkg/api/http.go +++ b/pkg/api/http.go @@ -22,7 +22,7 @@ import ( const instanceKey string = "apiInstance" -func ListenHttp(httpCfg *base.DownloaderHttpConfig, ai *Instance) (*model.HttpListenResult, func(), error) { +func ListenHttp(httpCfg *base.DownloaderHttpConfig, ai *Instance) (int, func(), error) { var r = mux.NewRouter() r.Methods(http.MethodGet).Path("/api/v1/info").HandlerFunc(Info) r.Methods(http.MethodPost).Path("/api/v1/resolve").HandlerFunc(Resolve) @@ -106,19 +106,16 @@ func ListenHttp(httpCfg *base.DownloaderHttpConfig, ai *Instance) (*model.HttpLi listener, err := net.Listen("tcp", net.JoinHostPort(httpCfg.Host, fmt.Sprintf("%d", httpCfg.Port))) if err != nil { - return nil, nil, err + return 0, nil, err } ai.srv = srv ai.listener = listener - return &model.HttpListenResult{ - Host: httpCfg.Host, - Port: listener.Addr().(*net.TCPAddr).Port, - }, func() { - if err := srv.Serve(listener); err != nil && !errors.Is(err, http.ErrServerClosed) { - ai.downloader.Logger.Error().Err(err).Msg("http server listen error") - } - }, nil + return listener.Addr().(*net.TCPAddr).Port, func() { + if err := srv.Serve(listener); err != nil && !errors.Is(err, http.ErrServerClosed) { + ai.downloader.Logger.Error().Err(err).Msg("http server listen error") + } + }, nil } func getInstance(r *http.Request) *Instance { diff --git a/pkg/base/model.go b/pkg/base/model.go index ca935ecd..fd46cfae 100644 --- a/pkg/base/model.go +++ b/pkg/base/model.go @@ -228,6 +228,8 @@ type DownloaderHttpConfig struct { Port int `json:"port"` // ApiToken is the auth token for http API ApiToken string `json:"apiToken"` + // RunningPort is the http server real listen port. + RunningPort int `json:"runningPort"` } type DownloaderProxyConfig struct { diff --git a/ui/flutter/include/libgopeed.h b/ui/flutter/include/libgopeed.h index 1af88c08..85fdf8d0 100644 --- a/ui/flutter/include/libgopeed.h +++ b/ui/flutter/include/libgopeed.h @@ -2,6 +2,7 @@ /* package github.com/GopeedLab/gopeed/bind/desktop */ + #line 1 "cgo-builtin-export-prolog" #include @@ -10,24 +11,19 @@ #define GO_CGO_EXPORT_PROLOGUE_H #ifndef GO_CGO_GOSTRING_TYPEDEF -typedef struct { - const char *p; - ptrdiff_t n; -} _GoString_; +typedef struct { const char *p; ptrdiff_t n; } _GoString_; #endif #endif /* Start of preamble from import "C" comments. */ -#line 3 "main.go" -#include -#line 1 "cgo-generated-wrapper" /* End of preamble from import "C" comments. */ + /* Start of boilerplate cgo prologue. */ #line 1 "cgo-gcc-export-header-prolog" @@ -60,22 +56,15 @@ typedef double _Complex GoComplex128; static assertion to make sure the file is being used on architecture at least with matching size of GoInt. */ -typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void *) == 64 / 8 ? 1 : -1]; +typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; #ifndef GO_CGO_GOSTRING_TYPEDEF typedef _GoString_ GoString; #endif typedef void *GoMap; typedef void *GoChan; -typedef struct { - void *t; - void *v; -} GoInterface; -typedef struct { - void *data; - GoInt len; - GoInt cap; -} GoSlice; +typedef struct { void *t; void *v; } GoInterface; +typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; #endif @@ -85,8 +74,8 @@ typedef struct { extern "C" { #endif -extern __declspec(dllexport) char *Create(char *cfg); -extern __declspec(dllexport) char *Invoke(GoInt index, char *req); +extern __declspec(dllexport) char* Init(char* cfg); +extern __declspec(dllexport) char* Invoke(char* req); #ifdef __cplusplus } diff --git a/ui/flutter/lib/api/entry/libgopeed_boot_native.dart b/ui/flutter/lib/api/entry/libgopeed_boot_native.dart index 257013f8..dd42d3cd 100644 --- a/ui/flutter/lib/api/entry/libgopeed_boot_native.dart +++ b/ui/flutter/lib/api/entry/libgopeed_boot_native.dart @@ -33,9 +33,10 @@ import 'libgopeed_boot_base.dart'; LibgopeedBoot create() => LibgopeedBootNative(); -class LibgopeedBootNative with LibgopeedBootBase implements LibgopeedBoot { +class LibgopeedBootNative + with LibgopeedBootBase + implements LibgopeedBoot, LibgopeedApi { late LibgopeedAbi _libgopeedAbi; - late int _apiInstance; late Dio _dio; LibgopeedBootNative() { @@ -69,8 +70,7 @@ class LibgopeedBootNative with LibgopeedBootBase implements LibgopeedBoot { } return jsonEncode(e); }).toList()); - final resp = - await _libgopeedAbi.invoke(_apiInstance, jsonEncode(invokeRequest)); + final resp = await _libgopeedAbi.invoke(jsonEncode(invokeRequest)); final result = Result.fromJson(jsonDecode(resp), fromJsonT ??= (json) => null as T); return handleResult(result); @@ -78,87 +78,86 @@ class LibgopeedBootNative with LibgopeedBootBase implements LibgopeedBoot { List _parseTaskFilter(TaskFilter? filter) { if (filter == null) { - return []; + return [null]; } return [filter]; } @override - Future init(StartConfig cfg) async { - final result = await _libgopeedAbi.create(jsonEncode(cfg.toJson())); - _apiInstance = - Result.fromJson(jsonDecode(result), (data) => data as int).data!; + Future init(StartConfig cfg) async { + await _libgopeedAbi.init(jsonEncode(cfg.toJson())); _dio = createDio(); + return this; } @override Future startHttp() async { return _invoke( - "startHttp", [], (json) => HttpListenResult.fromJson(json)); + "StartHttp", [], (json) => HttpListenResult.fromJson(json)); } @override Future stopHttp() async { - await _invoke("stopHttp", [], null); + await _invoke("StopHttp", [], null); } @override Future restartHttp() async { - await _invoke("restartHttp", [], null); + await _invoke("RestartHttp", [], null); } @override Future info() async { - return _invoke("info", [], (json) => Info.fromJson(json)); + return _invoke("Info", [], (json) => Info.fromJson(json)); } @override Future resolve(Request request) async { return _invoke( - "resolve", [request], (json) => ResolveResult.fromJson(json)); + "Resolve", [request], (json) => ResolveResult.fromJson(json)); } @override Future createTask(CreateTask createTask) async { return _invoke( - "createTask", [createTask], (json) => json as String); + "CreateTask", [createTask], (json) => json as String); } @override Future createTaskBatch(CreateTaskBatch createTask) async { return _invoke( - "createTaskBatch", [createTask], (json) => json as String); + "CreateTaskBatch", [createTask], (json) => json as String); } @override Future pauseTask(String id) async { - await _invoke("pauseTask", [id], null); + await _invoke("PauseTask", [id], null); } @override Future pauseTasks(TaskFilter? filter) async { - await _invoke("pauseTasks", _parseTaskFilter(filter), null); + await _invoke("PauseTasks", _parseTaskFilter(filter), null); } @override Future continueTask(String id) async { - await _invoke("continueTask", [id], null); + await _invoke("ContinueTask", [id], null); } @override Future continueTasks(TaskFilter? filter) async { - await _invoke("continueTasks", _parseTaskFilter(filter), null); + await _invoke("ContinueTasks", _parseTaskFilter(filter), null); } @override Future deleteTask(String id, bool force) async { - await _invoke("deleteTask", [id, force], null); + await _invoke("DeleteTask", [id, force], null); } @override Future deleteTasks(TaskFilter? filter, bool force) async { await _invoke( - "deleteTasks", + "DeleteTasks", _parseTaskFilter(filter).apply((it) { it.add(force); }), @@ -167,40 +166,40 @@ class LibgopeedBootNative with LibgopeedBootBase implements LibgopeedBoot { @override Future getTask(String id) async { - return _invoke("getTask", [id], (json) => Task.fromJson(json)); + return _invoke("GetTask", [id], (json) => Task.fromJson(json)); } @override Future> getTasks(TaskFilter? filter) async { - return _invoke>("getTasks", _parseTaskFilter(filter), + return _invoke>("GetTasks", _parseTaskFilter(filter), (json) => json.map((e) => Task.fromJson(e)).toList()); } @override Future> getTaskStats(String id) async { return _invoke>( - "getTaskStats", [id], (json) => json as Map); + "GetTaskStats", [id], (json) => json as Map); } @override Future getConfig() async { return _invoke( - "getConfig", [], (json) => DownloaderConfig.fromJson(json)); + "GetConfig", [], (json) => DownloaderConfig.fromJson(json)); } @override Future putConfig(DownloaderConfig config) async { - await _invoke("putConfig", [config], null); + await _invoke("PutConfig", [config], null); } @override Future installExtension(InstallExtension installExtension) async { - await _invoke("installExtension", [installExtension], null); + await _invoke("InstallExtension", [installExtension], null); } @override Future> getExtensions() async { - return _invoke>("getExtensions", [], + return _invoke>("GetExtensions", [], (json) => json.map((e) => Extension.fromJson(e)).toList()); } @@ -208,33 +207,35 @@ class LibgopeedBootNative with LibgopeedBootBase implements LibgopeedBoot { Future updateExtensionSettings( String identity, UpdateExtensionSettings updateExtensionSettings) async { await _invoke( - "updateExtensionSettings", [identity, updateExtensionSettings], null); + "UpdateExtensionSettings", [identity, updateExtensionSettings], null); } @override Future switchExtension( - String identity, SwitchExtension switchExtension) async {} + String identity, SwitchExtension switchExtension) async { + await _invoke("SwitchExtension", [identity, switchExtension], null); + } @override Future deleteExtension(String identity) async { - await _invoke("deleteExtension", [identity], null); + await _invoke("DeleteExtension", [identity], null); } @override Future upgradeCheckExtension( String identity) async { - return _invoke("upgradeCheckExtension", + return _invoke("UpgradeCheckExtension", [identity], (json) => UpdateCheckExtensionResp.fromJson(json)); } @override Future upgradeExtension(String identity) async { - await _invoke("upgradeExtension", [identity], null); + await _invoke("UpgradeExtension", [identity], null); } @override Future close() async { - await _invoke("close", [], null); + await _invoke("Close", [], null); } @override diff --git a/ui/flutter/lib/api/entry/libgopeed_boot_web.dart b/ui/flutter/lib/api/entry/libgopeed_boot_web.dart index 4c739556..29e9d166 100644 --- a/ui/flutter/lib/api/entry/libgopeed_boot_web.dart +++ b/ui/flutter/lib/api/entry/libgopeed_boot_web.dart @@ -20,12 +20,15 @@ import '../../util/extensions.dart'; import '../../util/util.dart'; import '../api_exception.dart'; import '../libgopeed_boot.dart'; +import '../native/libgopeed_interface.dart'; import '../native/model/start_config.dart'; import 'libgopeed_boot_base.dart'; LibgopeedBoot create() => LibgopeedBootWeb(); -class LibgopeedBootWeb with LibgopeedBootBase implements LibgopeedBoot { +class LibgopeedBootWeb + with LibgopeedBootBase + implements LibgopeedBoot, LibgopeedApi { late Dio _dio; static const String _apiPrefix = '/api/v1'; @@ -72,9 +75,10 @@ class LibgopeedBootWeb with LibgopeedBootBase implements LibgopeedBoot { } @override - Future init(StartConfig cfg) async { + Future init(StartConfig cfg) async { _dio = createDio(); _dio.options.baseUrl = kDebugMode ? 'http://127.0.0.1:9999' : ''; + return this; } @override diff --git a/ui/flutter/lib/api/libgopeed_boot.dart b/ui/flutter/lib/api/libgopeed_boot.dart index a3d82588..d000c7ba 100644 --- a/ui/flutter/lib/api/libgopeed_boot.dart +++ b/ui/flutter/lib/api/libgopeed_boot.dart @@ -3,11 +3,14 @@ import "libgopeed_boot_stub.dart" if (dart.library.io) 'entry/libgopeed_boot_native.dart'; import 'native/libgopeed_interface.dart'; -abstract class LibgopeedBoot implements LibgopeedApi { - static LibgopeedBoot? _instance; +abstract class LibgopeedBoot implements LibgopeedApiSingleton { + static LibgopeedApi? _instance; - static LibgopeedBoot get instance { - _instance ??= LibgopeedBoot(); + static void singleton(LibgopeedApi instance) { + _instance ??= instance; + } + + static LibgopeedApi get instance { return _instance!; } diff --git a/ui/flutter/lib/api/native/channel/libgopeed_channel.dart b/ui/flutter/lib/api/native/channel/libgopeed_channel.dart index 6c958c10..934fd3e2 100644 --- a/ui/flutter/lib/api/native/channel/libgopeed_channel.dart +++ b/ui/flutter/lib/api/native/channel/libgopeed_channel.dart @@ -6,17 +6,15 @@ class LibgopeedChannel implements LibgopeedAbi { static const _channel = MethodChannel('gopeed.com/libgopeed'); @override - Future create(String cfg) async { - final result = await _channel.invokeMethod('create', { + Future init(String cfg) async { + await _channel.invokeMethod('init', { 'cfg': cfg, }); - return result!; } @override - Future invoke(int instance, String params) async { + Future invoke(String params) async { final result = await _channel.invokeMethod('invoke', { - 'instance': instance, 'params': params, }); return result!; diff --git a/ui/flutter/lib/api/native/ffi/libgopeed_bind.dart b/ui/flutter/lib/api/native/ffi/libgopeed_bind.dart index 0002e15a..4ed93a94 100644 --- a/ui/flutter/lib/api/native/ffi/libgopeed_bind.dart +++ b/ui/flutter/lib/api/native/ffi/libgopeed_bind.dart @@ -177,4295 +177,6 @@ class LibgopeedBind { _lookup>('__threadhandle'); late final ___threadhandle = ___threadhandlePtr.asFunction(); - ffi.Pointer _calloc_base( - int _Count, - int _Size, - ) { - return __calloc_base( - _Count, - _Size, - ); - } - - late final __calloc_basePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Size, ffi.Size)>>('_calloc_base'); - late final __calloc_base = - __calloc_basePtr.asFunction Function(int, int)>(); - - ffi.Pointer calloc( - int _Count, - int _Size, - ) { - return _calloc( - _Count, - _Size, - ); - } - - late final _callocPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Size, ffi.Size)>>('calloc'); - late final _calloc = - _callocPtr.asFunction Function(int, int)>(); - - int _callnewh( - int _Size, - ) { - return __callnewh( - _Size, - ); - } - - late final __callnewhPtr = - _lookup>('_callnewh'); - late final __callnewh = __callnewhPtr.asFunction(); - - ffi.Pointer _expand( - ffi.Pointer _Block, - int _Size, - ) { - return __expand( - _Block, - _Size, - ); - } - - late final __expandPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Size)>>('_expand'); - late final __expand = __expandPtr - .asFunction Function(ffi.Pointer, int)>(); - - void _free_base( - ffi.Pointer _Block, - ) { - return __free_base( - _Block, - ); - } - - late final __free_basePtr = - _lookup)>>( - '_free_base'); - late final __free_base = - __free_basePtr.asFunction)>(); - - void free( - ffi.Pointer _Block, - ) { - return _free( - _Block, - ); - } - - late final _freePtr = - _lookup)>>( - 'free'); - late final _free = - _freePtr.asFunction)>(); - - ffi.Pointer _malloc_base( - int _Size, - ) { - return __malloc_base( - _Size, - ); - } - - late final __malloc_basePtr = - _lookup Function(ffi.Size)>>( - '_malloc_base'); - late final __malloc_base = - __malloc_basePtr.asFunction Function(int)>(); - - ffi.Pointer malloc( - int _Size, - ) { - return _malloc( - _Size, - ); - } - - late final _mallocPtr = - _lookup Function(ffi.Size)>>( - 'malloc'); - late final _malloc = - _mallocPtr.asFunction Function(int)>(); - - int _msize_base( - ffi.Pointer _Block, - ) { - return __msize_base( - _Block, - ); - } - - late final __msize_basePtr = - _lookup)>>( - '_msize_base'); - late final __msize_base = - __msize_basePtr.asFunction)>(); - - int _msize( - ffi.Pointer _Block, - ) { - return __msize( - _Block, - ); - } - - late final __msizePtr = - _lookup)>>( - '_msize'); - late final __msize = - __msizePtr.asFunction)>(); - - ffi.Pointer _realloc_base( - ffi.Pointer _Block, - int _Size, - ) { - return __realloc_base( - _Block, - _Size, - ); - } - - late final __realloc_basePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Size)>>('_realloc_base'); - late final __realloc_base = __realloc_basePtr - .asFunction Function(ffi.Pointer, int)>(); - - ffi.Pointer realloc( - ffi.Pointer _Block, - int _Size, - ) { - return _realloc( - _Block, - _Size, - ); - } - - late final _reallocPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Size)>>('realloc'); - late final _realloc = _reallocPtr - .asFunction Function(ffi.Pointer, int)>(); - - ffi.Pointer _recalloc_base( - ffi.Pointer _Block, - int _Count, - int _Size, - ) { - return __recalloc_base( - _Block, - _Count, - _Size, - ); - } - - late final __recalloc_basePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Size, ffi.Size)>>('_recalloc_base'); - late final __recalloc_base = __recalloc_basePtr.asFunction< - ffi.Pointer Function(ffi.Pointer, int, int)>(); - - ffi.Pointer _recalloc( - ffi.Pointer _Block, - int _Count, - int _Size, - ) { - return __recalloc( - _Block, - _Count, - _Size, - ); - } - - late final __recallocPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Size, ffi.Size)>>('_recalloc'); - late final __recalloc = __recallocPtr.asFunction< - ffi.Pointer Function(ffi.Pointer, int, int)>(); - - void _aligned_free( - ffi.Pointer _Block, - ) { - return __aligned_free( - _Block, - ); - } - - late final __aligned_freePtr = - _lookup)>>( - '_aligned_free'); - late final __aligned_free = - __aligned_freePtr.asFunction)>(); - - ffi.Pointer _aligned_malloc( - int _Size, - int _Alignment, - ) { - return __aligned_malloc( - _Size, - _Alignment, - ); - } - - late final __aligned_mallocPtr = _lookup< - ffi - .NativeFunction Function(ffi.Size, ffi.Size)>>( - '_aligned_malloc'); - late final __aligned_malloc = __aligned_mallocPtr - .asFunction Function(int, int)>(); - - ffi.Pointer _aligned_offset_malloc( - int _Size, - int _Alignment, - int _Offset, - ) { - return __aligned_offset_malloc( - _Size, - _Alignment, - _Offset, - ); - } - - late final __aligned_offset_mallocPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Size, ffi.Size, ffi.Size)>>('_aligned_offset_malloc'); - late final __aligned_offset_malloc = __aligned_offset_mallocPtr - .asFunction Function(int, int, int)>(); - - int _aligned_msize( - ffi.Pointer _Block, - int _Alignment, - int _Offset, - ) { - return __aligned_msize( - _Block, - _Alignment, - _Offset, - ); - } - - late final __aligned_msizePtr = _lookup< - ffi.NativeFunction< - ffi.Size Function( - ffi.Pointer, ffi.Size, ffi.Size)>>('_aligned_msize'); - late final __aligned_msize = __aligned_msizePtr - .asFunction, int, int)>(); - - ffi.Pointer _aligned_offset_realloc( - ffi.Pointer _Block, - int _Size, - int _Alignment, - int _Offset, - ) { - return __aligned_offset_realloc( - _Block, - _Size, - _Alignment, - _Offset, - ); - } - - late final __aligned_offset_reallocPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer, ffi.Size, - ffi.Size, ffi.Size)>>('_aligned_offset_realloc'); - late final __aligned_offset_realloc = __aligned_offset_reallocPtr.asFunction< - ffi.Pointer Function(ffi.Pointer, int, int, int)>(); - - ffi.Pointer _aligned_offset_recalloc( - ffi.Pointer _Block, - int _Count, - int _Size, - int _Alignment, - int _Offset, - ) { - return __aligned_offset_recalloc( - _Block, - _Count, - _Size, - _Alignment, - _Offset, - ); - } - - late final __aligned_offset_recallocPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer, ffi.Size, - ffi.Size, ffi.Size, ffi.Size)>>('_aligned_offset_recalloc'); - late final __aligned_offset_recalloc = - __aligned_offset_recallocPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, int, int, int, int)>(); - - ffi.Pointer _aligned_realloc( - ffi.Pointer _Block, - int _Size, - int _Alignment, - ) { - return __aligned_realloc( - _Block, - _Size, - _Alignment, - ); - } - - late final __aligned_reallocPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Size, ffi.Size)>>('_aligned_realloc'); - late final __aligned_realloc = __aligned_reallocPtr.asFunction< - ffi.Pointer Function(ffi.Pointer, int, int)>(); - - ffi.Pointer _aligned_recalloc( - ffi.Pointer _Block, - int _Count, - int _Size, - int _Alignment, - ) { - return __aligned_recalloc( - _Block, - _Count, - _Size, - _Alignment, - ); - } - - late final __aligned_recallocPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer, ffi.Size, - ffi.Size, ffi.Size)>>('_aligned_recalloc'); - late final __aligned_recalloc = __aligned_recallocPtr.asFunction< - ffi.Pointer Function(ffi.Pointer, int, int, int)>(); - - ffi.Pointer bsearch_s( - ffi.Pointer _Key, - ffi.Pointer _Base, - int _NumOfElements, - int _SizeOfElements, - _CoreCrtSecureSearchSortCompareFunction _CompareFunction, - ffi.Pointer _Context, - ) { - return _bsearch_s( - _Key, - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - _Context, - ); - } - - late final _bsearch_sPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - rsize_t, - rsize_t, - _CoreCrtSecureSearchSortCompareFunction, - ffi.Pointer)>>('bsearch_s'); - late final _bsearch_s = _bsearch_sPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - int, - int, - _CoreCrtSecureSearchSortCompareFunction, - ffi.Pointer)>(); - - void qsort_s( - ffi.Pointer _Base, - int _NumOfElements, - int _SizeOfElements, - _CoreCrtSecureSearchSortCompareFunction _CompareFunction, - ffi.Pointer _Context, - ) { - return _qsort_s( - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - _Context, - ); - } - - late final _qsort_sPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - rsize_t, - rsize_t, - _CoreCrtSecureSearchSortCompareFunction, - ffi.Pointer)>>('qsort_s'); - late final _qsort_s = _qsort_sPtr.asFunction< - void Function(ffi.Pointer, int, int, - _CoreCrtSecureSearchSortCompareFunction, ffi.Pointer)>(); - - ffi.Pointer bsearch( - ffi.Pointer _Key, - ffi.Pointer _Base, - int _NumOfElements, - int _SizeOfElements, - _CoreCrtNonSecureSearchSortCompareFunction _CompareFunction, - ) { - return _bsearch( - _Key, - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - ); - } - - late final _bsearchPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Size, - ffi.Size, - _CoreCrtNonSecureSearchSortCompareFunction)>>('bsearch'); - late final _bsearch = _bsearchPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - int, - int, - _CoreCrtNonSecureSearchSortCompareFunction)>(); - - void qsort( - ffi.Pointer _Base, - int _NumOfElements, - int _SizeOfElements, - _CoreCrtNonSecureSearchSortCompareFunction _CompareFunction, - ) { - return _qsort( - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - ); - } - - late final _qsortPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer, ffi.Size, ffi.Size, - _CoreCrtNonSecureSearchSortCompareFunction)>>('qsort'); - late final _qsort = _qsortPtr.asFunction< - void Function(ffi.Pointer, int, int, - _CoreCrtNonSecureSearchSortCompareFunction)>(); - - ffi.Pointer _lfind_s( - ffi.Pointer _Key, - ffi.Pointer _Base, - ffi.Pointer _NumOfElements, - int _SizeOfElements, - _CoreCrtSecureSearchSortCompareFunction _CompareFunction, - ffi.Pointer _Context, - ) { - return __lfind_s( - _Key, - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - _Context, - ); - } - - late final __lfind_sPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Size, - _CoreCrtSecureSearchSortCompareFunction, - ffi.Pointer)>>('_lfind_s'); - late final __lfind_s = __lfind_sPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - int, - _CoreCrtSecureSearchSortCompareFunction, - ffi.Pointer)>(); - - ffi.Pointer _lfind( - ffi.Pointer _Key, - ffi.Pointer _Base, - ffi.Pointer _NumOfElements, - int _SizeOfElements, - _CoreCrtNonSecureSearchSortCompareFunction _CompareFunction, - ) { - return __lfind( - _Key, - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - ); - } - - late final __lfindPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.UnsignedInt, - _CoreCrtNonSecureSearchSortCompareFunction)>>('_lfind'); - late final __lfind = __lfindPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - int, - _CoreCrtNonSecureSearchSortCompareFunction)>(); - - ffi.Pointer _lsearch_s( - ffi.Pointer _Key, - ffi.Pointer _Base, - ffi.Pointer _NumOfElements, - int _SizeOfElements, - _CoreCrtSecureSearchSortCompareFunction _CompareFunction, - ffi.Pointer _Context, - ) { - return __lsearch_s( - _Key, - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - _Context, - ); - } - - late final __lsearch_sPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Size, - _CoreCrtSecureSearchSortCompareFunction, - ffi.Pointer)>>('_lsearch_s'); - late final __lsearch_s = __lsearch_sPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - int, - _CoreCrtSecureSearchSortCompareFunction, - ffi.Pointer)>(); - - ffi.Pointer _lsearch( - ffi.Pointer _Key, - ffi.Pointer _Base, - ffi.Pointer _NumOfElements, - int _SizeOfElements, - _CoreCrtNonSecureSearchSortCompareFunction _CompareFunction, - ) { - return __lsearch( - _Key, - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - ); - } - - late final __lsearchPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.UnsignedInt, - _CoreCrtNonSecureSearchSortCompareFunction)>>('_lsearch'); - late final __lsearch = __lsearchPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - int, - _CoreCrtNonSecureSearchSortCompareFunction)>(); - - ffi.Pointer lfind( - ffi.Pointer _Key, - ffi.Pointer _Base, - ffi.Pointer _NumOfElements, - int _SizeOfElements, - _CoreCrtNonSecureSearchSortCompareFunction _CompareFunction, - ) { - return _lfind1( - _Key, - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - ); - } - - late final _lfindPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.UnsignedInt, - _CoreCrtNonSecureSearchSortCompareFunction)>>('lfind'); - late final _lfind1 = _lfindPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - int, - _CoreCrtNonSecureSearchSortCompareFunction)>(); - - ffi.Pointer lsearch( - ffi.Pointer _Key, - ffi.Pointer _Base, - ffi.Pointer _NumOfElements, - int _SizeOfElements, - _CoreCrtNonSecureSearchSortCompareFunction _CompareFunction, - ) { - return _lsearch1( - _Key, - _Base, - _NumOfElements, - _SizeOfElements, - _CompareFunction, - ); - } - - late final _lsearchPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.UnsignedInt, - _CoreCrtNonSecureSearchSortCompareFunction)>>('lsearch'); - late final _lsearch1 = _lsearchPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - int, - _CoreCrtNonSecureSearchSortCompareFunction)>(); - - int _itow_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __itow_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __itow_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Int, ffi.Pointer, ffi.Size, ffi.Int)>>('_itow_s'); - late final __itow_s = __itow_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _itow( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __itow( - _Value, - _Buffer, - _Radix, - ); - } - - late final __itowPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Int, ffi.Pointer, ffi.Int)>>('_itow'); - late final __itow = __itowPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int _ltow_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __ltow_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __ltow_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Long, ffi.Pointer, ffi.Size, ffi.Int)>>('_ltow_s'); - late final __ltow_s = __ltow_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _ltow( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __ltow( - _Value, - _Buffer, - _Radix, - ); - } - - late final __ltowPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Long, ffi.Pointer, ffi.Int)>>('_ltow'); - late final __ltow = __ltowPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int _ultow_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __ultow_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __ultow_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.UnsignedLong, ffi.Pointer, ffi.Size, - ffi.Int)>>('_ultow_s'); - late final __ultow_s = __ultow_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _ultow( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __ultow( - _Value, - _Buffer, - _Radix, - ); - } - - late final __ultowPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.UnsignedLong, ffi.Pointer, ffi.Int)>>('_ultow'); - late final __ultow = __ultowPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - double wcstod( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - ) { - return _wcstod( - _String, - _EndPtr, - ); - } - - late final _wcstodPtr = _lookup< - ffi.NativeFunction< - ffi.Double Function(ffi.Pointer, - ffi.Pointer>)>>('wcstod'); - late final _wcstod = _wcstodPtr.asFunction< - double Function( - ffi.Pointer, ffi.Pointer>)>(); - - double _wcstod_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - _locale_t _Locale, - ) { - return __wcstod_l( - _String, - _EndPtr, - _Locale, - ); - } - - late final __wcstod_lPtr = _lookup< - ffi.NativeFunction< - ffi.Double Function(ffi.Pointer, - ffi.Pointer>, _locale_t)>>('_wcstod_l'); - late final __wcstod_l = __wcstod_lPtr.asFunction< - double Function(ffi.Pointer, - ffi.Pointer>, _locale_t)>(); - - int wcstol( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return _wcstol( - _String, - _EndPtr, - _Radix, - ); - } - - late final _wcstolPtr = _lookup< - ffi.NativeFunction< - ffi.Long Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('wcstol'); - late final _wcstol = _wcstolPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _wcstol_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __wcstol_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __wcstol_lPtr = _lookup< - ffi.NativeFunction< - ffi.Long Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_wcstol_l'); - late final __wcstol_l = __wcstol_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int wcstoll( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return _wcstoll( - _String, - _EndPtr, - _Radix, - ); - } - - late final _wcstollPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('wcstoll'); - late final _wcstoll = _wcstollPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _wcstoll_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __wcstoll_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __wcstoll_lPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_wcstoll_l'); - late final __wcstoll_l = __wcstoll_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int wcstoul( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return _wcstoul( - _String, - _EndPtr, - _Radix, - ); - } - - late final _wcstoulPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('wcstoul'); - late final _wcstoul = _wcstoulPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _wcstoul_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __wcstoul_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __wcstoul_lPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_wcstoul_l'); - late final __wcstoul_l = __wcstoul_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int wcstoull( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return _wcstoull( - _String, - _EndPtr, - _Radix, - ); - } - - late final _wcstoullPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('wcstoull'); - late final _wcstoull = _wcstoullPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _wcstoull_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __wcstoull_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __wcstoull_lPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_wcstoull_l'); - late final __wcstoull_l = __wcstoull_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - double wcstof( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - ) { - return _wcstof( - _String, - _EndPtr, - ); - } - - late final _wcstofPtr = _lookup< - ffi.NativeFunction< - ffi.Float Function(ffi.Pointer, - ffi.Pointer>)>>('wcstof'); - late final _wcstof = _wcstofPtr.asFunction< - double Function( - ffi.Pointer, ffi.Pointer>)>(); - - double _wcstof_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - _locale_t _Locale, - ) { - return __wcstof_l( - _String, - _EndPtr, - _Locale, - ); - } - - late final __wcstof_lPtr = _lookup< - ffi.NativeFunction< - ffi.Float Function(ffi.Pointer, - ffi.Pointer>, _locale_t)>>('_wcstof_l'); - late final __wcstof_l = __wcstof_lPtr.asFunction< - double Function(ffi.Pointer, - ffi.Pointer>, _locale_t)>(); - - double _wtof( - ffi.Pointer _String, - ) { - return __wtof( - _String, - ); - } - - late final __wtofPtr = - _lookup)>>( - '_wtof'); - late final __wtof = - __wtofPtr.asFunction)>(); - - double _wtof_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __wtof_l( - _String, - _Locale, - ); - } - - late final __wtof_lPtr = _lookup< - ffi.NativeFunction< - ffi.Double Function(ffi.Pointer, _locale_t)>>('_wtof_l'); - late final __wtof_l = __wtof_lPtr - .asFunction, _locale_t)>(); - - int _wtoi( - ffi.Pointer _String, - ) { - return __wtoi( - _String, - ); - } - - late final __wtoiPtr = - _lookup)>>( - '_wtoi'); - late final __wtoi = - __wtoiPtr.asFunction)>(); - - int _wtoi_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __wtoi_l( - _String, - _Locale, - ); - } - - late final __wtoi_lPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, _locale_t)>>('_wtoi_l'); - late final __wtoi_l = - __wtoi_lPtr.asFunction, _locale_t)>(); - - int _wtol( - ffi.Pointer _String, - ) { - return __wtol( - _String, - ); - } - - late final __wtolPtr = - _lookup)>>( - '_wtol'); - late final __wtol = - __wtolPtr.asFunction)>(); - - int _wtol_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __wtol_l( - _String, - _Locale, - ); - } - - late final __wtol_lPtr = _lookup< - ffi.NativeFunction< - ffi.Long Function(ffi.Pointer, _locale_t)>>('_wtol_l'); - late final __wtol_l = - __wtol_lPtr.asFunction, _locale_t)>(); - - int _wtoll( - ffi.Pointer _String, - ) { - return __wtoll( - _String, - ); - } - - late final __wtollPtr = _lookup< - ffi - .NativeFunction)>>('_wtoll'); - late final __wtoll = - __wtollPtr.asFunction)>(); - - int _wtoll_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __wtoll_l( - _String, - _Locale, - ); - } - - late final __wtoll_lPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function( - ffi.Pointer, _locale_t)>>('_wtoll_l'); - late final __wtoll_l = __wtoll_lPtr - .asFunction, _locale_t)>(); - - int _i64tow_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __i64tow_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __i64tow_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.LongLong, ffi.Pointer, ffi.Size, - ffi.Int)>>('_i64tow_s'); - late final __i64tow_s = __i64tow_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _i64tow( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __i64tow( - _Value, - _Buffer, - _Radix, - ); - } - - late final __i64towPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.LongLong, ffi.Pointer, ffi.Int)>>('_i64tow'); - late final __i64tow = __i64towPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int _ui64tow_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __ui64tow_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __ui64tow_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.UnsignedLongLong, ffi.Pointer, - ffi.Size, ffi.Int)>>('_ui64tow_s'); - late final __ui64tow_s = __ui64tow_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _ui64tow( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __ui64tow( - _Value, - _Buffer, - _Radix, - ); - } - - late final __ui64towPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.UnsignedLongLong, - ffi.Pointer, ffi.Int)>>('_ui64tow'); - late final __ui64tow = __ui64towPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int _wtoi64( - ffi.Pointer _String, - ) { - return __wtoi64( - _String, - ); - } - - late final __wtoi64Ptr = _lookup< - ffi.NativeFunction)>>( - '_wtoi64'); - late final __wtoi64 = - __wtoi64Ptr.asFunction)>(); - - int _wtoi64_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __wtoi64_l( - _String, - _Locale, - ); - } - - late final __wtoi64_lPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function( - ffi.Pointer, _locale_t)>>('_wtoi64_l'); - late final __wtoi64_l = __wtoi64_lPtr - .asFunction, _locale_t)>(); - - int _wcstoi64( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return __wcstoi64( - _String, - _EndPtr, - _Radix, - ); - } - - late final __wcstoi64Ptr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('_wcstoi64'); - late final __wcstoi64 = __wcstoi64Ptr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _wcstoi64_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __wcstoi64_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __wcstoi64_lPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_wcstoi64_l'); - late final __wcstoi64_l = __wcstoi64_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int _wcstoui64( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return __wcstoui64( - _String, - _EndPtr, - _Radix, - ); - } - - late final __wcstoui64Ptr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('_wcstoui64'); - late final __wcstoui64 = __wcstoui64Ptr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _wcstoui64_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __wcstoui64_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __wcstoui64_lPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_wcstoui64_l'); - late final __wcstoui64_l = __wcstoui64_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - ffi.Pointer _wfullpath( - ffi.Pointer _Buffer, - ffi.Pointer _Path, - int _BufferCount, - ) { - return __wfullpath( - _Buffer, - _Path, - _BufferCount, - ); - } - - late final __wfullpathPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer, - ffi.Pointer, ffi.Size)>>('_wfullpath'); - late final __wfullpath = __wfullpathPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Pointer, int)>(); - - int _wmakepath_s( - ffi.Pointer _Buffer, - int _BufferCount, - ffi.Pointer _Drive, - ffi.Pointer _Dir, - ffi.Pointer _Filename, - ffi.Pointer _Ext, - ) { - return __wmakepath_s( - _Buffer, - _BufferCount, - _Drive, - _Dir, - _Filename, - _Ext, - ); - } - - late final __wmakepath_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>>('_wmakepath_s'); - late final __wmakepath_s = __wmakepath_sPtr.asFunction< - int Function( - ffi.Pointer, - int, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>(); - - void _wmakepath( - ffi.Pointer _Buffer, - ffi.Pointer _Drive, - ffi.Pointer _Dir, - ffi.Pointer _Filename, - ffi.Pointer _Ext, - ) { - return __wmakepath( - _Buffer, - _Drive, - _Dir, - _Filename, - _Ext, - ); - } - - late final __wmakepathPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>>('_wmakepath'); - late final __wmakepath = __wmakepathPtr.asFunction< - void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>(); - - void _wperror( - ffi.Pointer _ErrorMessage, - ) { - return __wperror( - _ErrorMessage, - ); - } - - late final __wperrorPtr = - _lookup)>>( - '_wperror'); - late final __wperror = - __wperrorPtr.asFunction)>(); - - void _wsplitpath( - ffi.Pointer _FullPath, - ffi.Pointer _Drive, - ffi.Pointer _Dir, - ffi.Pointer _Filename, - ffi.Pointer _Ext, - ) { - return __wsplitpath( - _FullPath, - _Drive, - _Dir, - _Filename, - _Ext, - ); - } - - late final __wsplitpathPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>>('_wsplitpath'); - late final __wsplitpath = __wsplitpathPtr.asFunction< - void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>(); - - int _wsplitpath_s( - ffi.Pointer _FullPath, - ffi.Pointer _Drive, - int _DriveCount, - ffi.Pointer _Dir, - int _DirCount, - ffi.Pointer _Filename, - int _FilenameCount, - ffi.Pointer _Ext, - int _ExtCount, - ) { - return __wsplitpath_s( - _FullPath, - _Drive, - _DriveCount, - _Dir, - _DirCount, - _Filename, - _FilenameCount, - _Ext, - _ExtCount, - ); - } - - late final __wsplitpath_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Pointer, - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Size)>>('_wsplitpath_s'); - late final __wsplitpath_s = __wsplitpath_sPtr.asFunction< - int Function( - ffi.Pointer, - ffi.Pointer, - int, - ffi.Pointer, - int, - ffi.Pointer, - int, - ffi.Pointer, - int)>(); - - int _wdupenv_s( - ffi.Pointer> _Buffer, - ffi.Pointer _BufferCount, - ffi.Pointer _VarName, - ) { - return __wdupenv_s( - _Buffer, - _BufferCount, - _VarName, - ); - } - - late final __wdupenv_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer>, - ffi.Pointer, ffi.Pointer)>>('_wdupenv_s'); - late final __wdupenv_s = __wdupenv_sPtr.asFunction< - int Function(ffi.Pointer>, ffi.Pointer, - ffi.Pointer)>(); - - ffi.Pointer _wgetenv( - ffi.Pointer _VarName, - ) { - return __wgetenv( - _VarName, - ); - } - - late final __wgetenvPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer)>>('_wgetenv'); - late final __wgetenv = __wgetenvPtr - .asFunction Function(ffi.Pointer)>(); - - int _wgetenv_s( - ffi.Pointer _RequiredCount, - ffi.Pointer _Buffer, - int _BufferCount, - ffi.Pointer _VarName, - ) { - return __wgetenv_s( - _RequiredCount, - _Buffer, - _BufferCount, - _VarName, - ); - } - - late final __wgetenv_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Pointer, - ffi.Size, ffi.Pointer)>>('_wgetenv_s'); - late final __wgetenv_s = __wgetenv_sPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int, - ffi.Pointer)>(); - - int _wputenv( - ffi.Pointer _EnvString, - ) { - return __wputenv( - _EnvString, - ); - } - - late final __wputenvPtr = - _lookup)>>( - '_wputenv'); - late final __wputenv = - __wputenvPtr.asFunction)>(); - - int _wputenv_s( - ffi.Pointer _Name, - ffi.Pointer _Value, - ) { - return __wputenv_s( - _Name, - _Value, - ); - } - - late final __wputenv_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Pointer, ffi.Pointer)>>('_wputenv_s'); - late final __wputenv_s = __wputenv_sPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer)>(); - - int _wsearchenv_s( - ffi.Pointer _Filename, - ffi.Pointer _VarName, - ffi.Pointer _Buffer, - int _BufferCount, - ) { - return __wsearchenv_s( - _Filename, - _VarName, - _Buffer, - _BufferCount, - ); - } - - late final __wsearchenv_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer, ffi.Size)>>('_wsearchenv_s'); - late final __wsearchenv_s = __wsearchenv_sPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer, int)>(); - - void _wsearchenv( - ffi.Pointer _Filename, - ffi.Pointer _VarName, - ffi.Pointer _ResultPath, - ) { - return __wsearchenv( - _Filename, - _VarName, - _ResultPath, - ); - } - - late final __wsearchenvPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer)>>('_wsearchenv'); - late final __wsearchenv = __wsearchenvPtr.asFunction< - void Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer)>(); - - int _wsystem( - ffi.Pointer _Command, - ) { - return __wsystem( - _Command, - ); - } - - late final __wsystemPtr = - _lookup)>>( - '_wsystem'); - late final __wsystem = - __wsystemPtr.asFunction)>(); - - void _swab( - ffi.Pointer _Buf1, - ffi.Pointer _Buf2, - int _SizeInBytes, - ) { - return __swab( - _Buf1, - _Buf2, - _SizeInBytes, - ); - } - - late final __swabPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, ffi.Pointer, ffi.Int)>>('_swab'); - late final __swab = __swabPtr.asFunction< - void Function(ffi.Pointer, ffi.Pointer, int)>(); - - void exit( - int _Code, - ) { - return _exit1( - _Code, - ); - } - - late final _exitPtr = - _lookup>('exit'); - late final _exit1 = _exitPtr.asFunction(); - - void _exit( - int _Code, - ) { - return __exit( - _Code, - ); - } - - late final __exitPtr = - _lookup>('_exit'); - late final __exit = __exitPtr.asFunction(); - - void _Exit( - int _Code, - ) { - return __Exit( - _Code, - ); - } - - late final __ExitPtr = - _lookup>('_Exit'); - late final __Exit = __ExitPtr.asFunction(); - - void quick_exit( - int _Code, - ) { - return _quick_exit( - _Code, - ); - } - - late final _quick_exitPtr = - _lookup>('quick_exit'); - late final _quick_exit = _quick_exitPtr.asFunction(); - - void abort() { - return _abort(); - } - - late final _abortPtr = - _lookup>('abort'); - late final _abort = _abortPtr.asFunction(); - - int _set_abort_behavior( - int _Flags, - int _Mask, - ) { - return __set_abort_behavior( - _Flags, - _Mask, - ); - } - - late final __set_abort_behaviorPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedInt Function( - ffi.UnsignedInt, ffi.UnsignedInt)>>('_set_abort_behavior'); - late final __set_abort_behavior = - __set_abort_behaviorPtr.asFunction(); - - int atexit( - ffi.Pointer> arg0, - ) { - return _atexit( - arg0, - ); - } - - late final _atexitPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function( - ffi.Pointer>)>>('atexit'); - late final _atexit = _atexitPtr.asFunction< - int Function(ffi.Pointer>)>(); - - _onexit_t _onexit( - _onexit_t _Func, - ) { - return __onexit( - _Func, - ); - } - - late final __onexitPtr = - _lookup>('_onexit'); - late final __onexit = __onexitPtr.asFunction<_onexit_t Function(_onexit_t)>(); - - int at_quick_exit( - ffi.Pointer> arg0, - ) { - return _at_quick_exit( - arg0, - ); - } - - late final _at_quick_exitPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function( - ffi.Pointer>)>>( - 'at_quick_exit'); - late final _at_quick_exit = _at_quick_exitPtr.asFunction< - int Function(ffi.Pointer>)>(); - - _purecall_handler _set_purecall_handler( - _purecall_handler _Handler, - ) { - return __set_purecall_handler( - _Handler, - ); - } - - late final __set_purecall_handlerPtr = _lookup< - ffi.NativeFunction<_purecall_handler Function(_purecall_handler)>>( - '_set_purecall_handler'); - late final __set_purecall_handler = __set_purecall_handlerPtr - .asFunction<_purecall_handler Function(_purecall_handler)>(); - - _purecall_handler _get_purecall_handler() { - return __get_purecall_handler(); - } - - late final __get_purecall_handlerPtr = - _lookup>( - '_get_purecall_handler'); - late final __get_purecall_handler = - __get_purecall_handlerPtr.asFunction<_purecall_handler Function()>(); - - _invalid_parameter_handler _set_invalid_parameter_handler( - _invalid_parameter_handler _Handler, - ) { - return __set_invalid_parameter_handler( - _Handler, - ); - } - - late final __set_invalid_parameter_handlerPtr = _lookup< - ffi.NativeFunction< - _invalid_parameter_handler Function( - _invalid_parameter_handler)>>('_set_invalid_parameter_handler'); - late final __set_invalid_parameter_handler = - __set_invalid_parameter_handlerPtr.asFunction< - _invalid_parameter_handler Function(_invalid_parameter_handler)>(); - - _invalid_parameter_handler _get_invalid_parameter_handler() { - return __get_invalid_parameter_handler(); - } - - late final __get_invalid_parameter_handlerPtr = - _lookup>( - '_get_invalid_parameter_handler'); - late final __get_invalid_parameter_handler = - __get_invalid_parameter_handlerPtr - .asFunction<_invalid_parameter_handler Function()>(); - - _invalid_parameter_handler _set_thread_local_invalid_parameter_handler( - _invalid_parameter_handler _Handler, - ) { - return __set_thread_local_invalid_parameter_handler( - _Handler, - ); - } - - late final __set_thread_local_invalid_parameter_handlerPtr = _lookup< - ffi.NativeFunction< - _invalid_parameter_handler Function(_invalid_parameter_handler)>>( - '_set_thread_local_invalid_parameter_handler'); - late final __set_thread_local_invalid_parameter_handler = - __set_thread_local_invalid_parameter_handlerPtr.asFunction< - _invalid_parameter_handler Function(_invalid_parameter_handler)>(); - - _invalid_parameter_handler _get_thread_local_invalid_parameter_handler() { - return __get_thread_local_invalid_parameter_handler(); - } - - late final __get_thread_local_invalid_parameter_handlerPtr = - _lookup>( - '_get_thread_local_invalid_parameter_handler'); - late final __get_thread_local_invalid_parameter_handler = - __get_thread_local_invalid_parameter_handlerPtr - .asFunction<_invalid_parameter_handler Function()>(); - - int _set_error_mode( - int _Mode, - ) { - return __set_error_mode( - _Mode, - ); - } - - late final __set_error_modePtr = - _lookup>('_set_error_mode'); - late final __set_error_mode = - __set_error_modePtr.asFunction(); - - ffi.Pointer __doserrno() { - return ___doserrno(); - } - - late final ___doserrnoPtr = - _lookup Function()>>( - '__doserrno'); - late final ___doserrno = - ___doserrnoPtr.asFunction Function()>(); - - int _set_doserrno( - int _Value, - ) { - return __set_doserrno( - _Value, - ); - } - - late final __set_doserrnoPtr = - _lookup>( - '_set_doserrno'); - late final __set_doserrno = __set_doserrnoPtr.asFunction(); - - int _get_doserrno( - ffi.Pointer _Value, - ) { - return __get_doserrno( - _Value, - ); - } - - late final __get_doserrnoPtr = _lookup< - ffi.NativeFunction)>>( - '_get_doserrno'); - late final __get_doserrno = __get_doserrnoPtr - .asFunction)>(); - - ffi.Pointer> __sys_errlist() { - return ___sys_errlist(); - } - - late final ___sys_errlistPtr = _lookup< - ffi.NativeFunction> Function()>>( - '__sys_errlist'); - late final ___sys_errlist = ___sys_errlistPtr - .asFunction> Function()>(); - - ffi.Pointer __sys_nerr() { - return ___sys_nerr(); - } - - late final ___sys_nerrPtr = - _lookup Function()>>( - '__sys_nerr'); - late final ___sys_nerr = - ___sys_nerrPtr.asFunction Function()>(); - - void perror( - ffi.Pointer _ErrMsg, - ) { - return _perror( - _ErrMsg, - ); - } - - late final _perrorPtr = - _lookup)>>( - 'perror'); - late final _perror = - _perrorPtr.asFunction)>(); - - ffi.Pointer> __p__pgmptr() { - return ___p__pgmptr(); - } - - late final ___p__pgmptrPtr = _lookup< - ffi.NativeFunction> Function()>>( - '__p__pgmptr'); - late final ___p__pgmptr = ___p__pgmptrPtr - .asFunction> Function()>(); - - ffi.Pointer> __p__wpgmptr() { - return ___p__wpgmptr(); - } - - late final ___p__wpgmptrPtr = _lookup< - ffi.NativeFunction> Function()>>( - '__p__wpgmptr'); - late final ___p__wpgmptr = ___p__wpgmptrPtr - .asFunction> Function()>(); - - ffi.Pointer __p__fmode() { - return ___p__fmode(); - } - - late final ___p__fmodePtr = - _lookup Function()>>( - '__p__fmode'); - late final ___p__fmode = - ___p__fmodePtr.asFunction Function()>(); - - int _get_pgmptr( - ffi.Pointer> _Value, - ) { - return __get_pgmptr( - _Value, - ); - } - - late final __get_pgmptrPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer>)>>('_get_pgmptr'); - late final __get_pgmptr = __get_pgmptrPtr - .asFunction>)>(); - - int _get_wpgmptr( - ffi.Pointer> _Value, - ) { - return __get_wpgmptr( - _Value, - ); - } - - late final __get_wpgmptrPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Pointer>)>>('_get_wpgmptr'); - late final __get_wpgmptr = __get_wpgmptrPtr - .asFunction>)>(); - - int _set_fmode( - int _Mode, - ) { - return __set_fmode( - _Mode, - ); - } - - late final __set_fmodePtr = - _lookup>('_set_fmode'); - late final __set_fmode = __set_fmodePtr.asFunction(); - - int _get_fmode( - ffi.Pointer _PMode, - ) { - return __get_fmode( - _PMode, - ); - } - - late final __get_fmodePtr = - _lookup)>>( - '_get_fmode'); - late final __get_fmode = - __get_fmodePtr.asFunction)>(); - - int abs( - int _Number, - ) { - return _abs( - _Number, - ); - } - - late final _absPtr = - _lookup>('abs'); - late final _abs = _absPtr.asFunction(); - - int labs( - int _Number, - ) { - return _labs( - _Number, - ); - } - - late final _labsPtr = - _lookup>('labs'); - late final _labs = _labsPtr.asFunction(); - - int llabs( - int _Number, - ) { - return _llabs( - _Number, - ); - } - - late final _llabsPtr = - _lookup>('llabs'); - late final _llabs = _llabsPtr.asFunction(); - - int _abs64( - int _Number, - ) { - return __abs64( - _Number, - ); - } - - late final __abs64Ptr = - _lookup>( - '_abs64'); - late final __abs64 = __abs64Ptr.asFunction(); - - int _byteswap_ushort( - int _Number, - ) { - return __byteswap_ushort( - _Number, - ); - } - - late final __byteswap_ushortPtr = _lookup< - ffi.NativeFunction>( - '_byteswap_ushort'); - late final __byteswap_ushort = - __byteswap_ushortPtr.asFunction(); - - int _byteswap_ulong( - int _Number, - ) { - return __byteswap_ulong( - _Number, - ); - } - - late final __byteswap_ulongPtr = - _lookup>( - '_byteswap_ulong'); - late final __byteswap_ulong = - __byteswap_ulongPtr.asFunction(); - - int _byteswap_uint64( - int _Number, - ) { - return __byteswap_uint64( - _Number, - ); - } - - late final __byteswap_uint64Ptr = _lookup< - ffi - .NativeFunction>( - '_byteswap_uint64'); - late final __byteswap_uint64 = - __byteswap_uint64Ptr.asFunction(); - - div_t div( - int _Numerator, - int _Denominator, - ) { - return _div( - _Numerator, - _Denominator, - ); - } - - late final _divPtr = - _lookup>('div'); - late final _div = _divPtr.asFunction(); - - ldiv_t ldiv( - int _Numerator, - int _Denominator, - ) { - return _ldiv( - _Numerator, - _Denominator, - ); - } - - late final _ldivPtr = - _lookup>('ldiv'); - late final _ldiv = _ldivPtr.asFunction(); - - lldiv_t lldiv( - int _Numerator, - int _Denominator, - ) { - return _lldiv( - _Numerator, - _Denominator, - ); - } - - late final _lldivPtr = - _lookup>( - 'lldiv'); - late final _lldiv = _lldivPtr.asFunction(); - - int _rotl( - int _Value, - int _Shift, - ) { - return __rotl( - _Value, - _Shift, - ); - } - - late final __rotlPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedInt Function(ffi.UnsignedInt, ffi.Int)>>('_rotl'); - late final __rotl = __rotlPtr.asFunction(); - - int _lrotl( - int _Value, - int _Shift, - ) { - return __lrotl( - _Value, - _Shift, - ); - } - - late final __lrotlPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLong Function(ffi.UnsignedLong, ffi.Int)>>('_lrotl'); - late final __lrotl = __lrotlPtr.asFunction(); - - int _rotl64( - int _Value, - int _Shift, - ) { - return __rotl64( - _Value, - _Shift, - ); - } - - late final __rotl64Ptr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function( - ffi.UnsignedLongLong, ffi.Int)>>('_rotl64'); - late final __rotl64 = __rotl64Ptr.asFunction(); - - int _rotr( - int _Value, - int _Shift, - ) { - return __rotr( - _Value, - _Shift, - ); - } - - late final __rotrPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedInt Function(ffi.UnsignedInt, ffi.Int)>>('_rotr'); - late final __rotr = __rotrPtr.asFunction(); - - int _lrotr( - int _Value, - int _Shift, - ) { - return __lrotr( - _Value, - _Shift, - ); - } - - late final __lrotrPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLong Function(ffi.UnsignedLong, ffi.Int)>>('_lrotr'); - late final __lrotr = __lrotrPtr.asFunction(); - - int _rotr64( - int _Value, - int _Shift, - ) { - return __rotr64( - _Value, - _Shift, - ); - } - - late final __rotr64Ptr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function( - ffi.UnsignedLongLong, ffi.Int)>>('_rotr64'); - late final __rotr64 = __rotr64Ptr.asFunction(); - - void srand( - int _Seed, - ) { - return _srand( - _Seed, - ); - } - - late final _srandPtr = - _lookup>('srand'); - late final _srand = _srandPtr.asFunction(); - - int rand() { - return _rand(); - } - - late final _randPtr = _lookup>('rand'); - late final _rand = _randPtr.asFunction(); - - double atof( - ffi.Pointer _String, - ) { - return _atof( - _String, - ); - } - - late final _atofPtr = - _lookup)>>( - 'atof'); - late final _atof = - _atofPtr.asFunction)>(); - - int atoi( - ffi.Pointer _String, - ) { - return _atoi( - _String, - ); - } - - late final _atoiPtr = - _lookup)>>( - 'atoi'); - late final _atoi = _atoiPtr.asFunction)>(); - - int atol( - ffi.Pointer _String, - ) { - return _atol( - _String, - ); - } - - late final _atolPtr = - _lookup)>>( - 'atol'); - late final _atol = _atolPtr.asFunction)>(); - - int atoll( - ffi.Pointer _String, - ) { - return _atoll( - _String, - ); - } - - late final _atollPtr = - _lookup)>>( - 'atoll'); - late final _atoll = - _atollPtr.asFunction)>(); - - int _atoi64( - ffi.Pointer _String, - ) { - return __atoi64( - _String, - ); - } - - late final __atoi64Ptr = - _lookup)>>( - '_atoi64'); - late final __atoi64 = - __atoi64Ptr.asFunction)>(); - - double _atof_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __atof_l( - _String, - _Locale, - ); - } - - late final __atof_lPtr = _lookup< - ffi.NativeFunction< - ffi.Double Function(ffi.Pointer, _locale_t)>>('_atof_l'); - late final __atof_l = __atof_lPtr - .asFunction, _locale_t)>(); - - int _atoi_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __atoi_l( - _String, - _Locale, - ); - } - - late final __atoi_lPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, _locale_t)>>('_atoi_l'); - late final __atoi_l = - __atoi_lPtr.asFunction, _locale_t)>(); - - int _atol_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __atol_l( - _String, - _Locale, - ); - } - - late final __atol_lPtr = _lookup< - ffi.NativeFunction< - ffi.Long Function(ffi.Pointer, _locale_t)>>('_atol_l'); - late final __atol_l = - __atol_lPtr.asFunction, _locale_t)>(); - - int _atoll_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __atoll_l( - _String, - _Locale, - ); - } - - late final __atoll_lPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function(ffi.Pointer, _locale_t)>>('_atoll_l'); - late final __atoll_l = - __atoll_lPtr.asFunction, _locale_t)>(); - - int _atoi64_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __atoi64_l( - _String, - _Locale, - ); - } - - late final __atoi64_lPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function( - ffi.Pointer, _locale_t)>>('_atoi64_l'); - late final __atoi64_l = __atoi64_lPtr - .asFunction, _locale_t)>(); - - int _atoflt( - ffi.Pointer<_CRT_FLOAT> _Result, - ffi.Pointer _String, - ) { - return __atoflt( - _Result, - _String, - ); - } - - late final __atofltPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function( - ffi.Pointer<_CRT_FLOAT>, ffi.Pointer)>>('_atoflt'); - late final __atoflt = __atofltPtr.asFunction< - int Function(ffi.Pointer<_CRT_FLOAT>, ffi.Pointer)>(); - - int _atodbl( - ffi.Pointer<_CRT_DOUBLE> _Result, - ffi.Pointer _String, - ) { - return __atodbl( - _Result, - _String, - ); - } - - late final __atodblPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function( - ffi.Pointer<_CRT_DOUBLE>, ffi.Pointer)>>('_atodbl'); - late final __atodbl = __atodblPtr.asFunction< - int Function(ffi.Pointer<_CRT_DOUBLE>, ffi.Pointer)>(); - - int _atoldbl( - ffi.Pointer<_LDOUBLE> _Result, - ffi.Pointer _String, - ) { - return __atoldbl( - _Result, - _String, - ); - } - - late final __atoldblPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function( - ffi.Pointer<_LDOUBLE>, ffi.Pointer)>>('_atoldbl'); - late final __atoldbl = __atoldblPtr - .asFunction, ffi.Pointer)>(); - - int _atoflt_l( - ffi.Pointer<_CRT_FLOAT> _Result, - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __atoflt_l( - _Result, - _String, - _Locale, - ); - } - - late final __atoflt_lPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer<_CRT_FLOAT>, ffi.Pointer, - _locale_t)>>('_atoflt_l'); - late final __atoflt_l = __atoflt_lPtr.asFunction< - int Function( - ffi.Pointer<_CRT_FLOAT>, ffi.Pointer, _locale_t)>(); - - int _atodbl_l( - ffi.Pointer<_CRT_DOUBLE> _Result, - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __atodbl_l( - _Result, - _String, - _Locale, - ); - } - - late final __atodbl_lPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer<_CRT_DOUBLE>, ffi.Pointer, - _locale_t)>>('_atodbl_l'); - late final __atodbl_l = __atodbl_lPtr.asFunction< - int Function( - ffi.Pointer<_CRT_DOUBLE>, ffi.Pointer, _locale_t)>(); - - int _atoldbl_l( - ffi.Pointer<_LDOUBLE> _Result, - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __atoldbl_l( - _Result, - _String, - _Locale, - ); - } - - late final __atoldbl_lPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer<_LDOUBLE>, ffi.Pointer, - _locale_t)>>('_atoldbl_l'); - late final __atoldbl_l = __atoldbl_lPtr.asFunction< - int Function(ffi.Pointer<_LDOUBLE>, ffi.Pointer, _locale_t)>(); - - double strtof( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - ) { - return _strtof( - _String, - _EndPtr, - ); - } - - late final _strtofPtr = _lookup< - ffi.NativeFunction< - ffi.Float Function(ffi.Pointer, - ffi.Pointer>)>>('strtof'); - late final _strtof = _strtofPtr.asFunction< - double Function( - ffi.Pointer, ffi.Pointer>)>(); - - double _strtof_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - _locale_t _Locale, - ) { - return __strtof_l( - _String, - _EndPtr, - _Locale, - ); - } - - late final __strtof_lPtr = _lookup< - ffi.NativeFunction< - ffi.Float Function(ffi.Pointer, - ffi.Pointer>, _locale_t)>>('_strtof_l'); - late final __strtof_l = __strtof_lPtr.asFunction< - double Function(ffi.Pointer, ffi.Pointer>, - _locale_t)>(); - - double strtod( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - ) { - return _strtod( - _String, - _EndPtr, - ); - } - - late final _strtodPtr = _lookup< - ffi.NativeFunction< - ffi.Double Function(ffi.Pointer, - ffi.Pointer>)>>('strtod'); - late final _strtod = _strtodPtr.asFunction< - double Function( - ffi.Pointer, ffi.Pointer>)>(); - - double _strtod_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - _locale_t _Locale, - ) { - return __strtod_l( - _String, - _EndPtr, - _Locale, - ); - } - - late final __strtod_lPtr = _lookup< - ffi.NativeFunction< - ffi.Double Function(ffi.Pointer, - ffi.Pointer>, _locale_t)>>('_strtod_l'); - late final __strtod_l = __strtod_lPtr.asFunction< - double Function(ffi.Pointer, ffi.Pointer>, - _locale_t)>(); - - int strtol( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return _strtol( - _String, - _EndPtr, - _Radix, - ); - } - - late final _strtolPtr = _lookup< - ffi.NativeFunction< - ffi.Long Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('strtol'); - late final _strtol = _strtolPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _strtol_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __strtol_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __strtol_lPtr = _lookup< - ffi.NativeFunction< - ffi.Long Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_strtol_l'); - late final __strtol_l = __strtol_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int strtoll( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return _strtoll( - _String, - _EndPtr, - _Radix, - ); - } - - late final _strtollPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('strtoll'); - late final _strtoll = _strtollPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _strtoll_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __strtoll_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __strtoll_lPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_strtoll_l'); - late final __strtoll_l = __strtoll_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int strtoul( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return _strtoul( - _String, - _EndPtr, - _Radix, - ); - } - - late final _strtoulPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('strtoul'); - late final _strtoul = _strtoulPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _strtoul_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __strtoul_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __strtoul_lPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_strtoul_l'); - late final __strtoul_l = __strtoul_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int strtoull( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return _strtoull( - _String, - _EndPtr, - _Radix, - ); - } - - late final _strtoullPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('strtoull'); - late final _strtoull = _strtoullPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _strtoull_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __strtoull_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __strtoull_lPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_strtoull_l'); - late final __strtoull_l = __strtoull_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int _strtoi64( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return __strtoi64( - _String, - _EndPtr, - _Radix, - ); - } - - late final __strtoi64Ptr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('_strtoi64'); - late final __strtoi64 = __strtoi64Ptr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _strtoi64_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __strtoi64_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __strtoi64_lPtr = _lookup< - ffi.NativeFunction< - ffi.LongLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_strtoi64_l'); - late final __strtoi64_l = __strtoi64_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int _strtoui64( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - ) { - return __strtoui64( - _String, - _EndPtr, - _Radix, - ); - } - - late final __strtoui64Ptr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function(ffi.Pointer, - ffi.Pointer>, ffi.Int)>>('_strtoui64'); - late final __strtoui64 = __strtoui64Ptr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer>, int)>(); - - int _strtoui64_l( - ffi.Pointer _String, - ffi.Pointer> _EndPtr, - int _Radix, - _locale_t _Locale, - ) { - return __strtoui64_l( - _String, - _EndPtr, - _Radix, - _Locale, - ); - } - - late final __strtoui64_lPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLongLong Function( - ffi.Pointer, - ffi.Pointer>, - ffi.Int, - _locale_t)>>('_strtoui64_l'); - late final __strtoui64_l = __strtoui64_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer>, - int, _locale_t)>(); - - int _itoa_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __itoa_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __itoa_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Int, ffi.Pointer, ffi.Size, ffi.Int)>>('_itoa_s'); - late final __itoa_s = __itoa_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _itoa( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __itoa( - _Value, - _Buffer, - _Radix, - ); - } - - late final __itoaPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Int, ffi.Pointer, ffi.Int)>>('_itoa'); - late final __itoa = __itoaPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int _ltoa_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __ltoa_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __ltoa_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Long, ffi.Pointer, ffi.Size, ffi.Int)>>('_ltoa_s'); - late final __ltoa_s = __ltoa_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _ltoa( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __ltoa( - _Value, - _Buffer, - _Radix, - ); - } - - late final __ltoaPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Long, ffi.Pointer, ffi.Int)>>('_ltoa'); - late final __ltoa = __ltoaPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int _ultoa_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __ultoa_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __ultoa_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.UnsignedLong, ffi.Pointer, ffi.Size, - ffi.Int)>>('_ultoa_s'); - late final __ultoa_s = __ultoa_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _ultoa( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __ultoa( - _Value, - _Buffer, - _Radix, - ); - } - - late final __ultoaPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.UnsignedLong, ffi.Pointer, ffi.Int)>>('_ultoa'); - late final __ultoa = __ultoaPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int _i64toa_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __i64toa_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __i64toa_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.LongLong, ffi.Pointer, ffi.Size, - ffi.Int)>>('_i64toa_s'); - late final __i64toa_s = __i64toa_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _i64toa( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __i64toa( - _Value, - _Buffer, - _Radix, - ); - } - - late final __i64toaPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.LongLong, ffi.Pointer, ffi.Int)>>('_i64toa'); - late final __i64toa = __i64toaPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int _ui64toa_s( - int _Value, - ffi.Pointer _Buffer, - int _BufferCount, - int _Radix, - ) { - return __ui64toa_s( - _Value, - _Buffer, - _BufferCount, - _Radix, - ); - } - - late final __ui64toa_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.UnsignedLongLong, ffi.Pointer, - ffi.Size, ffi.Int)>>('_ui64toa_s'); - late final __ui64toa_s = __ui64toa_sPtr - .asFunction, int, int)>(); - - ffi.Pointer _ui64toa( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return __ui64toa( - _Value, - _Buffer, - _Radix, - ); - } - - late final __ui64toaPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.UnsignedLongLong, - ffi.Pointer, ffi.Int)>>('_ui64toa'); - late final __ui64toa = __ui64toaPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int _ecvt_s( - ffi.Pointer _Buffer, - int _BufferCount, - double _Value, - int _DigitCount, - ffi.Pointer _PtDec, - ffi.Pointer _PtSign, - ) { - return __ecvt_s( - _Buffer, - _BufferCount, - _Value, - _DigitCount, - _PtDec, - _PtSign, - ); - } - - late final __ecvt_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Size, ffi.Double, ffi.Int, - ffi.Pointer, ffi.Pointer)>>('_ecvt_s'); - late final __ecvt_s = __ecvt_sPtr.asFunction< - int Function(ffi.Pointer, int, double, int, - ffi.Pointer, ffi.Pointer)>(); - - ffi.Pointer _ecvt( - double _Value, - int _DigitCount, - ffi.Pointer _PtDec, - ffi.Pointer _PtSign, - ) { - return __ecvt( - _Value, - _DigitCount, - _PtDec, - _PtSign, - ); - } - - late final __ecvtPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Double, ffi.Int, - ffi.Pointer, ffi.Pointer)>>('_ecvt'); - late final __ecvt = __ecvtPtr.asFunction< - ffi.Pointer Function( - double, int, ffi.Pointer, ffi.Pointer)>(); - - int _fcvt_s( - ffi.Pointer _Buffer, - int _BufferCount, - double _Value, - int _FractionalDigitCount, - ffi.Pointer _PtDec, - ffi.Pointer _PtSign, - ) { - return __fcvt_s( - _Buffer, - _BufferCount, - _Value, - _FractionalDigitCount, - _PtDec, - _PtSign, - ); - } - - late final __fcvt_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Size, ffi.Double, ffi.Int, - ffi.Pointer, ffi.Pointer)>>('_fcvt_s'); - late final __fcvt_s = __fcvt_sPtr.asFunction< - int Function(ffi.Pointer, int, double, int, - ffi.Pointer, ffi.Pointer)>(); - - ffi.Pointer _fcvt( - double _Value, - int _FractionalDigitCount, - ffi.Pointer _PtDec, - ffi.Pointer _PtSign, - ) { - return __fcvt( - _Value, - _FractionalDigitCount, - _PtDec, - _PtSign, - ); - } - - late final __fcvtPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Double, ffi.Int, - ffi.Pointer, ffi.Pointer)>>('_fcvt'); - late final __fcvt = __fcvtPtr.asFunction< - ffi.Pointer Function( - double, int, ffi.Pointer, ffi.Pointer)>(); - - int _gcvt_s( - ffi.Pointer _Buffer, - int _BufferCount, - double _Value, - int _DigitCount, - ) { - return __gcvt_s( - _Buffer, - _BufferCount, - _Value, - _DigitCount, - ); - } - - late final __gcvt_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Size, ffi.Double, - ffi.Int)>>('_gcvt_s'); - late final __gcvt_s = __gcvt_sPtr - .asFunction, int, double, int)>(); - - ffi.Pointer _gcvt( - double _Value, - int _DigitCount, - ffi.Pointer _Buffer, - ) { - return __gcvt( - _Value, - _DigitCount, - _Buffer, - ); - } - - late final __gcvtPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Double, ffi.Int, ffi.Pointer)>>('_gcvt'); - late final __gcvt = __gcvtPtr.asFunction< - ffi.Pointer Function(double, int, ffi.Pointer)>(); - - int ___mb_cur_max_func() { - return ____mb_cur_max_func(); - } - - late final ____mb_cur_max_funcPtr = - _lookup>('___mb_cur_max_func'); - late final ____mb_cur_max_func = - ____mb_cur_max_funcPtr.asFunction(); - - int ___mb_cur_max_l_func( - _locale_t _Locale, - ) { - return ____mb_cur_max_l_func( - _Locale, - ); - } - - late final ____mb_cur_max_l_funcPtr = - _lookup>( - '___mb_cur_max_l_func'); - late final ____mb_cur_max_l_func = - ____mb_cur_max_l_funcPtr.asFunction(); - - int mblen( - ffi.Pointer _Ch, - int _MaxCount, - ) { - return _mblen( - _Ch, - _MaxCount, - ); - } - - late final _mblenPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.Size)>>('mblen'); - late final _mblen = - _mblenPtr.asFunction, int)>(); - - int _mblen_l( - ffi.Pointer _Ch, - int _MaxCount, - _locale_t _Locale, - ) { - return __mblen_l( - _Ch, - _MaxCount, - _Locale, - ); - } - - late final __mblen_lPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function( - ffi.Pointer, ffi.Size, _locale_t)>>('_mblen_l'); - late final __mblen_l = __mblen_lPtr - .asFunction, int, _locale_t)>(); - - int _mbstrlen( - ffi.Pointer _String, - ) { - return __mbstrlen( - _String, - ); - } - - late final __mbstrlenPtr = - _lookup)>>( - '_mbstrlen'); - late final __mbstrlen = - __mbstrlenPtr.asFunction)>(); - - int _mbstrlen_l( - ffi.Pointer _String, - _locale_t _Locale, - ) { - return __mbstrlen_l( - _String, - _Locale, - ); - } - - late final __mbstrlen_lPtr = _lookup< - ffi.NativeFunction< - ffi.Size Function(ffi.Pointer, _locale_t)>>('_mbstrlen_l'); - late final __mbstrlen_l = __mbstrlen_lPtr - .asFunction, _locale_t)>(); - - int _mbstrnlen( - ffi.Pointer _String, - int _MaxCount, - ) { - return __mbstrnlen( - _String, - _MaxCount, - ); - } - - late final __mbstrnlenPtr = _lookup< - ffi.NativeFunction< - ffi.Size Function(ffi.Pointer, ffi.Size)>>('_mbstrnlen'); - late final __mbstrnlen = - __mbstrnlenPtr.asFunction, int)>(); - - int _mbstrnlen_l( - ffi.Pointer _String, - int _MaxCount, - _locale_t _Locale, - ) { - return __mbstrnlen_l( - _String, - _MaxCount, - _Locale, - ); - } - - late final __mbstrnlen_lPtr = _lookup< - ffi.NativeFunction< - ffi.Size Function( - ffi.Pointer, ffi.Size, _locale_t)>>('_mbstrnlen_l'); - late final __mbstrnlen_l = __mbstrnlen_lPtr - .asFunction, int, _locale_t)>(); - - int mbtowc( - ffi.Pointer _DstCh, - ffi.Pointer _SrcCh, - int _SrcSizeInBytes, - ) { - return _mbtowc( - _DstCh, - _SrcCh, - _SrcSizeInBytes, - ); - } - - late final _mbtowcPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.Pointer, - ffi.Size)>>('mbtowc'); - late final _mbtowc = _mbtowcPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int)>(); - - int _mbtowc_l( - ffi.Pointer _DstCh, - ffi.Pointer _SrcCh, - int _SrcSizeInBytes, - _locale_t _Locale, - ) { - return __mbtowc_l( - _DstCh, - _SrcCh, - _SrcSizeInBytes, - _Locale, - ); - } - - late final __mbtowc_lPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.Pointer, - ffi.Size, _locale_t)>>('_mbtowc_l'); - late final __mbtowc_l = __mbtowc_lPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer, int, _locale_t)>(); - - int mbstowcs_s( - ffi.Pointer _PtNumOfCharConverted, - ffi.Pointer _DstBuf, - int _SizeInWords, - ffi.Pointer _SrcBuf, - int _MaxCount, - ) { - return _mbstowcs_s( - _PtNumOfCharConverted, - _DstBuf, - _SizeInWords, - _SrcBuf, - _MaxCount, - ); - } - - late final _mbstowcs_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Pointer, - ffi.Size, ffi.Pointer, ffi.Size)>>('mbstowcs_s'); - late final _mbstowcs_s = _mbstowcs_sPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int, - ffi.Pointer, int)>(); - - int mbstowcs( - ffi.Pointer _Dest, - ffi.Pointer _Source, - int _MaxCount, - ) { - return _mbstowcs( - _Dest, - _Source, - _MaxCount, - ); - } - - late final _mbstowcsPtr = _lookup< - ffi.NativeFunction< - ffi.Size Function(ffi.Pointer, ffi.Pointer, - ffi.Size)>>('mbstowcs'); - late final _mbstowcs = _mbstowcsPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int)>(); - - int _mbstowcs_s_l( - ffi.Pointer _PtNumOfCharConverted, - ffi.Pointer _DstBuf, - int _SizeInWords, - ffi.Pointer _SrcBuf, - int _MaxCount, - _locale_t _Locale, - ) { - return __mbstowcs_s_l( - _PtNumOfCharConverted, - _DstBuf, - _SizeInWords, - _SrcBuf, - _MaxCount, - _Locale, - ); - } - - late final __mbstowcs_s_lPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Pointer, - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Size, - _locale_t)>>('_mbstowcs_s_l'); - late final __mbstowcs_s_l = __mbstowcs_s_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int, - ffi.Pointer, int, _locale_t)>(); - - int _mbstowcs_l( - ffi.Pointer _Dest, - ffi.Pointer _Source, - int _MaxCount, - _locale_t _Locale, - ) { - return __mbstowcs_l( - _Dest, - _Source, - _MaxCount, - _Locale, - ); - } - - late final __mbstowcs_lPtr = _lookup< - ffi.NativeFunction< - ffi.Size Function(ffi.Pointer, ffi.Pointer, - ffi.Size, _locale_t)>>('_mbstowcs_l'); - late final __mbstowcs_l = __mbstowcs_lPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer, int, _locale_t)>(); - - int wctomb( - ffi.Pointer _MbCh, - int _WCh, - ) { - return _wctomb( - _MbCh, - _WCh, - ); - } - - late final _wctombPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.WChar)>>('wctomb'); - late final _wctomb = - _wctombPtr.asFunction, int)>(); - - int _wctomb_l( - ffi.Pointer _MbCh, - int _WCh, - _locale_t _Locale, - ) { - return __wctomb_l( - _MbCh, - _WCh, - _Locale, - ); - } - - late final __wctomb_lPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function( - ffi.Pointer, ffi.WChar, _locale_t)>>('_wctomb_l'); - late final __wctomb_l = __wctomb_lPtr - .asFunction, int, _locale_t)>(); - - int wctomb_s( - ffi.Pointer _SizeConverted, - ffi.Pointer _MbCh, - int _SizeInBytes, - int _WCh, - ) { - return _wctomb_s( - _SizeConverted, - _MbCh, - _SizeInBytes, - _WCh, - ); - } - - late final _wctomb_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Pointer, rsize_t, - ffi.WChar)>>('wctomb_s'); - late final _wctomb_s = _wctomb_sPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int, int)>(); - - int _wctomb_s_l( - ffi.Pointer _SizeConverted, - ffi.Pointer _MbCh, - int _SizeInBytes, - int _WCh, - _locale_t _Locale, - ) { - return __wctomb_s_l( - _SizeConverted, - _MbCh, - _SizeInBytes, - _WCh, - _Locale, - ); - } - - late final __wctomb_s_lPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Pointer, - ffi.Size, ffi.WChar, _locale_t)>>('_wctomb_s_l'); - late final __wctomb_s_l = __wctomb_s_lPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer, int, int, _locale_t)>(); - - int wcstombs_s( - ffi.Pointer _PtNumOfCharConverted, - ffi.Pointer _Dst, - int _DstSizeInBytes, - ffi.Pointer _Src, - int _MaxCountInBytes, - ) { - return _wcstombs_s( - _PtNumOfCharConverted, - _Dst, - _DstSizeInBytes, - _Src, - _MaxCountInBytes, - ); - } - - late final _wcstombs_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Pointer, - ffi.Size, ffi.Pointer, ffi.Size)>>('wcstombs_s'); - late final _wcstombs_s = _wcstombs_sPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int, - ffi.Pointer, int)>(); - - int wcstombs( - ffi.Pointer _Dest, - ffi.Pointer _Source, - int _MaxCount, - ) { - return _wcstombs( - _Dest, - _Source, - _MaxCount, - ); - } - - late final _wcstombsPtr = _lookup< - ffi.NativeFunction< - ffi.Size Function(ffi.Pointer, ffi.Pointer, - ffi.Size)>>('wcstombs'); - late final _wcstombs = _wcstombsPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int)>(); - - int _wcstombs_s_l( - ffi.Pointer _PtNumOfCharConverted, - ffi.Pointer _Dst, - int _DstSizeInBytes, - ffi.Pointer _Src, - int _MaxCountInBytes, - _locale_t _Locale, - ) { - return __wcstombs_s_l( - _PtNumOfCharConverted, - _Dst, - _DstSizeInBytes, - _Src, - _MaxCountInBytes, - _Locale, - ); - } - - late final __wcstombs_s_lPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Pointer, - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Size, - _locale_t)>>('_wcstombs_s_l'); - late final __wcstombs_s_l = __wcstombs_s_lPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int, - ffi.Pointer, int, _locale_t)>(); - - int _wcstombs_l( - ffi.Pointer _Dest, - ffi.Pointer _Source, - int _MaxCount, - _locale_t _Locale, - ) { - return __wcstombs_l( - _Dest, - _Source, - _MaxCount, - _Locale, - ); - } - - late final __wcstombs_lPtr = _lookup< - ffi.NativeFunction< - ffi.Size Function(ffi.Pointer, ffi.Pointer, - ffi.Size, _locale_t)>>('_wcstombs_l'); - late final __wcstombs_l = __wcstombs_lPtr.asFunction< - int Function( - ffi.Pointer, ffi.Pointer, int, _locale_t)>(); - - ffi.Pointer _fullpath( - ffi.Pointer _Buffer, - ffi.Pointer _Path, - int _BufferCount, - ) { - return __fullpath( - _Buffer, - _Path, - _BufferCount, - ); - } - - late final __fullpathPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer, - ffi.Pointer, ffi.Size)>>('_fullpath'); - late final __fullpath = __fullpathPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Pointer, int)>(); - - int _makepath_s( - ffi.Pointer _Buffer, - int _BufferCount, - ffi.Pointer _Drive, - ffi.Pointer _Dir, - ffi.Pointer _Filename, - ffi.Pointer _Ext, - ) { - return __makepath_s( - _Buffer, - _BufferCount, - _Drive, - _Dir, - _Filename, - _Ext, - ); - } - - late final __makepath_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>>('_makepath_s'); - late final __makepath_s = __makepath_sPtr.asFunction< - int Function( - ffi.Pointer, - int, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>(); - - void _makepath( - ffi.Pointer _Buffer, - ffi.Pointer _Drive, - ffi.Pointer _Dir, - ffi.Pointer _Filename, - ffi.Pointer _Ext, - ) { - return __makepath( - _Buffer, - _Drive, - _Dir, - _Filename, - _Ext, - ); - } - - late final __makepathPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>>('_makepath'); - late final __makepath = __makepathPtr.asFunction< - void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>(); - - void _splitpath( - ffi.Pointer _FullPath, - ffi.Pointer _Drive, - ffi.Pointer _Dir, - ffi.Pointer _Filename, - ffi.Pointer _Ext, - ) { - return __splitpath( - _FullPath, - _Drive, - _Dir, - _Filename, - _Ext, - ); - } - - late final __splitpathPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>>('_splitpath'); - late final __splitpath = __splitpathPtr.asFunction< - void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer)>(); - - int _splitpath_s( - ffi.Pointer _FullPath, - ffi.Pointer _Drive, - int _DriveCount, - ffi.Pointer _Dir, - int _DirCount, - ffi.Pointer _Filename, - int _FilenameCount, - ffi.Pointer _Ext, - int _ExtCount, - ) { - return __splitpath_s( - _FullPath, - _Drive, - _DriveCount, - _Dir, - _DirCount, - _Filename, - _FilenameCount, - _Ext, - _ExtCount, - ); - } - - late final __splitpath_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Pointer, - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Size, - ffi.Pointer, - ffi.Size)>>('_splitpath_s'); - late final __splitpath_s = __splitpath_sPtr.asFunction< - int Function( - ffi.Pointer, - ffi.Pointer, - int, - ffi.Pointer, - int, - ffi.Pointer, - int, - ffi.Pointer, - int)>(); - - int getenv_s( - ffi.Pointer _RequiredCount, - ffi.Pointer _Buffer, - int _BufferCount, - ffi.Pointer _VarName, - ) { - return _getenv_s( - _RequiredCount, - _Buffer, - _BufferCount, - _VarName, - ); - } - - late final _getenv_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Pointer, - rsize_t, ffi.Pointer)>>('getenv_s'); - late final _getenv_s = _getenv_sPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, int, - ffi.Pointer)>(); - - ffi.Pointer __p___argc() { - return ___p___argc(); - } - - late final ___p___argcPtr = - _lookup Function()>>( - '__p___argc'); - late final ___p___argc = - ___p___argcPtr.asFunction Function()>(); - - ffi.Pointer>> __p___argv() { - return ___p___argv(); - } - - late final ___p___argvPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer>> - Function()>>('__p___argv'); - late final ___p___argv = ___p___argvPtr - .asFunction>> Function()>(); - - ffi.Pointer>> __p___wargv() { - return ___p___wargv(); - } - - late final ___p___wargvPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer>> - Function()>>('__p___wargv'); - late final ___p___wargv = ___p___wargvPtr.asFunction< - ffi.Pointer>> Function()>(); - - ffi.Pointer>> __p__environ() { - return ___p__environ(); - } - - late final ___p__environPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer>> - Function()>>('__p__environ'); - late final ___p__environ = ___p__environPtr - .asFunction>> Function()>(); - - ffi.Pointer>> __p__wenviron() { - return ___p__wenviron(); - } - - late final ___p__wenvironPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer>> - Function()>>('__p__wenviron'); - late final ___p__wenviron = ___p__wenvironPtr.asFunction< - ffi.Pointer>> Function()>(); - - ffi.Pointer getenv( - ffi.Pointer _VarName, - ) { - return _getenv( - _VarName, - ); - } - - late final _getenvPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer)>>('getenv'); - late final _getenv = _getenvPtr - .asFunction Function(ffi.Pointer)>(); - - int _dupenv_s( - ffi.Pointer> _Buffer, - ffi.Pointer _BufferCount, - ffi.Pointer _VarName, - ) { - return __dupenv_s( - _Buffer, - _BufferCount, - _VarName, - ); - } - - late final __dupenv_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer>, - ffi.Pointer, ffi.Pointer)>>('_dupenv_s'); - late final __dupenv_s = __dupenv_sPtr.asFunction< - int Function(ffi.Pointer>, ffi.Pointer, - ffi.Pointer)>(); - - int system( - ffi.Pointer _Command, - ) { - return _system( - _Command, - ); - } - - late final _systemPtr = - _lookup)>>( - 'system'); - late final _system = - _systemPtr.asFunction)>(); - - int _putenv( - ffi.Pointer _EnvString, - ) { - return __putenv( - _EnvString, - ); - } - - late final __putenvPtr = - _lookup)>>( - '_putenv'); - late final __putenv = - __putenvPtr.asFunction)>(); - - int _putenv_s( - ffi.Pointer _Name, - ffi.Pointer _Value, - ) { - return __putenv_s( - _Name, - _Value, - ); - } - - late final __putenv_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function( - ffi.Pointer, ffi.Pointer)>>('_putenv_s'); - late final __putenv_s = __putenv_sPtr - .asFunction, ffi.Pointer)>(); - - int _searchenv_s( - ffi.Pointer _Filename, - ffi.Pointer _VarName, - ffi.Pointer _Buffer, - int _BufferCount, - ) { - return __searchenv_s( - _Filename, - _VarName, - _Buffer, - _BufferCount, - ); - } - - late final __searchenv_sPtr = _lookup< - ffi.NativeFunction< - errno_t Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer, ffi.Size)>>('_searchenv_s'); - late final __searchenv_s = __searchenv_sPtr.asFunction< - int Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer, int)>(); - - void _searchenv( - ffi.Pointer _Filename, - ffi.Pointer _VarName, - ffi.Pointer _Buffer, - ) { - return __searchenv( - _Filename, - _VarName, - _Buffer, - ); - } - - late final __searchenvPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer)>>('_searchenv'); - late final __searchenv = __searchenvPtr.asFunction< - void Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer)>(); - - void _seterrormode( - int _Mode, - ) { - return __seterrormode( - _Mode, - ); - } - - late final __seterrormodePtr = - _lookup>('_seterrormode'); - late final __seterrormode = - __seterrormodePtr.asFunction(); - - void _beep( - int _Frequency, - int _Duration, - ) { - return __beep( - _Frequency, - _Duration, - ); - } - - late final __beepPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function(ffi.UnsignedInt, ffi.UnsignedInt)>>('_beep'); - late final __beep = __beepPtr.asFunction(); - - void _sleep( - int _Duration, - ) { - return __sleep( - _Duration, - ); - } - - late final __sleepPtr = - _lookup>( - '_sleep'); - late final __sleep = __sleepPtr.asFunction(); - - ffi.Pointer ecvt( - double _Value, - int _DigitCount, - ffi.Pointer _PtDec, - ffi.Pointer _PtSign, - ) { - return _ecvt1( - _Value, - _DigitCount, - _PtDec, - _PtSign, - ); - } - - late final _ecvtPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Double, ffi.Int, - ffi.Pointer, ffi.Pointer)>>('ecvt'); - late final _ecvt1 = _ecvtPtr.asFunction< - ffi.Pointer Function( - double, int, ffi.Pointer, ffi.Pointer)>(); - - ffi.Pointer fcvt( - double _Value, - int _FractionalDigitCount, - ffi.Pointer _PtDec, - ffi.Pointer _PtSign, - ) { - return _fcvt1( - _Value, - _FractionalDigitCount, - _PtDec, - _PtSign, - ); - } - - late final _fcvtPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Double, ffi.Int, - ffi.Pointer, ffi.Pointer)>>('fcvt'); - late final _fcvt1 = _fcvtPtr.asFunction< - ffi.Pointer Function( - double, int, ffi.Pointer, ffi.Pointer)>(); - - ffi.Pointer gcvt( - double _Value, - int _DigitCount, - ffi.Pointer _DstBuf, - ) { - return _gcvt1( - _Value, - _DigitCount, - _DstBuf, - ); - } - - late final _gcvtPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Double, ffi.Int, ffi.Pointer)>>('gcvt'); - late final _gcvt1 = _gcvtPtr.asFunction< - ffi.Pointer Function(double, int, ffi.Pointer)>(); - - ffi.Pointer itoa( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return _itoa1( - _Value, - _Buffer, - _Radix, - ); - } - - late final _itoaPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Int, ffi.Pointer, ffi.Int)>>('itoa'); - late final _itoa1 = _itoaPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - ffi.Pointer ltoa( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return _ltoa1( - _Value, - _Buffer, - _Radix, - ); - } - - late final _ltoaPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Long, ffi.Pointer, ffi.Int)>>('ltoa'); - late final _ltoa1 = _ltoaPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - void swab( - ffi.Pointer _Buf1, - ffi.Pointer _Buf2, - int _SizeInBytes, - ) { - return _swab1( - _Buf1, - _Buf2, - _SizeInBytes, - ); - } - - late final _swabPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, ffi.Pointer, ffi.Int)>>('swab'); - late final _swab1 = _swabPtr.asFunction< - void Function(ffi.Pointer, ffi.Pointer, int)>(); - - ffi.Pointer ultoa( - int _Value, - ffi.Pointer _Buffer, - int _Radix, - ) { - return _ultoa1( - _Value, - _Buffer, - _Radix, - ); - } - - late final _ultoaPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.UnsignedLong, ffi.Pointer, ffi.Int)>>('ultoa'); - late final _ultoa1 = _ultoaPtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer, int)>(); - - int putenv( - ffi.Pointer _EnvString, - ) { - return _putenv1( - _EnvString, - ); - } - - late final _putenvPtr = - _lookup)>>( - 'putenv'); - late final _putenv1 = - _putenvPtr.asFunction)>(); - - _onexit_t onexit( - _onexit_t _Func, - ) { - return _onexit1( - _Func, - ); - } - - late final _onexitPtr = - _lookup>('onexit'); - late final _onexit1 = _onexitPtr.asFunction<_onexit_t Function(_onexit_t)>(); - double cabs( _Dcomplex _Z, ) { @@ -5146,36 +857,33 @@ class LibgopeedBind { late final __FCmulcr = __FCmulcrPtr.asFunction<_Fcomplex Function(_Fcomplex, double)>(); - ffi.Pointer Create( + ffi.Pointer Init( ffi.Pointer cfg, ) { - return _Create( + return _Init( cfg, ); } - late final _CreatePtr = _lookup< + late final _InitPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer)>>('Create'); - late final _Create = _CreatePtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>>('Init'); + late final _Init = _InitPtr.asFunction< ffi.Pointer Function(ffi.Pointer)>(); ffi.Pointer Invoke( - int index, ffi.Pointer req, ) { return _Invoke( - index, req, ); } late final _InvokePtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function( - GoInt, ffi.Pointer)>>('Invoke'); + ffi.Pointer Function(ffi.Pointer)>>('Invoke'); late final _Invoke = _InvokePtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer)>(); + ffi.Pointer Function(ffi.Pointer)>(); } typedef va_list = ffi.Pointer; @@ -5223,92 +931,6 @@ final class _GoString_ extends ffi.Struct { typedef ptrdiff_t = ffi.LongLong; typedef Dartptrdiff_t = int; -typedef rsize_t = ffi.Size; -typedef Dartrsize_t = int; -typedef _CoreCrtSecureSearchSortCompareFunction = ffi.Pointer< - ffi.NativeFunction<_CoreCrtSecureSearchSortCompareFunctionFunction>>; -typedef _CoreCrtSecureSearchSortCompareFunctionFunction = ffi.Int Function( - ffi.Pointer, ffi.Pointer, ffi.Pointer); -typedef Dart_CoreCrtSecureSearchSortCompareFunctionFunction = int Function( - ffi.Pointer, ffi.Pointer, ffi.Pointer); -typedef _CoreCrtNonSecureSearchSortCompareFunction = ffi.Pointer< - ffi.NativeFunction<_CoreCrtNonSecureSearchSortCompareFunctionFunction>>; -typedef _CoreCrtNonSecureSearchSortCompareFunctionFunction = ffi.Int Function( - ffi.Pointer, ffi.Pointer); -typedef Dart_CoreCrtNonSecureSearchSortCompareFunctionFunction = int Function( - ffi.Pointer, ffi.Pointer); -typedef _locale_t = ffi.Pointer<__crt_locale_pointers>; -typedef _onexit_t = ffi.Pointer>; -typedef _onexit_tFunction = ffi.Int Function(); -typedef Dart_onexit_tFunction = int Function(); -typedef _purecall_handler - = ffi.Pointer>; -typedef _purecall_handlerFunction = ffi.Void Function(); -typedef Dart_purecall_handlerFunction = void Function(); -typedef _invalid_parameter_handler - = ffi.Pointer>; -typedef _invalid_parameter_handlerFunction = ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.UnsignedInt, - ffi.UintPtr); -typedef Dart_invalid_parameter_handlerFunction = void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - int, - int); - -final class _div_t extends ffi.Struct { - @ffi.Int() - external int quot; - - @ffi.Int() - external int rem; -} - -final class _ldiv_t extends ffi.Struct { - @ffi.Long() - external int quot; - - @ffi.Long() - external int rem; -} - -final class _lldiv_t extends ffi.Struct { - @ffi.LongLong() - external int quot; - - @ffi.LongLong() - external int rem; -} - -typedef div_t = _div_t; -typedef ldiv_t = _ldiv_t; -typedef lldiv_t = _lldiv_t; - -final class _LDOUBLE extends ffi.Struct { - @ffi.Array.multi([10]) - external ffi.Array ld; -} - -final class _CRT_DOUBLE extends ffi.Struct { - @ffi.Double() - external double x; -} - -final class _CRT_FLOAT extends ffi.Struct { - @ffi.Float() - external double f; -} - -final class _LONGDOUBLE extends ffi.Opaque {} - -final class _LDBL12 extends ffi.Struct { - @ffi.Array.multi([12]) - external ffi.Array ld12; -} final class _C_double_complex extends ffi.Struct { @ffi.Array.multi([2]) @@ -5414,141 +1036,3 @@ const int _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES = 1; const int _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY = 0; const int _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY = 0; - -const int _MAX_ITOSTR_BASE16_COUNT = 9; - -const int _MAX_ITOSTR_BASE10_COUNT = 12; - -const int _MAX_ITOSTR_BASE8_COUNT = 12; - -const int _MAX_ITOSTR_BASE2_COUNT = 33; - -const int _MAX_LTOSTR_BASE16_COUNT = 9; - -const int _MAX_LTOSTR_BASE10_COUNT = 12; - -const int _MAX_LTOSTR_BASE8_COUNT = 12; - -const int _MAX_LTOSTR_BASE2_COUNT = 33; - -const int _MAX_ULTOSTR_BASE16_COUNT = 9; - -const int _MAX_ULTOSTR_BASE10_COUNT = 11; - -const int _MAX_ULTOSTR_BASE8_COUNT = 12; - -const int _MAX_ULTOSTR_BASE2_COUNT = 33; - -const int _MAX_I64TOSTR_BASE16_COUNT = 17; - -const int _MAX_I64TOSTR_BASE10_COUNT = 21; - -const int _MAX_I64TOSTR_BASE8_COUNT = 23; - -const int _MAX_I64TOSTR_BASE2_COUNT = 65; - -const int _MAX_U64TOSTR_BASE16_COUNT = 17; - -const int _MAX_U64TOSTR_BASE10_COUNT = 21; - -const int _MAX_U64TOSTR_BASE8_COUNT = 23; - -const int _MAX_U64TOSTR_BASE2_COUNT = 65; - -const int CHAR_BIT = 8; - -const int SCHAR_MIN = -128; - -const int SCHAR_MAX = 127; - -const int UCHAR_MAX = 255; - -const int CHAR_MIN = -128; - -const int CHAR_MAX = 127; - -const int MB_LEN_MAX = 5; - -const int SHRT_MIN = -32768; - -const int SHRT_MAX = 32767; - -const int USHRT_MAX = 65535; - -const int INT_MIN = -2147483648; - -const int INT_MAX = 2147483647; - -const int UINT_MAX = 4294967295; - -const int LONG_MIN = -2147483648; - -const int LONG_MAX = 2147483647; - -const int ULONG_MAX = 4294967295; - -const int LLONG_MAX = 9223372036854775807; - -const int LLONG_MIN = -9223372036854775808; - -const int ULLONG_MAX = -1; - -const int _I8_MIN = -128; - -const int _I8_MAX = 127; - -const int _UI8_MAX = 255; - -const int _I16_MIN = -32768; - -const int _I16_MAX = 32767; - -const int _UI16_MAX = 65535; - -const int _I32_MIN = -2147483648; - -const int _I32_MAX = 2147483647; - -const int _UI32_MAX = 4294967295; - -const int _I64_MIN = -9223372036854775808; - -const int _I64_MAX = 9223372036854775807; - -const int _UI64_MAX = -1; - -const int SIZE_MAX = -1; - -const int RSIZE_MAX = 9223372036854775807; - -const int EXIT_SUCCESS = 0; - -const int EXIT_FAILURE = 1; - -const int _WRITE_ABORT_MSG = 1; - -const int _CALL_REPORTFAULT = 2; - -const int _OUT_TO_DEFAULT = 0; - -const int _OUT_TO_STDERR = 1; - -const int _OUT_TO_MSGBOX = 2; - -const int _REPORT_ERRMODE = 3; - -const int RAND_MAX = 32767; - -const int _CVTBUFSIZE = 349; - -const int _MAX_PATH = 260; - -const int _MAX_DRIVE = 3; - -const int _MAX_DIR = 256; - -const int _MAX_FNAME = 256; - -const int _MAX_EXT = 256; - -const int _MAX_ENV = 32767; diff --git a/ui/flutter/lib/api/native/ffi/libgopeed_ffi.dart b/ui/flutter/lib/api/native/ffi/libgopeed_ffi.dart index 4b4b71e7..5f5cd022 100644 --- a/ui/flutter/lib/api/native/ffi/libgopeed_ffi.dart +++ b/ui/flutter/lib/api/native/ffi/libgopeed_ffi.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:ffi'; import 'package:ffi/ffi.dart'; @@ -13,21 +14,25 @@ class LibgopeedFFi implements LibgopeedAbi { } @override - Future create(String cfg) { + Future init(String cfg) { final cfgPtr = cfg.toNativeUtf8(); try { - final result = _libgopeed.Create(cfgPtr.cast()); - return Future.value(result.cast().toDartString()); + final result = _libgopeed.Init(cfgPtr.cast()); + if (result != nullptr) { + throw Exception( + 'Libgopeed init failed: ${result.cast().toDartString()}'); + } + return Future.value(); } finally { calloc.free(cfgPtr); } } @override - Future invoke(int instance, String params) { + Future invoke(String params) { final paramsPtr = params.toNativeUtf8(); try { - final result = _libgopeed.Invoke(instance, paramsPtr.cast()); + final result = _libgopeed.Invoke(paramsPtr.cast()); return Future.value(result.cast().toDartString()); } finally { calloc.free(paramsPtr); diff --git a/ui/flutter/lib/api/native/libgopeed_interface.dart b/ui/flutter/lib/api/native/libgopeed_interface.dart index c8f4b555..d58f8200 100644 --- a/ui/flutter/lib/api/native/libgopeed_interface.dart +++ b/ui/flutter/lib/api/native/libgopeed_interface.dart @@ -17,13 +17,15 @@ import '../model/update_extension_settings.dart'; import 'model/start_config.dart'; abstract class LibgopeedAbi { - Future create(String cfg); - Future invoke(int instance, String params); + Future init(String cfg); + Future invoke(String params); +} + +abstract class LibgopeedApiSingleton { + Future init(StartConfig config); } abstract class LibgopeedApi { - Future init(StartConfig cfg); - Future startHttp(); Future stopHttp(); diff --git a/ui/flutter/lib/main.dart b/ui/flutter/lib/main.dart index f3ccfe2a..8bd6fb64 100644 --- a/ui/flutter/lib/main.dart +++ b/ui/flutter/lib/main.dart @@ -73,10 +73,11 @@ Future init(Args args) async { final controller = Get.put(AppController()); try { - await LibgopeedBoot.instance.init(StartConfig( + final instance = await LibgopeedBoot().init(StartConfig( storage: "bolt", storageDir: Util.getStorageDir(), )); + LibgopeedBoot.singleton(instance); } catch (e) { logger.e("libgopeed init fail", e); }