在程序中有这样一行代码 write(STDOUT_fileno,buff,BUFFSIZE); 可执行到 这一行时屏幕上并没有输出任何东西 ,是那里有问题呢 ??
这段代码运行会宕掉,问题在于fileno函数异常。 现在可以采用下面任一种方法使程序正常运行,但是不明白为什么。 请大家帮忙分析一下原因,thanks。 1:不执行下面程序段,则程序正常运行。 [code] for( i = 0; i < MidFpNum; i++ ){ fclose( MidFp.fp ); }[/code] 2: 如果realloc 改为malloc 重新分配内存,(仍执行上面程序段), 程序也可以正常运行 [code] if( idx >= Alloc_MidFp ){ Alloc_MidFp = Alloc_MidFp + All...
[code]#include
举个例子,我给fileno传一个非法指针,在solaris8(gcc 2.95.2)上面程序就崩溃了。我用man看到的fileno The fileno() function returns the integer file descriptor associated with the named stream; see open(2). 不应该崩溃吧! 是不是应该给个错误返回码(例如-1)。在man里面似乎没有提到遇到错误的时候fileno函数应该如何处理,难道这就是著名的"未定义"???????? ----------------------------------------------...
刚刚开始接触Linux网络编程,看到程序里用到了STDIN_fileno,不清楚是什么意思。。。 为什么在select()前要: FD_SET (STDIN_fileno, &read_fds); 而在select()后要: if (FD_ISSET (STDIN_fileno, &read_fds)) { ... } 请问这样做的用意是什么?谢谢!
我想使用fileno()函数把fopen()函数的文件指针转换成为整型的文件描述符。但是fileno()函数总是返回一个“-1”。同样的程序在UNIX下面就很正常。真是搞不懂AS400上面的这个fileno()函数!!!
本帖最后由 一介村夫 于 2013-02-06 21:42 编辑 做了fclose(stdin)以后,如何在重新打开stdin时使得fileno(stdin)==STDIN_fileno? Linux的man文档上说: [quote]The file descriptor returned by a successful “open” call will be the lowest-numbered file descriptor not currently open for the process.[/quote] 这个算法是不是所有Unix的标准? 如果不是,那么有什么通用算法能够使得fileno(stdin)==STDIN_fileno成...