fclose()的源码是什么?那位高人能指点一下?解决思路
发布时间:2011-06-28 16:12:54 文章来源:www.iduyao.cn 采编人员:星星草
fclose()的源码是什么?那位高人能指点一下?
现在发现一个错误,可能是由于打开一个文件,而关闭两次造成了,苦于不知道fclose()的内部实现,哪位能指点一下?十分感激!
------解决方案--------------------
steedhorse(晨星)说的一点没错,而且光有fclose源码也没有,要看FILE的定义及其它相关函数
以下为small C的fclose源码:
extern int Ustatus[], Udevice[], Ufd[];
fclose(fd) int fd; {
if(!Umode(fd)) return (ERR);
if(!isatty(fd)) {
if(Umsdos(0,0,Ufd[fd],CLOFIL)==ERR)
return (ERR);
}
return (Ustatus[fd]=Udevice[fd]=NULL);
}
以下是C++ BUILDER的:
int _RTLENTRY _EXPFUNC fclose (FILE *fp)
{
int rc;
if (fp == NULL || fp-> token != (unsigned char) fp)
return(EOF); /* invalid pointer */
_lock_stream(fp);
if (fp-> bsize)
{
if (fp-> level < 0 && fflush (fp))
RETURN(EOF);
if (fp-> flags & _F_BUF)
free (fp-> buffer);
}
rc = __close (fp-> fd);
fp-> flags = 0;
fp-> bsize = 0;
fp-> level = 0;
fp-> fd = -1;
if (fp-> istemp != 0)
{
_unlink(__mkname((char *)NULL, (char *)NULL, fp-> istemp));
fp-> istemp = 0;
}
exit:
_unlock_stream(fp);
return rc;
}
------解决方案--------------------
#ifdef _MT
int __cdecl fclose (
FILE *stream
)
{
int result = EOF;
_ASSERTE(stream != NULL);
/* If stream is a string, simply clear flag and return EOF */
if (stream-> _flag & _IOSTRG)
stream-> _flag = 0; /* IS THIS REALLY NEEDED ??? */
/* Stream is a real file. */
else {
_lock_str(stream);
result = _fclose_lk(stream);
_unlock_str(stream);
}
return(result);
}
int __cdecl _fclose_lk (
FILE *str
)
{
REG1 FILE *stream;
REG2 int result = EOF;
/* Init near stream pointer */
stream = str;
#else /* _MT */
int __cdecl fclose (
FILE *str
)
{
REG1 FILE *stream;
REG2 int result = EOF;
/* Init near stream pointer */
stream = str;
if (stream-> _flag & _IOSTRG) {
stream-> _flag = 0;
return(EOF);
}
#endif /* _MT */
_ASSERTE(str != NULL);
if (inuse(stream)) {
/* Stream is in use:
(1) flush stream
(2) free the buffer
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
【★C/C++奖励基金-30期★】更新获奖书籍,请选择~ - C/C++ / 非技术区
【★C/C++奖励基金-30期★】
C/C++ 2011-12专家榜
名次...
-
C/c++ 如何按位拷贝呢?
我有一个结构体
strut st_header
{
unsigned short ver:2
unsigned short ping:1
unsgne...
-
uboot上的一点代码,没看明白!
struct in_str {
const char *p;
#ifndef __U_BOOT__
char peek_buf[2];
#endif
int __promptme;
...
-
Debug时为什么变量的地址不变?
是巧合还是某种必然. 是不是因为C中生成的可执行程序存储的地址是相对地址而不是绝对的物理地址.
...
-
关于switch语句。我不知道哪里错了,大侠帮忙bug一下
#include <stdio.h>
int main()
{
int a;
char b;
do{
printf("1.Chines...
-
#pragma section 的 $ 语法
在 ARX 头文件中间过如下三行,放在一起:
#pragma section("ARXCOMMAND$__a")
#pragma section("ARXCOMM...
-
read 问题再现
#define N 205
signed short x[N];
for(i=0;i<N;i++)
{
printf("hello boy!!\n");
...
-
征求一个C语言输入函数?
不知道大家有没有学习过Java? 现在需要一个类似Java的Scanner的函数集, 要求如下:
1. 三个函数: int rea...
-
求一道算法。一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
/*我写了一点,但是有错误,汗*/
/*
...
-
3n+1问题
求救,不知道错在哪里
#include<stdio.h>
int count(int a,int b)
{
int max=0,len=0,a1;
while(a<=b)
{
...