I currently have a program that does the following:
It does a vfork() then executes another binary. This new binary takes its input on descriptors 0 and descriptors 1.
Meanwhile, back in my program, I open two files and I use dup2() to redirect the first file to descriptor 0 and the second file to descriptor 1.
This works very well.
What I'm trying to do now is to modify the data as it's being read from file #2. I basically need to add a line of text before the first bare \n that's being found and then send the data on its way to descriptor 1. What is the easiest/fastest way to do this ?
My only thoughts so far were to read the file, do the modification, write back to the file. Then open it back again and do the dup2() but it seems a very inefficient way to do things.