从文件中获取文件名* [英] Getting the file name from a FILE *

查看:86
本文介绍了从文件中获取文件名*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们正在为64位版本的lcc-win

重写libc,我们在FILE结构中添加了一个新字段:

char * FileName;

fopen()将保存文件名和访问者函数

将返回给定文件名*的文件名。


问题:


这个函数的最佳名称是什么?

char * fname(FILE *); //小写,短,类似于其他

//文件功能


//明确名称但可能太长了?

char * FileNameFromFileP(FILE *);


此功能可能出现什么问题?为什么不在C API中?


我们正在考虑扩展我们的文件函数来处理许多文件系统支持的
文件属性。我们将有两个

指针指向扩展属性和一个用户指针。指针,

即一个指针,由用户设置并带有用户

定义的数据,我们不会触及。访问者/设置者函数

将允许用户设置/检索数据。


请注意,FILE结构现在是一个完全不透明的结构。

用户无法获得FILE的定义,但是


struct __FILE;

typedef struct __FILE FILE;

-

jacob navia

jacob at jacob point remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32

解决方案

6月20日下午6:11,jacob navia< ja ... @ nospam.comwrote:




我们正在重写libc for 64位版本的lcc-win

我们在FILE结构中添加了一个新字段:

char * FileName;

fopen()将保存文件名和访问者函数

将返回文件名giv一个文件*。



它应该为tempfile(),stdin,stdout,stderr返回什么?


问题:


这个函数的最佳名称是什么?

char * fname(FILE *); //小写,短,类似于其他

//文件功能


//明确名称但可能太长了?

char * FileNameFromFileP(FILE *);


此功能可能出现什么问题?为什么不在C API中?



因为FILE不需要是一个结构。

另外,为什么不把它作为一个宏写入所有大写字母?你要做的就是

从结构中返回一个元素...


我们正在考虑扩展我们的文件函数来处理

许多文件系统支持的文件属性。我们将有两个

指针指向扩展属性和一个用户指针。指针,

即一个指针,由用户设置并带有用户

定义的数据,我们不会触及。访问者/设置者函数

将允许用户设置/检索数据。


请注意,FILE结构现在是一个完全不透明的结构。

用户无法获得FILE的定义,但是


struct __FILE;

typedef struct __FILE FILE;



我不明白最后两行...


jacob navia写道:




我们正在重写libc for 64位版本的lcc-win

我们添加了一个FILE结构中的新字段:

char * FileName;

fopen()将保存文件名和访问者函数

将返回文件名给出一个文件*。


问题:


这个函数的最佳名称是什么?

char * fname(FILE *); //小写,短,类似于其他

//文件功能


//明确名称但可能太长了?

char * FileNameFromFileP(FILE *);


此功能可能出现什么问题?为什么不在C API中?



如果文件被删除(remove()/ unlink())会发生什么,而它仍然是打开的(在POSIX中)是可能的,不确定C标准或Windowds

对此有何说法)?

在这种情况下,文件名将消失,不再存在。
< blockquote class =post_quotes>
我们正在考虑扩展我们的文件函数来处理许多文件系统支持的
文件属性。我们将有两个

指针指向扩展属性和一个用户指针。指针,

即一个指针,由用户设置并带有用户

定义的数据,我们不会触及。访问者/设置者函数

将允许用户设置/检索数据。


请注意,FILE结构现在是一个完全不透明的结构。

用户无法获得FILE的定义,但是


struct __FILE;

typedef struct __FILE FILE;



在文章< g3 ********** @ aioe.org> ;, jacob navia< ja * **@nospam.orgwrote:


>我们正在为64位版本的lcc-win重写libc
我们添加了一个新字段在FILE结构中:
char * FileName;
fopen()将保存文件名和访问器函数
将返回给定FILE *的文件名。



什么是文件名?插座或管道?由tmpnam()创建的文件

?斯坦丁?如果所有的调用程序都打开了你打开的文件,那么你可以找到几个可能的名字

来查找文件系统有真正的象征性

链接?在具有备用数据流(ADS)的系统中,

