Stupid C...

  • Thread starter Lennon Day-Reynolds
  • Start date
L

Lennon Day-Reynolds

So, I'm stuck trying to do something clever in C, which feels kind of
like being asked to paint a portrait with ketchup and a spatula -- I'm
sure someone could do a great job with it, but I just can't get over
how awful the tools are. It's only remotely related to Ruby, but I
thought that someone around here may do enough POSIX I/O coding on a
regular basis to help.

Basically, what I'm trying to do is embed a Ruby script (along with
the normal runtime) inside a normal binary. Currently, I have it
appended to the binary itself, and the app opens argv[0], does a dup2
to replace stdin, and then initializes Ruby.

Unfortunately, I get a EINVAL on the dup2 call -- dup2(this_fh,
fileno(stdin)). I'm able to read from the same 'this_fh' file
descriptor earlier in the same code, so I know that it should be fine.
I'm also closing stdin before doing the dup2; otherwise, it appears to
become a no-op, and my binary just behaves like a normal Ruby
interpreter reading from stdin.

Anyway, if people have any suggestions, I'd greatly appreciate it. I
can post slightly longer sections of code if needed, but as I said,
it's all pretty much boilerplate ANSI C file handling.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

C programming 5
Homework in C - Help Needed 1
Three stupid C questions: ++,... 23
Lexical Analysis on C++ 1
Beginner - Chess at C 4
Three stupid C questions 16
Open WebBrowser in C# 0
Become a C++ programmer 6

Members online

Forum statistics

Threads
474,172
Messages
2,570,935
Members
47,479
Latest member
JaysonK723

Latest Threads

Top