开发者

Why is fileno failing to return a valid descriptor?

I'm opening a stream with funopen

FILE *fin = funopen(cookie, readfn, NULL, NULL, closefn);
if (fin == NULL)
{
    handle_error();
    return -1;
}
int fdin = fileno(fin);

The call to funopen succeeds but fileno(fin) returns -开发者_Go百科1.

How can I get the file descriptor? Thanks.


A FILE opened with funopen (which is not part of any standard, by the way; AFAIK it's a BSD extension) does not have an underlying file descriptor. It has the cookie instead. I don't know what you wanted the file descriptor for, but you're probably out of luck.


There's no file connected to funopen, and thus no fd. Try tmpfile instead if you need that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