可以是具有类似于符号链接的效果的程序,或者是用于循环安装的


-

罗马人相信每个男人都有他的天才,每个男人都有她的朱诺。 - Thomas Bulfinch


Hi
We are rewriting the libc for the 64 bit version of lcc-win
and we have added a new field in the FILE structure:
char *FileName;
fopen() will save the file name and an accessor function
will return the file name given a FILE *.

Questions:

What would be the best name for this function?
char *fname(FILE *); // lower case, short, similar to other
// file functions

// clear name but maybe too long?
char *FileNameFromFileP(FILE *);

What problems could arise with this function? Why is not in the C API?

We are considering extending our file functions to handle
file attributes that many file systems support. We will have two
pointers that point to extended attributes and a "user" pointer,
i.e. a pointer that would be set by the user and would carry user
defined data that we would not touch. An accessor/setter function
would allow the user to set/retrieve data.

Note that the FILE structure is now a completely opaque structure.
No definition for FILE will be available to the user but

struct __FILE;
typedef struct __FILE FILE;
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

解决方案

On Jun 20, 6:11 pm, jacob navia <ja...@nospam.comwrote:

Hi
We are rewriting the libc for the 64 bit version of lcc-win
and we have added a new field in the FILE structure:
char *FileName;
fopen() will save the file name and an accessor function
will return the file name given a FILE *.

What should it return for tempfile(), stdin, stdout, stderr?

Questions:

What would be the best name for this function?
char *fname(FILE *); // lower case, short, similar to other
// file functions

// clear name but maybe too long?
char *FileNameFromFileP(FILE *);

What problems could arise with this function? Why is not in the C API?

Because FILE needs not to be a struct.
Also, why not just write it as a macro in all caps? All you do is
return an element from the struct anyway...

We are considering extending our file functions to handle
file attributes that many file systems support. We will have two
pointers that point to extended attributes and a "user" pointer,
i.e. a pointer that would be set by the user and would carry user
defined data that we would not touch. An accessor/setter function
would allow the user to set/retrieve data.

Note that the FILE structure is now a completely opaque structure.
No definition for FILE will be available to the user but

struct __FILE;
typedef struct __FILE FILE;

I don''t understand these last two lines...


jacob navia wrote:

Hi
We are rewriting the libc for the 64 bit version of lcc-win
and we have added a new field in the FILE structure:
char *FileName;
fopen() will save the file name and an accessor function
will return the file name given a FILE *.

Questions:

What would be the best name for this function?
char *fname(FILE *); // lower case, short, similar to other
// file functions

// clear name but maybe too long?
char *FileNameFromFileP(FILE *);

What problems could arise with this function? Why is not in the C API?

What happens if the file gets deleted (remove()/unlink()), while it is still
open (in POSIX that is possible, not sure what the C Standard nor Windowds
says about this)?
In that case the filename would have disappeared, no longer exist.

We are considering extending our file functions to handle
file attributes that many file systems support. We will have two
pointers that point to extended attributes and a "user" pointer,
i.e. a pointer that would be set by the user and would carry user
defined data that we would not touch. An accessor/setter function
would allow the user to set/retrieve data.

Note that the FILE structure is now a completely opaque structure.
No definition for FILE will be available to the user but

struct __FILE;
typedef struct __FILE FILE;



In article <g3**********@aioe.org>, jacob navia <ja***@nospam.orgwrote:

>We are rewriting the libc for the 64 bit version of lcc-win
and we have added a new field in the FILE structure:
char *FileName;
fopen() will save the file name and an accessor function
will return the file name given a FILE *.

What is the "file name" of a socket or pipe? Of a file created
by tmpnam() ? Of stdin? If all the calling program hands you is
the open file, then -which- of the several possible names for it
are you going to find for the file, in a system which has true symbolic
links? In a system which has Alternate Data Streams (ADS) that
can be programs that have effects similar to symbolic links or
to loop-back mounts?
--
"The Romans believed that every man had his Genius, and every
woman her Juno." -- Thomas Bulfinch


这篇关于从文件中获取文件名*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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