o*****e 发帖数: 379 | 1 只找到remove函数删数,但是参数是文件名。如果一个FILE指针已经打开了文件,如何
获得其打开的文件的名字呢?
或者有什么函数以FILE指针为参数删除文件?
因为是在别人的大project里面改,所以自己定义结构保存指针和文件名的pair会比较
困难。
谢谢。 |
m*****e 发帖数: 4193 | 2 In general, you can't. On Linux, you can access /proc/self/fd/x. But if you
ask this question, there is something wrong with your design.
【在 o*****e 的大作中提到】 : 只找到remove函数删数,但是参数是文件名。如果一个FILE指针已经打开了文件,如何 : 获得其打开的文件的名字呢? : 或者有什么函数以FILE指针为参数删除文件? : 因为是在别人的大project里面改,所以自己定义结构保存指针和文件名的pair会比较 : 困难。 : 谢谢。
|
l*****c 发帖数: 1153 | 3 This is defnitely the safe solution. And in cases not feasible. If other
process opens the same file, you may not be able to delete it.
you
【在 m*****e 的大作中提到】 : In general, you can't. On Linux, you can access /proc/self/fd/x. But if you : ask this question, there is something wrong with your design.
|
m*****e 发帖数: 4193 | 4 You can always delete the file. Other processes can still access it if they
already opened it. In some Unix systems (including maybe the latest Linux
kernel), there is a revoke call that closes all open file descriptors too.
【在 l*****c 的大作中提到】 : This is defnitely the safe solution. And in cases not feasible. If other : process opens the same file, you may not be able to delete it. : : you
|
l*****c 发帖数: 1153 | 5 This is true on Linux/Unix but not on all platforms, i.e. on Windows
platform, you can't delete a file if it is open.
they
【在 m*****e 的大作中提到】 : You can always delete the file. Other processes can still access it if they : already opened it. In some Unix systems (including maybe the latest Linux : kernel), there is a revoke call that closes all open file descriptors too.
|
x****u 发帖数: 44466 | 6 严格的说,Win32 API DeleteFile的实现就是在打开文件句柄的情况下设置文件属性为
关闭时删除的。
【在 l*****c 的大作中提到】 : This is true on Linux/Unix but not on all platforms, i.e. on Windows : platform, you can't delete a file if it is open. : : they
|