How to send and receive an image over RPC - c

I am using Sun XDR RPC in ubuntu 14. I need to send and receive an image over RPC for compression. Here is my .x file
onst MAXPARAMNAME = 9024;
typedef string prog<MAXPARAMNAME>;
struct prognames
{
prog program1;
int index;
};
program RPC_PROG {
version RPC_VERS {
string RUN_PROGS(prognames) = 1; /* procedure numer=1 */
} = 1; /* version number = 1 */
} = 0x12345678; /* program number = 0x12345678 */
Following is client file
FILE *imageN=fopen("index.jpg", "r");
char b[9024];
int i=0;
while(!feof(imageN))
{
fread(b, 1,1024,imageN );
i+=1024;
fseek( imageN,i, SEEK_SET );
}
prognames args;
args.program1 =&b;
/*remote procedure run_progs */
resultStringFromServerExecutePrograms = run_progs_1(&args, cl);
I am only mentioning that code where image is being sent.
Finally server code:
char** run_progs_1_svc(prognames *argparams, struct svc_req *arg2)
{
FILE* fpipe;
char* program1AndProgram2;
char* prog1 = argparams->program1;
static char* readPipeInto1;
readPipeInto1 = (char*)malloc((READ_MAX_SIZE + 1)*sizeof(char));
static char* readPipeInto;
readPipeInto = (char*)malloc((READ_MAX_SIZE + 1)*sizeof(char));
memset(readPipeInto, 0, READ_MAX_SIZE + 1);
program1AndProgram2=(char*)malloc((strlen(prog1))*sizeof(char));
strcpy(program1AndProgram2, argparams->program1);
//execute commands
if ( !(fpipe= (FILE*)fopen("tst.jpg","w")) )
{
perror("Cant open pipe!");
exit(1);
}
fwrite(program1AndProgram2,0,8024,fpipe);
long length;
//calculating size of file
//fread((char *)readPipeInto1, length, 1, fpipe);
fclose(fpipe);
//compression code
After running code, server side says that the file is empty. While on the client side after a while following error is generated.
localhost: RPC: Unable to receive; errno = Connection refused
Basic logic behind my code is that client reads from file stores it in the structure and then sends this structure to server (RPC). Server writes data in structure to a file and then opens that file and compresses.
But I'm not sure whether my logic is correct or not.

Related

libxml2 get xsd validation errors

I'm using xmlTextReader to process large xml files. Now i need to validate the instance against an xsd schema. The api from libxml2 is a little bit confusing, how this is done.
With my approach, im getting the validation errors in the schemaParseErrorHandler function, but without any line numbers or column numbers.
How can i get these informations?
#include <stdio.h>
#include <libxml/xmlreader.h>
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
static void schemaParseErrorHandler(void *arg, xmlErrorPtr error)
{
fprintf( stderr, "Error at line %d, column %d\n%s",
error->line, error->int2, error->message);
*((bool*)arg) = true;
}
int main( int argc, char **argv )
{
xmlInitParser();
xmlSchemaPtr schema = NULL;
xmlSchemaParserCtxtPtr schema_parser_ctxt = NULL;
int has_schema_errors = 0;
int ret = -1;
xmlSchemaValidCtxtPtr valid_ctxt = NULL;
if ((schema_parser_ctxt = xmlSchemaNewParserCtxt("example.xsd")))
{
schema = xmlSchemaParse(schema_parser_ctxt);
xmlSchemaFreeParserCtxt(schema_parser_ctxt);
if (schema)
{
valid_ctxt = xmlSchemaNewValidCtxt(schema);
}
}
xmlTextReaderPtr reader = NULL;
reader = xmlReaderForFile(filename, RPCXmlStream::STD_ENCODING, 0);
if (reader != NULL)
{
if (valid_ctxt)
{
xmlTextReaderSchemaValidateCtxt(reader, valid_ctxt, 0);
xmlSchemaSetValidStructuredErrors(valid_ctxt, schemaParseErrorHandler, &has_schema_errors);
}
ret = xmlTextReaderRead(reader);
while (ret == 1 && !has_schema_errors)
{
//... procesing informations
ret = xmlTextReaderRead(reader);
}
}
if (ret != 0)
{
xmlErrorPtr err = xmlGetLastError();
TRACE("%s: failed to parse in line %d, col %d. Error %d: %s\n",
err->file,
err->line,
err->int2,
err->code,
err->message);
}
xmlFreeTextReader(reader);
xmlCleanupParser();
return 0;
}
Another try was to use the function
xmlTextReaderSchemaValidate(reader, "example.xsd");
instead of creating an xmlSchemaNewValidCtxt, but than the programm is crashing on the first call to xmlTextReaderRead.
So how is validation done right, so that the error informations includes line and column numbers?
So, your questions got me thinking and when I looked in the libxml2 documentation,
Structure xmlError
struct _xmlError {
int domain : What part of the library raised this er
int code : The error code, e.g. an xmlParserError
char * message : human-readable informative error messag
xmlErrorLevel level : how consequent is the error
char * file : the filename
int line : the line number if available
char * str1 : extra string information
char * str2 : extra string information
char * str3 : extra string information
int int1 : extra number information
int int2 : error column # or 0 if N/A (todo: renam
void * ctxt : the parser context if available
void * node : the node in the tree
}
where we can clearly see that the xmlErrorPtr which is returned by the function xmlGetLastError() clearly contains information about the filename and the line number and the column number.
char * file : the filename
int line : the line number if available
...
int int2 : error column
So to test if this was possible or not, here is the code that I used (basically your code with minor changes to make it run on my system):
#include <stdio.h>
#include <stdbool.h>
#include <libxml/xmlreader.h>
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
static void schemaParseErrorHandler(void *arg, xmlErrorPtr error)
{
fprintf(stderr, "Error at line %d, column %d\n%s", error->line, error->int2, error->message);
*((bool*)arg) = true;
}
int main( int argc, char **argv )
{
xmlInitParser();
xmlSchemaPtr schema = NULL;
xmlSchemaParserCtxtPtr schema_parser_ctxt = NULL;
int has_schema_errors = 0;
int ret = -1;
xmlSchemaValidCtxtPtr valid_ctxt = NULL;
if ((schema_parser_ctxt = xmlSchemaNewParserCtxt("/home/junglefox/shiporder.xsd")))
{
schema = xmlSchemaParse(schema_parser_ctxt);
xmlSchemaFreeParserCtxt(schema_parser_ctxt);
if (schema)
{
valid_ctxt = xmlSchemaNewValidCtxt(schema);
}
}
xmlTextReaderPtr reader = NULL;
const char* filename = "/home/junglefox/shiporder.xml";
reader = xmlReaderForFile(filename, /*RPCXmlStream::STD_ENCODING,*/ NULL, 0);
if (reader != NULL)
{
if (valid_ctxt)
{
xmlTextReaderSchemaValidateCtxt(reader, valid_ctxt, 0);
xmlSchemaSetValidStructuredErrors(valid_ctxt, schemaParseErrorHandler, &has_schema_errors);
}
ret = xmlTextReaderRead(reader);
while (ret == 1 && !has_schema_errors)
{
//... procesing informations
ret = xmlTextReaderRead(reader);
}
}
if (ret != 0)
{
xmlErrorPtr err = xmlGetLastError();
fprintf(stdout, "%s: failed to parse in line %d, col %d. Error %d: %s\n",
err->file,
err->line,
err->int2,
err->code,
err->message);
}
xmlFreeTextReader(reader);
xmlCleanupParser();
return 0;
}
where, the shiporder.xml and shiporder.xsd used in that program were copied from the url and saved locally.
I compiled and ran the code like this:
junglefox#ubuntu:~$ gcc -o test_xsd main.c -I/usr/include/libxml2/ -lxml2 -L/usr/lib/x86_64-linux-gnu/
junglefox#ubuntu:~$ ./test_xsd
junglefox#ubuntu:~$
The output this time was nothing. As it should be as there were no errors.
If however now I make an intentional error in the shiporder.xml file, as shown below:
Here is the partial-snippet from the buggy shiporder.xml:
<?xml version="1.0" encoding="UTF-8"?>
...
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
price>9.90</price>
</item>
</shiporder>
Notice the missing < before price!
Now I run the program again,
junglefox#ubuntu:~$ ./test_xsd
Error at line 22, column 0
Element 'item': Character content other than whitespace is not allowed because the content type is 'element-only'.
which answers your question(s):
With my approach, im getting the validation errors in the schemaParseErrorHandler function, but without any line numbers or column numbers. How can i get these informations?
and,
So how is validation done right, so that the error informations includes line and column numbers?
as the output clearly shows the line number 22 and column 0, where there was an unexpected empty space due to the missing <.

Receiving AT commands

I'm using a microcontroller to communicate with a SIM808 module and I want to send and receive AT commands.
The problem right now is that for some commands I receive only some portions of the answers I should receive, but for some others I receive what I should. For example, if I shut down the module I receive "NORMAL POWER DOWN", as expected.
I believe I'm receiving everything, I'm just not being capable of seeing it. I receive the beginning and the end of the response, so the problem should be on the way I parse and buffer. I'm using a FIFO buffered RXC interrupt.
For example, for the command "AT+CBC" I should receive something like:
"
+CBC: 1,96,4175
OK
"
But I receive "+CBC1,4130OK"
(I replaced the unreadable characters with a dot)
bool USART_RXBufferData_Available(USART_data_t * usart_data)
{
/* Make copies to make sure that volatile access is specified. */
uint8_t tempHead = usart_data->buffer.RX_Head;
uint8_t tempTail = usart_data->buffer.RX_Tail;
/* There are data left in the buffer unless Head and Tail are equal. */
return (tempHead != tempTail);
}
uint8_t USART_receive_array (USART_data_t * usart_data, uint8_t * arraybuffer)
{
uint8_t i = 0;
while (USART_RXBufferData_Available(usart_data))
{
arraybuffer[i] = USART_RXBuffer_GetByte(usart_data);
++i;
}
return i;
}
void USART_send_array (USART_data_t * usart_data, uint8_t * arraybuffer, uint8_t buffersize)
{
uint8_t i = 0;
/* Wait until it is possible to put data into TX data register.
* NOTE: If TXDataRegister never becomes empty this will be a DEADLOCK. */
while (i < buffersize)
{
bool byteToBuffer;
byteToBuffer = USART_TXBuffer_PutByte(usart_data, arraybuffer[i]);
if(byteToBuffer)
{
++i;
}
}
}
void send_AT(char * command){
uint8_t TXbuff_size = strlen((const char*)command);
USART_send_array(&expa_USART_data, (uint8_t *)command, TXbuff_size);
fprintf(PRINT_DEBUG, "Sent: %s\n\n", command);
}
void receive_AT(uint8_t *RXbuff){
memset (RXbuff, 0, 100);
uint8_t bytes = 0;
bytes = USART_receive_array(&expa_USART_data, RXbuff);
int n;
if (bytes>0)
{
RXbuff[bytes]=0;
for (n=0;n<bytes;n++)
{
if (RXbuff[n]<32)
{
RXbuff[n]='.';
}
}
}
fprintf(PRINT_DEBUG, "Received: %s\n\n", RXbuff);
}
int main(){
unsigned char RXbuff[2000];
send_AT("ATE0\r\n");
receive_AT(RXbuff);
send_AT("AT\r\n");
receive_AT(RXbuff);
send_AT("AT+IPR=9600\r\n");
receive_AT(RXbuff);
send_AT("AT+ECHARGE=1\r\n");
receive_AT(RXbuff);
send_AT("AT+CBC\r\n");
_delay_ms(2000);
receive_AT(RXbuff);
send_AT("AT+CSQ\r\n");
_delay_ms(2000);
receive_AT(RXbuff);
}
So, the problem didn't have to do with this part of the code. I am using an emulated serial port to print stuff from the micro-controller to the PC. The issue was that the rate with which I was printing a char to the PC was much faster than what the PC was receiving, that's why some parts didn't appear.

Using KissFFT on a wave file

I am trying to use the KissFFT Library with this 11 second 44kHz .wav sample file as a test input.
However as I process the file with a window size of 512, I am getting only 1 output value. Which is weird, the 11 sec .wav file at 44kHz should not give 1 value as an output with a windows size of 512. A smaller windows like 16 would give me 5 values, which is still a low count.
Does anyone know what I am doing wrong?
This is my code:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <math.h>
#include "kiss_fft.h"
#define WIN 512
int main()
{
char *music_file = "C:/MSin44W16-13.wav";
FILE *in;
char buf[WIN * 2];
int nfft = WIN, i, fx;
double intensity = 0;
kiss_fft_cfg cfg;
kiss_fft_cpx cx_in[WIN];
kiss_fft_cpx cx_out[WIN];
short *sh;
cfg = kiss_fft_alloc(nfft, 0, 0, 0);
in = fopen(music_file, "r");
if (!in) {
printf("unable to open file: %s\n", music_file);
perror("Error");
return 1;
}
fx = 0;
while (fread(buf, 1, WIN * 2, in))
{
for (i = 0;i<WIN;i++) {
sh = (short *)&buf[i * 2];
cx_in[i].r = (float) (((double)*sh) / 32768.0);
cx_in[i].i = 0.0;
}
kiss_fft(cfg, cx_in, cx_out);
//Display the value of a position
int position = 511;
intensity = sqrt(pow(cx_out[position].r, 2) + pow(cx_out[position].i, 2));
printf("%9.4f\n", intensity);
//Display all values
/*
for (i = 0;i<WIN;i++) {
//printf("Joe: cx_out[i].r:%f\n", cx_out[i].r);
//printf("Joe: cx_out[i].i:%f\n", cx_out[i].i);
intensity = sqrt(pow(cx_out[i].r,2) + pow(cx_out[i].i,2));
printf("%d - %9.4f\n", i, intensity);
}
*/
}
free(cfg);
scanf("%d");
return 0;
}
This is the output I get:
42.7577
This is the Updated Code version, but I am getting errors at compile:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <math.h>
#include "kiss_fft.h"
#include "sndfile.h"
#define WIN 512
int main()
{
char *music_file = "C:/voice.wav";
SNDFILE *infile;
SF_INFO sfinfo;
//int readcount;
short buf[WIN * 2];
int nfft = WIN;
double intensity = 0;
kiss_fft_cfg cfg;
kiss_fft_cpx cx_in[WIN];
kiss_fft_cpx cx_out[WIN];
short *sh;
cfg = kiss_fft_alloc(nfft, 0, 0, 0);
if (!( infile = sf_open(music_file, SFM_READ, &sfinfo) ))
{ /* Open failed so print an error message. */
printf("Not able to open input file %s.\n", "input.wav");
/* Print the error message fron libsndfile. */
sf_perror(NULL);
return 1;
}
while ((sf_read_short(infile, buf, WIN)))//fread(buf, 1, WIN * 2, in)
{
//system("cls");
for (int i = 0;i<WIN;i++) {
sh = (short *)&buf[i * 2];
cx_in[i].r = (float) (((double)*sh) / 32768.0);
cx_in[i].i = 0.0;
}
kiss_fft(cfg, cx_in, cx_out);
//Display the value of a position
int position = 511;
intensity = sqrt(pow(cx_out[position].r, 2) + pow(cx_out[position].i, 2));
printf("%9.4f\n", intensity);
//Display all values
/*
for (i = 0;i<WIN;i++) {
//printf("Joe: cx_out[i].r:%f\n", cx_out[i].r);
//printf("Joe: cx_out[i].i:%f\n", cx_out[i].i);
intensity = sqrt(pow(cx_out[i].r,2) + pow(cx_out[i].i,2));
printf("%d - %9.4f\n", i, intensity);
}
*/
}
sf_close(infile);
free(cfg);
int temp;
scanf_s("%d", &temp);
return 0;
}
I followed the steps on this post:
"error LNK2019: unresolved external symbol" error in Visual Studio 2010
And I still get these errors:
The problem does not comes from KissFFT, but rather from the fact that you are trying to read a binary wave file opened in ASCII mode on the line:
in = fopen(music_file, "r");
As you later try to read data with fread you eventually hit an invalid character. In your specific sample file, the 215th character read is the Substitute Character (hex value 0x1A), which is interpreted as an end of file marker by your C runtime library. Correspondingly, fread stops filling in more data and eventually return 0 (at the second iteration with WIN set to 512 and a little later with WIN set to 16).
To get around this problem, you should open the file in binary more with:
in = fopen(music_file, "rb");
Note that this will ensure the binary data is read as-is into your input buffer, but would not decode the wave file header for you. To properly read and decode a wave file and get meaningful data in, you should look into using an audio library (such as libsndfile to name one). If you must roll your own wave file reader you should read the specifications and/or check out one of many tutorials on the topic.

File access control in linux

I`m writing a module to control file access. I'm now trying to implement the prohibition of file opening. I've already tried are kernel module system open overload: http://pastebin.com/JWKbpFYT
I've also tried system read overload: http://pastebin.com/psK8vX41
The problem in the first one is that I could restrict access to target file only in console (it didn't work in graphical interface, e.g. gedit).
The second one didn't work as the system stopped responding on running gedit with target file.
How can I prohibit file opening without using SELinux?
asmlinkage int custom_open(const char __user *file_name, int flags, mode_t mod)
{
printk("hook: open(\"%s\")", file_name);
if (!strcmp(file_name, "test"))
return -1;
return original_open(file_name, flags, mod);
}
struct file *fget(unsigned int fd)
{
struct file *file;
struct files_struct *files = current->files;
rcu_read_lock();
file = fcheck_files(files, fd);
if (file) {
/* File object ref couldn't be taken */
if (file->f_mode & FMODE_PATH ||
!atomic_long_inc_not_zero(&file->f_count))
file = NULL;
}
rcu_read_unlock();
return file;
}
asmlinkage int custom_read(int fd, void *buf, size_t noct)
{
struct file *filp = fget(fd);
unsigned char f_name[DNAME_INLINE_LEN];
strcpy(f_name,filp->f_path.dentry->d_name.name);
if (!strcmp(f_name, "_ttt.c")){
printk("hook1: read fd=(%d: -> %s)\n",fd,f_name);
return -1;
}
return original_read(fd, buf, noct);
}

Shared library function does working correctly after first dlopen

I am creating a websocket server in C. Since taking a server down, recompiling it, and running it again is counterproductive to what a server app should do, I am looking for ways to dynamically load in my functions so that I can keep the main server app running while being able to alter / create new functions that will be used in it. I created a function that allows me to call a function by name with correct arguments like you would a normal function call, but when I go to call it the second time it does not do the same thing the second time I call it dynamically. To lay out my problem by steps, consider the following situations:
Situation 1
Start server application without calling sendMessage dynamically.
Connect to the websocket server via browser.
After successful connection send a message to the server (I use Hello World)
Server will echo the message the client sent.
Send the same message to the server again.
Server will echo message again. (this is when the server sendMessage function is not loaded dynamically
Repeating steps 5 and 6 will not cause the client to disconnect.
Now for the situation using a dynamic version of the servers sendMessage function to echo the client message.
Situation 2
Start server application while allowing sendMessage to be called using loadFunction.
Connect to the websocket server via browser.
After successful connection send a message to the server (again I use Hello World)
Server will echo the message the client sent like it should.
Send the same message to the server again.
This time the server does not echo the message the client sent.
Sending more messages after the first will eventually cause the connection to end (This is where I am having a problem
Situation 1 is when my function sendMessage is called normally (not through loadFunction) while situation 2 is where I replace sendMessage with my loadFunction call that loads the library holding sendMessage, assigns it to a location function variable (see code) and call the function like it would normally.
I am thinking that the problem lies with the write function in sendMessage when I dynamically load it. But the function works perfectly when I don't load it dynamically which is odd to me.
My question is why is why would my sendMessage function operate differently from when I call it normally and when I call it dynamically? Below is some code and output from both situations
sendMessage.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include "include/structs.h"
//#include "include/functions.h"
/*
* sendMessage: this function is used then we want to send message (s)
* of length (len) from the server to a client (sock)
*
* ARGUMENTS
* sock: the socket where we want the message to go
* s: A string containing the message we want to send
* len: the length of the string s
*/
void *sendMessage(int sock, char *s, int len) {
int frameCount;
uint16_t len16;
char frame[10];
char *reply = malloc(sizeof(char) * (len + 8));
frame[0] = '\x81';
if (len <= 125) {
frame[1] = len;
frameCount = 2;
} else if (len >= 126 && len <= 65535) {
frame[1] = 126;
len16 = htons(len);
memcpy(frame + 2, &len16, 2);
frameCount = 4;
} else {
frame[1] = 127;
//NOTE: HAVE NOT FULLY CONFIGURED A MESSAGE OF THIS LENGTH (TODO)
//frame[2] = (char)( ((char)len >> 56) & (char)255 );
//frame[3] = (char)( ((char)len >> 48) & (char)255 );
//frame[4] = (char)( ((char)len >> 40) & (char)255 );
//frame[5] = (char)( ((char)len >> 32) & (char)255 );
//frame[6] = (char)( ((char)len >> 24) & (char)255 );
frame[7] = (char)( ((char)len >> 16) & (char)255 );
frame[8] = (char)( ((char)len >> 8) & (char)255 );
frame[9] = (char)( ((char)len) & (char)255 );
frameCount = 10;
}//END IF
memcpy(reply, frame, frameCount);
memcpy(reply + frameCount, s, len);
//printf("sock: %d\ts: %s\tlen: %d\n", sock, s, len);
if (write(sock, reply, strlen(reply)) <= 0) {
printf("\n\nWE ARE NOT WRITING!!\n\n");
} else {
//printf("we did write\n");
}//END IF
free(reply);
reply = NULL;
return NULL;
}//END FUNCTION
loadFunction.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include "include/functions.h"
int checkForError(char *error) {
if (error != NULL) {
printf("ERROR: %s\n", error);
exit(EXIT_FAILURE);
}//END IF
return 0;
}//END IF
void * loadFunction(char *func, void ** args) {
void *handle;
//void * (*alterStruct)(int sock, char *action);
int filenameLength;
char * filename;
//void *(*funcPtr);
filenameLength = strlen("lib/lib") + strlen(func) + strlen(".dll");
filename = malloc(sizeof(char) * (filenameLength + 1));
strcpy(filename, "lib/lib");
strcat(filename, func);
strcat(filename, ".dll");
handle = dlopen(filename, RTLD_LAZY);
free(filename);
if (!handle) {
checkForError(dlerror());
}//END IF
dlerror();
if (strncmp(func, "sendMessage", strlen(func)) == 0) {
void * (*funcPtr)(int, char *, int);
//*(void **) (&funcPtr) = dlsym(handle, func);
funcPtr = (void *)dlsym(handle, func);
checkForError(dlerror());
(*funcPtr)((int)args[0], (char *)args[1], (int)args[2]);
//free(*(void **)(&funcPtr));
//*(void **) (&funcPtr) = NULL;
}// else if (strncmp(func, "alterStruct", strlen(func)) == 0) {
//void * (*funcPtr)(int sock, char *action);
//} else if (strncmp(func, "execute", strlen(func)) == 0) {
//void * (*funcPtr)(const char *command, clientStruct s, FILE **in, FILE **out, FILE **err);
//} else {
//void * (*funcPtr)(int sock, char *s, int len);
//}//END IF
dlclose(handle);
handle = NULL;
return NULL;
return NULL;
}//END loadFunction
If you need more code to solve this problem I have it accessable on GitHub here (the dynamic branch is where the problem can be found)
Also, I am using Cygwins' GNU gcc compiler (which I have never have a problem compiling on) to compile my application and libraries so I may not have access to certain Linux commands (for example dlmopen). That said, please do not say use a different compiler because I've had no other problems thus far and I do not intend on changing how I compile my code.
I did not document the command I use to compile just the libsendMessage.dll used in loadFunction. you can obtain it using the following
gcc -c -fPIC sendMessage.c
mv sendMessage.o objects/sendMessage.o
gcc -shared -o lib/libsendMessage.dll objects/sendMessage.o libfunctions.c
Thank you in advance.
I have figured out my problem and it is quite an odd one.
When i was testing the sendMessage function using my dynamic method i printf exactly what was being sent through the socket and apparently it was sending the correct message. However, it was also sending the characters from my filename variable in the loadFunction function which to me is strange that the memory address was accessable to sendMessage when it was malloced, freed and set to NULL way before the function call to the dynamic sendMessage was called.
Solution
After I opened my library with dlopen(filename, RTLD_LAZY) I used memset(filename, '\0', filenameLength) to write null characters to the memory address of filename making the string contain all null characters which when accessed as a character counts as a end of string.
I'm not sure why I am having to use memset so much in this application but i know that it has fixed string bugs for me multiple times.

Resources