文件描述符,文件指针,文件路径三者转换
2013-02-21 14:07
423 查看
定义
1、pathname --> fp,fd
2、fd --> fp,pathname
下面这个函数能够实现由fd转成pathname,
3、fp --> fd,pathname
由于有get_pathname_from_fd作基础,很容易实现fp->pathname,
FILE *fp; //文件指针、句柄 int fd; //文件描述符 char pathname[1024]; //文件路径
1、pathname --> fp,fd
fp = fopen(pathname,"r");
fd = open(pathname,O_RDONLY);
2、fd --> fp,pathname
fp = fdopen(fd,"r");
下面这个函数能够实现由fd转成pathname,
int get_pathname_from_fd(int fd, char pathname[], int n) { char buf[1024]; pid_t pid; bzero(buf, sizeof(buf)); pid = getpid(); snprintf(buf, sizeof(buf), "/proc/%i/fd/%i", pid, fd); return readlink(buf, pathname, n); }
3、fp --> fd,pathname
fd = fileno(fp);
由于有get_pathname_from_fd作基础,很容易实现fp->pathname,
int get_pathname_from_fp(FILE *fp, char pathname[], int n)
{
return get_pathname_from_fd(fileno(fp),pathname,n);
}
相关文章推荐
- 文件指针/句柄、文件描述符、文件路径的相互转换
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- Linux C语言 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换(完整版,收集,整理)
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换(完整版,收集,整理)
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- 文件描述符、文件句柄、文件路径的转换接口
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换
- 文件指针/句柄(FILE*)、文件描述符(fd)以及 文件路径(filepath)的相互转换(转)
- Python遍历路径下文件并转换成UTF-8编码
- C语言文件指针和文件描述符相互转换
- 文件路径以及相关字符格式转换
- Android之图片压缩和Uri与String类型的路径转换,获取图片,文件大小的工具类
- html5中将图片的绝对路径转换成文件对象