473,508 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typedef struct _iobuf FILE;

I have some c code which I have acquired and would like to use,
unfortunately all the code (there is a lot of it) is expecting a passed
FILE* pointer.
The data I have is of the correct type but it is in memory. Is there a way
I can create a FILE structure and point it to the data in memory, or
generally convert my in memory data to a FILE structure?

I know that I could always save the data in memory to disk and then load it
again, to acquire the FILE structure but I would rather not.

many thanks
Nov 14 '05 #1
9 17089
Beefheart wrote:

I have some c code which I have acquired and would like to use,
unfortunately all the code (there is a lot of it) is expecting a passed
FILE* pointer.
The data I have is of the correct type but it is in memory. Is there a way
I can create a FILE structure and point it to the data in memory, or
generally convert my in memory data to a FILE structure?

I know that I could always save the data in memory to disk and then load it
again, to acquire the FILE structure but I would rather not.


Unless you have access to the source of the functions you are calling,
and can modify them to take a pointer to the data, the only portable
way I know of to pass a FILE* to the data is to write it to disk, fopen
the file, and pass a real FILE*.

There may be a platform-/compiler-specific method to do what you ask,
but I can't help you there.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody at spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+

Nov 14 '05 #2
Beefheart wrote:

I have some c code which I have acquired and would like to use,
unfortunately all the code (there is a lot of it) is expecting a passed
FILE* pointer.
The data I have is of the correct type but it is in memory. Is there a way
I can create a FILE structure and point it to the data in memory, or
generally convert my in memory data to a FILE structure?

I know that I could always save the data in memory to disk and then load it
again, to acquire the FILE structure but I would rather not.


There's nothing in ISO standard C that will allow you to do that. Any
methods will be platform-specific and off-topic here. You need a
newsgroup dedicated to your particular hardware/OS/compiler.

Possibilities to investigate include writing your own driver or a
thirdparty ramdisk solution.


Brian Rodenborn
Nov 14 '05 #3
Default User wrote:
Beefheart wrote:

I have some c code which I have acquired and would like to use,
unfortunately all the code (there is a lot of it) is expecting
a passed FILE* pointer.
The data I have is of the correct type but it is in memory. Is
there a way I can create a FILE structure and point it to the
data in memory, or generally convert my in memory data to a
FILE structure?

I know that I could always save the data in memory to disk and
then load it again, to acquire the FILE structure but I would
rather not.


There's nothing in ISO standard C that will allow you to do that.
Any methods will be platform-specific and off-topic here. You
need a newsgroup dedicated to your particular hardware/OS/compiler.

Possibilities to investigate include writing your own driver or a
thirdparty ramdisk solution.


I suspect the OP is highly confused, and needs to describe his
problems more clearly. There is no way he is allowed to create a
FILE structure. It sounds to me as if he really needs to open
some appropriate files.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #4
I have found a function called fmemopen on the http://www.gnu.org/ site,
which seems to exactly what I need and seems to be in some elusive version
of stdio.h. Only problem is I dont seem to be able to find the source code.

is this off topic, sorry newbie question?


"Beefheart" <te********@hotmail.com> wrote in message
news:nC**************@newsfe3-win.server.ntli.net...
I have some c code which I have acquired and would like to use,
unfortunately all the code (there is a lot of it) is expecting a passed
FILE* pointer.
The data I have is of the correct type but it is in memory. Is there a way I can create a FILE structure and point it to the data in memory, or
generally convert my in memory data to a FILE structure?

I know that I could always save the data in memory to disk and then load it again, to acquire the FILE structure but I would rather not.

many thanks

Nov 14 '05 #5
CBFalconer <cb********@yahoo.com> wrote in message news:<40***************@yahoo.com>...
Default User wrote:
Beefheart wrote: [request for in-memory FILE type redacted]

I suspect the OP is highly confused, and needs to describe his
problems more clearly. There is no way he is allowed to create a
FILE structure. It sounds to me as if he really needs to open
some appropriate files.


I think the OP was wondering if there's a C equivalent to the C++
stringstream construct. I don't believe there is.
Nov 14 '05 #6
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Beefheart wrote:
| I have found a function called fmemopen on the http://www.gnu.org/ site,
| which seems to exactly what I need and seems to be in some elusive version
| of stdio.h. Only problem is I dont seem to be able to find the source
code.
|
| is this off topic, sorry newbie question?
|
|

Yes, it seems it is. From the relevent section of GNU's site:

Portability Note: The facilities described in this section are specific
to GNU. Other systems or C implementations might or might not provide
equivalent functionality.

<OT>
My stdio.h does indeed contain fmemopen, but then *I* run a glibc (i.e.
GNU) operating system. If you don't, then you're probably SOL.
</OT>

Ross
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAkvHB9bR4xmappRARAmogAKCu8RnZFbRLUcu2vBG/7sfT+KXmAACg2erH
gSgLv5dqyak7N7+N/+OSlNg=
=kcWU
-----END PGP SIGNATURE-----
Nov 14 '05 #7
In article <news:Iz***************@newsfe3-win.server.ntli.net>
Beefheart <te********@hotmail.com> writes:
I have found a function called fmemopen on the http://www.gnu.org/ site,
which seems to exactly what I need and seems to be in some elusive version
of stdio.h. Only problem is I dont seem to be able to find the source code.


