标准读取和写入FILE功能用于指代存储器 [英] Standard Read and Write FILE functions to refer to memory

查看:52
本文介绍了标准读取和写入FILE功能用于指代存储器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量使用标准文件函数的遗留代码。

我想传递内存指针而不是FILE指针。


我试图在代码中使用FILE来引用内存缓冲区。

基本上,我希望能够使用所有标准的读写

函数,但是我希望他们引用内存位置,而不是



文件。


我不想触及遗留代码。有没有人知道图书馆

来做这件事。我很感激帮助。


Ben Beroukhim

I have huge number of legacy code which use standard files functions.
I would like to pass a memory pointer rather than a FILE pointer.

I am trying to use FILEs in the code to refer to memory buffers.
Basically, I want to be able to use all the standard read and write
functions, but I want them to refer to memory locations, rather than
disk
files.

I do not want to touch the legacy code. Does any one know of a library
to do this. I would appreciate the help.

Ben Beroukhim

推荐答案

bb ******** @ aws.com (ben beroukhim)写道:
bb********@aws.com (ben beroukhim) writes:
我是试图在代码中使用FILE来引用内存缓冲区。基本上,我希望能够使用所有标准的读写功能,但我希望它们能够引用内存位置,而不是磁盘文件。
I am trying to use FILEs in the code to refer to memory
buffers. Basically, I want to be able to use all the standard
read and write functions, but I want them to refer to memory
locations, rather than disk files.




没有标准的方法可以做到这一点。然而,

C库的许多实现提供了允许它的扩展。你应该

参考C实现的参考手册,看看你的b
$ b。

-

int main(void){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\

\ n",* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr(); int putchar(\

); while(* q){i + = strchr(p,* q ++) - p; if(i> =(int )sizeof p)i- = sizeof p-1; putchar(p [i] \

);} return 0;}



There is no standard way to do this. Many implementations of the
C library offer extensions that allow it, however. You should
refer to the reference manual for your C implementation to see if
yours is one of them.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}


2004年11月30日11:54:01 -0800
bb********@aws.com (ben beroukhim)写道:
On 30 Nov 2004 11:54:01 -0800
bb********@aws.com (ben beroukhim) wrote:
我有大量使用标准文件函数的遗留代码。
我想传递内存指针而不是FILE指针。

我试图在代码中使用FILE来引用内存缓冲区。
基本上,我希望能够使用所有标准的读写功能,但我希望他们重新开始fer到内存位置,而不是磁盘文件。


由于C文件功能是文件功能,因此它们对文件进行操作。

我不想触及遗留代码。有没有人知道图书馆
这样做。我很感激帮助。
I have huge number of legacy code which use standard files functions.
I would like to pass a memory pointer rather than a FILE pointer.

I am trying to use FILEs in the code to refer to memory buffers.
Basically, I want to be able to use all the standard read and write
functions, but I want them to refer to memory locations, rather than
disk
files.
Since the C file functions are file functions they operate on files.
I do not want to touch the legacy code. Does any one know of a library
to do this. I would appreciate the help.




没有库可以将文件转换为文件以外的任何内容。即使这样的事情是可能的,但对于这个群体来说仍然不合适,因为

我们只讨论标准C.


< OT>

您可以在专用于您的系统的组中询问RAM磁盘。

< / OT>

-

Flash Gordon

生活在有趣的时代。

虽然我的电子邮件地址说垃圾邮件,但它是真实的,我读了它。



No library can turn files in to anything other than files. Even if such
a thing were possible, it would still be off topic for this group since
we only discuss standard C.

<OT>
You could ask in a group dedicated to your system about RAM disks.
</OT>
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


Flash Gordon< sp ** @ flash-gordon.me.uk>写道:
Flash Gordon <sp**@flash-gordon.me.uk> writes:
2004年11月30日11:54:01 -0800
bb ** ******@aws.com (ben beroukhim)写道:
On 30 Nov 2004 11:54:01 -0800
bb********@aws.com (ben beroukhim) wrote:
我有大量使用标准文件功能的遗留代码。
我想传递一个内存指针而不是一个FILE指针。

我试图在代码中使用FILE来引用内存缓冲区。
基本上,我希望能够全部使用标准的读写功能,但是我想让它们引用内存位置,而不是磁盘文件。
I have huge number of legacy code which use standard files functions.
I would like to pass a memory pointer rather than a FILE pointer.

I am trying to use FILEs in the code to refer to memory buffers.
Basically, I want to be able to use all the standard read and write
functions, but I want them to refer to memory locations, rather than
disk
files.



自C文件函数是他们对文件进行操作的文件函数。



Since the C file functions are file functions they operate on files.




当然可以,但是什么是文件?


有'没有理由C实现无法提供将

引用到内存缓冲区的方法,就好像它是一个文件一样。例如,它可以建立一个任何文件名以mem:开头的约定。将

指向内存缓冲区。


从某种意义上说,它就像询问如何使用FILE来引用文件一样

存储在硬盘上(除了几乎所有C实现之外

支持这样的接口)。


这完全是针对特定于实现的。在标准C中无法使用

来实现所有实现。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/~ kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



Sure, but what is a "file"?

There''s no reason a C implementation couldn''t provide a way to refer
to a memory buffer as if it were a file. For example, it could
establish a convention that any file name starting with "mem:" refers
to a memory buffer.

In a sense, it''s just like asking how to use FILEs to refer to files
stored on a hard drive (except that almost all C implementations
support such an interface).

This is entirely implementation-specific, of course. There''s no way
to do it in standard C that''s going to work on all implementations.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于标准读取和写入FILE功能用于指代存储器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