0

The dlopen prototype: void *dlopen(const char *filename, int flag);

What I need is: void *dlopen(const char *pBufferWithSoContents, int flag);

I don't want to store the library.so in a filesystem. I want to store it in a memory buffer, not in a files system. Anyone know of any solutions I could use?

MatchPoint
  • 81
  • 3

1 Answers1

0
void *dlopen(const char *pBufferWithSoContents, int size, int flag) {

FILE* handle = fopen("lib.tmp", "w");

fwrite(pBufferWithSoContents, sizeof(char), size, handle);

fclose(handle);

void * ptr = dlopen("lib.tmp", flag);

remove("lib.tmp"); // Tmp file delete it.

return ptr;

}

I must admit not tested but essentially create a tmp file. You said its in memory but not in hard disk just temporarily save it on the disk load it using the dlopen posix call and just delete the temporary file.

Daniel Lopez
  • 1,728
  • 3
  • 24
  • 40
  • 1
    You are still writing the lib to the file system by storing it lib.tmp, albeit briefly. – MatchPoint Apr 14 '15 at 23:53
  • That is the point there is no way you can load it in memory. If you can answer my question why can't you just temporarily store it on the disk? Is there some performance gain, I would not think not. – Daniel Lopez Apr 15 '15 at 00:41