ftell on a file descriptor?

孤街浪徒 提交于 2019-11-29 16:39:56

问题


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().

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


回答1:


Just use:

position = lseek(fd, 0, SEEK_CUR);


来源:https://stackoverflow.com/questions/3399236/ftell-on-a-file-descriptor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!