fmemopen() is not standard, so there is no assurance that you
have one.

I added a generalized "function-oriented" stdio interface to 4.xBSD,
which is now in NetBSD and FreeBSD. Here, rather than a specific
"open memory region" function, there is an "open these functions"
function. You provide functions that implement reading, writing,
and/or seeking -- at least one of read and write is required --
and closing, along with a "void *" value. Your provided functions
will be called to accomplish data transfers. (For optimization
purposes you are allowed to call setvbuf() to attempt to redirect
future read/write operations to specific areas of memory, but you
must be prepared for this to fail or be overridden by the user.)

Given funopen(), you can implement the equivalent of fmemopen().
You can also implement a "FILE *" stream that sits atop a compression
algorithm, or a "FILE *" stream that implements encryption, or
any other trick you like. You can stack these on top of each
other because each one is just a "FILE *":

struct compression_data {
FILE *substream;
... more data here as needed ...
};

static int compress_write(void *cookie, const char *data, int len) {
struct compression_data *p = cookie;

... do whatever it takes to compress the data and write it
to p->substream ...

return number_of_bytes_transferred; /* or -1 for error */
}

FILE *compressed_output_stream(FILE *substream) {
FILE *rv;
struct compression_data *p;

if ((p = malloc(sizeof *p)) == NULL)
return NULL;
p->substream = substream;
rv = funopen(p, NULL, compress_write, NULL, compress_close);
if (rv == NULL)
free(p);
return rv;
}

struct encryption_data {
FILE *substream;
...
};

static int encrypt_write(void *cookie, const char *data, int len) {
struct encryption_data *p = cookie;

... do whatever it takes to encrypt the data and write it
to p->substream ...
return number_of_bytes_transferred;
}

FILE *encrypted_output_stream(FILE *substream, ...) {
FILE *rv;
struct encryption_data *p;

if ((p = malloc(sizeof *p)) == NULL)
return NULL;
p->substream = substream;
... handle additional details like keys here ...
rv = funopen(p, NULL, encrypt_write, NULL, encrypt_close);
if (rv == NULL)
free(p);
return rv;
}

Now you can get an encrypted compressed file like this:

FILE *bottom, *middle, *top;

out = fopen("foo.encrypted.compressed", "w");
middle = out ? compressed_output_stream(out) : NULL;
top = middle ? encrypted_output_stream(middle, ...) : NULL;

Now ordinary fprintf()s to "top" will encrypt, then compress, then
write. (Each "close" function, not shown here, has to push any
unwritten data through, of course.) Attempts to fseek() on "middle"
and "top" will be rejected since there is no underlying seek
function. (Supporting seeks within compressed or encrypted files
is generally difficult.)

Alas, funopen() is likewise nonstandard.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #8
in comp.lang.c i read:
Beefheart wrote: | I have found a function called fmemopen | is this off topic, sorry newbie question? Yes, it seems it is. From the relevent section of GNU's site:

Portability Note: The facilities described in this section are specific
to GNU. Other systems or C implementations might or might not provide
equivalent functionality.


not only might there not be an fmemopen, if there is one there is no way to
know if it implements the same semantics, even if it takes the same number
and type of parameters and returns the same type. (in this particular
case it's hard to imagine any other semantic that fit all those conditions.)

--
a signature
Nov 14 '05 #9
in comp.lang.c i read:
I think the OP was wondering if there's a C equivalent to the C++
stringstream construct. I don't believe there is.


nothing in program memory specifically. but tmpfile() can be wonderfully
useful, and it may be that it will operate entirely in memory (whether it
actually will is off-topic for this group).

--
a signature
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
4201
by: stephen henry | last post by:
Hi all, I have a question that I'm having difficulty answering. If I have a struct: typedef struct my_struct_tag{ struct my_other_struct *other; } my_struct_tag
2
3041
by: Immo Birnbaum | last post by:
Hi, I'm trying to solve a programming lab assignment for my college C programming course, but as they taught us two semesters of Java before teaching us any C, I'm having problems with all the...
16
3810
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
7
2445
by: Dennis Myrén | last post by:
Hi. Is there any way to define an alias for a type like you could in C++: typedef int NUMBER; I tried using #define but that did not work. Thank you. -- Regards,
6
7273
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if...
15
2540
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
8
28429
by: Mohammad Omer Nasir | last post by:
Hi, i made a structure in header file "commonstructs.h" is: typedef struct A { int i; A( ) {
8
8091
by: Guillaume Dargaud | last post by:
I just saw the following two lines in /usr/include/usb.h and my head is spinning: struct usb_dev_handle; typedef struct usb_dev_handle usb_dev_handle; What is that supposed to mean ? I...
16
2747
by: mdh | last post by:
A quick ? :-) question about Typedefs. There is a very brief discussion about this in K&R ( p146). Googling this group, there is a surprising dearth of questions about these. From one of the...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.