168. Calling the strcat() foreign function
The This function appends the Since the arguments of strcat() foreign function is part of the C standard library and has the following signature (char *strcat(char *strDestination, const char *strSource);
strSource at the end of the strDestination. The function doesn’t get these strings. It gets two pointers to these strings (so, two ADDRESS) and doesn’t return a value, so we rely on FunctionDescriptor.ofVoid(), as follows:Linker linker = Linker.nativeLinker();
SymbolLookup libLookup = linker.defaultLookup();
try (Arena arena = Arena.ofConfined()) {
MemorySegment segmentStrcat
= libLookup.find("strcat").get();
MethodHandle func = linker.downcallHandle(
segmentStrcat, FunctionDescriptor.ofVoid(
ValueLayout.ADDRESS, ValueLayout.ADDRESS));
...
strcat() are two pointers (ADDRESS), we have to create...