Get rid of file-based communications

I need to work with two C programs that exchange data through a file-based interface. That is, each of them has a main loop in which it polls three or four files (fopen, fscanf), responds to what it reads, and ultimately makes its own changes to the files (fprintf) to read another process.

Now I need to condense these two programs into one program with minimal changes in the program logic and in the general code. However, mainly for aesthetic reasons, I have to replace the file connection with something in my memory.

I can imagine some hacker ways to do this, but I'm sure stackoverflow will give me a hint for a nice solution :)

+3
source share
5 answers

Since you marked this Linux, I am going to suggest open_memstream. It has been added to POSIX since POSIX 2008, but it has been available on glibc-based Linux systems for a long time. This basically allows you to open FILE *, which is actually a dynamically growing buffer in memory, so you don't have to change the code. This "file" is for writing only, but you can simply use it sscanfinstead of fscanfthe buffer to read it or use it fmemopen(which does not have dynamic growth semantics, but it is very convenient for reading from buffers in memory).

+5
source

RabbitMQ - / . , . C libs, OPenAMQ.

0

Linux, /dev/shm. , - , : -)

0

, / . , ? , , , , .

0

sscanf sprintf .

-1

Source: https://habr.com/ru/post/1758330/


All Articles