Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Redirect stdin to a memory buffer

1 view
Skip to first unread message

Bob Steele

unread,
Dec 29, 2000, 11:32:55 PM12/29/00
to
Does anyone know how to redirect stdin to a memory buffer in C. I am
using glibc 2.2 with GCC on a Red Had 7.0 linux box.

For example:
stdin=(FILE *)freopen("test.txt","r",stdin); correctly redirects stdin
to a file "test.txt".

However, since there is no reopen function for memory buffers, I am
forced to use;

fclose(stdin);
stdin=(FILE *)fmemopen(buffer,strlen(buffer),"r");

According to the GNU man GLIBC web pages, this should redirect stdin to
read input from the buffer. Unfortunately, this does not seem to work.
It simply returns an EOF character indicating an error condition. Oh,
fmemopen is a very new function recently introduced in the standard GNU
C libraries (glibc 2.2).

Please help,
Bob Steele
email: rst...@1stlink.net


0 new messages