0

I'm trying to glue together two libraries where lib1 is providing scripts to lib2. The libraries are used in c++11 code I'm writing. I can't modify those libs.

Scripts in lib1 are embedded into the shared object with https://github.com/vector-of-bool/cmrc.

The content of each script can be accessed with an iterator, like so

cmrc::embedded_filesystem fs=cmrc::hpo::get_filesystem()
auto script1 = fs.open("script1")
# use iterator for script1...

However, lib2 function requires 'physical' file: void file(const char *);

I know I can dump content from lib1 iterator to a temp file, read it with lib2 and then remove the file. This solution sounds rather sub optimal and I'm looking for a better way.

3
  • OS-specific solutions OK? Standard C++ doesn't have many options besides that temporary file. Commented Oct 21, 2022 at 12:54
  • Yes it's fine. It must work for linux and ideally unix OS-family. Windows is really optional. Commented Oct 21, 2022 at 13:07
  • @msalters I mean I can imagine a crazy solution that is less OS specific, where you load the library in a sandbox of your own divising.... but that ends up with basically writing an entire fake os. Heh. Which just pushes the os specific stuff behind developer years of work. Commented Oct 21, 2022 at 13:09

1 Answer 1

1

While named pipes are usually used for inter-process communication, they also work intra-process. And on many Operating Systems, including Windows, they have a name that's part of the file system namespace. Hence you can usually pass a pipe name to libraries which expect file names.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you provide an example please?
@ad1v7: On Linux, you'd use mkfifo. You can create a unique name with tmpnam; if mkfifo succeeds you pass the same name to your void file(const char *);`.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.