fopen打开方式为“r+”才能正确fseek

因为fopen(3)的"a"参数非常可能导致库代码用"O_APPEND"参数调用open(2)。

解决方法先用fopen(file,"r+")打开,如果文件不存在返回NULL,再用fopen(file,"w"),fcolse()创建文件后,重新用fopen(file,"r+")打开。

参考:
http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=866761

http://blog.csdn.net/zanget/article/details/4428854

你可能感兴趣的:(fopen打开方式为“r+”才能正确fseek)