ftell文件描述符上? [英] ftell on a file descriptor?

查看:110
本文介绍了ftell文件描述符上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法在原始文件描述符而不是FILE *上执行ftell()(返回文件中的当前位置)的作用?我认为应该有,因为您可以使用lseek()查找原始文件描述符.

Is there a way to do what ftell() does (return the current position in the file) on a raw file descriptor instead of a FILE*? I think there ought to be, since you can seek on a raw file descriptor using lseek().

我知道我可以使用fdopen()创建与文件描述符相对应的FILE *,但是我宁愿不这样做.

I know I could use fdopen() to create a FILE* corresponding to the file descriptor, but I'd rather not do that.

推荐答案

只需使用:

position = lseek(fd, 0, SEEK_CUR);

这篇关于ftell文件描述符上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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