Port crypt package

This commit is contained in:
2026-01-21 19:05:46 -05:00
parent a72be0393c
commit d24202f63b
7 changed files with 144 additions and 34 deletions
+25 -6
View File
@@ -1,12 +1,10 @@
package main
/*
typedef struct {
char* data;
int len;
} PascalString;
*/
// #include <string.h>
// #include <stdlib.h>
// #include "types.h"
import "C"
import "unsafe"
// getPascalString returns a pascal
// string struct for the input Go string.
@@ -28,3 +26,24 @@ func getPascalStringFromBytes(goBytes []byte) C.PascalString {
len: C.int(len(goBytes)),
}
}
// GetPascalStringFromCString is a helper meant to be used from C.
//
//export GetPascalStringFromCString
func GetPascalStringFromCString(cString *C.char) C.PascalString {
return C.PascalString{
data: cString,
len: C.int(C.strlen(cString)),
}
}
// FreeArray frees the memory allocated by a C-allocated array.
//
//export FreeArray
func FreeArray(items *C.PascalString, count C.int) {
linesSlice := (*[1 << 30]C.PascalString)(unsafe.Pointer(items))[:count:count]
for i := 0; i < int(count); i++ {
C.free(unsafe.Pointer(linesSlice[i].data))
}
C.free(unsafe.Pointer(items))
}