mirror of
https://github.com/rwinkhart/cmutton.git
synced 2026-08-28 04:46:46 -04:00
Add helper function for passing Go string slices to C; document some functions that won't be ported
This commit is contained in:
@@ -27,6 +27,21 @@ func getPascalStringFromBytes(goBytes []byte) C.PascalString {
|
||||
}
|
||||
}
|
||||
|
||||
// getCPascalStringArrayFromStringSlice converts a Go slice
|
||||
// of strings to a C array of pascal strings.
|
||||
func getCPascalStringArrayFromStringSlice(goSlice []string) *C.PascalString {
|
||||
// allocate C array for PascalStrings
|
||||
cArrPtr := (*C.PascalString)(C.malloc(C.size_t(len(goSlice)) * C.size_t(C.sizeof_PascalString)))
|
||||
|
||||
// populate the array with the decrypted lines
|
||||
cArr := (*[1 << 30]C.PascalString)(unsafe.Pointer(cArrPtr))[:len(goSlice):len(goSlice)]
|
||||
for i := range goSlice {
|
||||
cArr[i] = getPascalString(goSlice[i])
|
||||
}
|
||||
|
||||
return cArrPtr
|
||||
}
|
||||
|
||||
// GetPascalStringFromCString is a helper meant to be used from C.
|
||||
//
|
||||
//export GetPascalStringFromCString
|
||||
|
||||
@@ -111,11 +111,11 @@ int main() {
|
||||
- [ ] ShearRemote(vanityPath string, onlyShearAgeFile bool) error
|
||||
- [ ] RunJob() (*syncListsT, error)
|
||||
- [ ] synccommon
|
||||
- [ ] AddFolderLocal(vanityPath string) error
|
||||
- [ ] RenameLocal(oldVanityPath, newVanityPath string) error
|
||||
- [ ] ShearAgeFileLocal(vanityPath string) error
|
||||
- [ ] ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (string, bool, error)
|
||||
- [X] ~~AddFolderLocal(vanityPath string) error~~ (not for use outside of libmutton)
|
||||
- [X] ~~RenameLocal(oldVanityPath, newVanityPath string) error~~ (not for use outside of libmutton)
|
||||
- [X] ~~ShearAgeFileLocal(vanityPath string) error~~ (not for use outside of libmutton)
|
||||
- [X] ~~ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (string, bool, error)~~ (not for use outside of libmutton)
|
||||
- [ ] WalkEntryDir() ([]string, []string, error)
|
||||
- [ ] GetAllEntryData() (EntryMapT, error)
|
||||
- [X] ~~GetAllEntryData() (EntryMapT, error)~~ (not easy to port to C; also not needed)
|
||||
- [ ] syncserver
|
||||
- [ ] GetRemoteDataFromServer(clientDeviceID string)
|
||||
|
||||
@@ -4,8 +4,6 @@ package main
|
||||
// #include "types.h"
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/rwinkhart/libmutton/crypt"
|
||||
"github.com/rwinkhart/rcw/wrappers"
|
||||
)
|
||||
@@ -28,16 +26,7 @@ func DecryptFileToSlice(realPath, rcwPassword C.PascalString) (*C.char, *C.Pasca
|
||||
return nil, nil, 0
|
||||
}
|
||||
|
||||
// allocate C array for PascalStrings
|
||||
cLinesPtr := (*C.PascalString)(C.malloc(C.size_t(len(lines)) * C.size_t(C.sizeof_PascalString)))
|
||||
|
||||
// populate the array with the decrypted lines
|
||||
cLinesSlice := (*[1 << 30]C.PascalString)(unsafe.Pointer(cLinesPtr))[:len(lines):len(lines)]
|
||||
for i, line := range lines {
|
||||
cLinesSlice[i] = getPascalString(line)
|
||||
}
|
||||
|
||||
return nil, cLinesPtr, C.int(len(lines))
|
||||
return nil, getCPascalStringArrayFromStringSlice(lines), C.int(len(lines))
|
||||
}
|
||||
|
||||
// EncryptBytes returns:
|
||||
|
||||
Reference in New Issue
Block a user