Article View: comp.unix.programmer
Article #834Re: File pointer to a memory location?
From: Larry Wall
Date: Tue, 11 Sep 1990 01:54
Date: Tue, 11 Sep 1990 01:54
40 lines
1783 bytes
1783 bytes
In article <119609@linus.mitre.org> rtidd@ccels3.mitre.org (Randy Tidd) writes:
: What I do now is query the database, get a block of memory, dump this
: memory to a temporary file, open the file with a file pointer, and
: pass the file pointer to the image processing routines. Not only is
: this dumb, but images can be a big as 3 megs and this is incredibly
: inefficient.
:
: Can anyone help me out?
It *definitely* counts as cheating, and it's not entirely portable, but
if you're desperate you can generally do something like this:
#include <stdio.h>
main()
{
char *string = "Now is the time\nfor all good men\nto come to.\n";
FILE *fake = fopen("/dev/null", "r");
char buf[512];
fake->_ptr = string; /* pointer to your memory */
fake->_cnt = strlen(string); /* length of your memory */
/* test it */
while (fgets(buf,512,fake)) {
fputs(buf,stdout);
}
}
As soon as the _cnt runs down, it resets _ptr back to _base and refills
from the fd that's connected to /dev/null, so you get EOF.
If this doesn't work, look in /usr/include/stdio.h to see what the fields
are actually called.
Like I said, it's cheating. But then again, many versions of sprintf()
do the same thing in reverse.
Larry
Technical Details
Message-ID:
<9455@jpl-devvax.JPL.NASA.GOV>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwallReferences:
<119609@linus.mitre.org>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.programmer Subject: Re: File pointer to a memory location? Message-ID: <9455@jpl-devvax.JPL.NASA.GOV> Date: 11 Sep 90 01:54:54 GMT References: <119609@linus.mitre.org> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 40