看似一个简单的有关问题。关于文件指针

看似一个简单的问题。。。。。。。关于文件指针
本帖最后由 setoy 于 2012-12-13 20:12:53 编辑
怎么输出文件指针对应文件的文件名呢?

是linux,命令提示符下编程,文件名仅为英文字母



void output_file_name (FILE *f1, FILE *f2)
{
 //在这里输出f1的文件名,怎么搞?
}




------解决方案--------------------
这个真没见过。
------解决方案--------------------
f1不是通过文件名的得到的指针么?
------解决方案--------------------
查一下有木有什麽系統函數可用,
------解决方案--------------------
typedef struct{
fstream fs;
string file_name;
}my_fstream;
------解决方案--------------------
GetFileInformationByHandleEx
------解决方案--------------------
这个题目很。。。。。。
------解决方案--------------------
这个还真搞不定。。。。
------解决方案--------------------
引用:
引用:win7下用
GetFinalPathNameByHandle

linux下的,纯字符界面

Linux下本人没搞过。楼主参考7楼代码?
再来一个windows XP下的供参考:
//Obtaining a File Name From a File Handle
//
//GetFinalPathNameByHandle, introduced in Windows Vista and Windows Server 2008, will return a path from a handle.
//If you need to do this on earlier releases of Windows, the following example obtains a file name from a handle
//to a file object using a file mapping object. It uses the CreateFileMapping and MapViewOfFile functions to create
//the mapping. Next, it uses the GetMappedFileName function to obtain the file name. For remote files, it prints
//the device path received from this function. For local files, it converts the path to use a drive letter and prints
//this path. To test this code, create a main function that opens a file using CreateFile and passes the resulting
//handle to GetFileNameFromHandle.
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <string.h>
#include <psapi.h>
//#include <strsafe.h>

#define BUFSIZE 512

BOOL GetFileNameFromHandle(HANDLE hFile)
{
  BOOL bSuccess = FALSE;
  TCHAR pszFilename[MAX_PATH+1];
  HANDLE hFileMap;

  // Get the file size.
  DWORD dwFileSizeHi = 0;
  DWORD dwFileSizeLo = GetFileSize(hFile, &dwFileSizeHi);

  if( dwFileSizeLo == 0 && dwFileSizeHi == 0 )
  {
     _tprintf(TEXT("Cannot map a file with a length of zero.\n"));
     return FALSE;
  }

  // Create a file mapping object.