else if (code == 200) { // Downloading whole file /* Write new file (plus allow reading once we finish) */ g = fname ? fopen(fname, "w+") : tmpfile(); }
但是这个程序,只能在Unix/Linux下工作,因为 Microsoft 的?tmpfile()的实现?居然选择了 C:\ 作为临时文件的存放目录,这对于那些没有管理员权限的人来说就出大问题了,在Windows 7下,就算你有管理员权限也会有问题。所以,上面的程序在Windows平台下需要用不同的方式来处理,不能直接使用Windows的tmpfile()函数。
于是作者就先把这个问题记下来,在注释中写下了FIXME:
else if (code == 200) { // Downloading whole file /* Write new file (plus allow reading once we finish) */
// FIXME Win32 native version fails here because // Microsoft's version of tmpfile() creates the file in C:\ g = fname ? fopen(fname, "w+") : tmpfile(); }
else if (code == 200) { // Downloading whole file /* Write new file (plus allow reading once we finish) */ // FIXME Win32 native version fails here because // Microsoft's version of tmpfile() creates the file in C:\ //g = fname ? fopen(fname, "w+") : tmpfile(); if(NULL != fname) { g = fopen(fname, "w+"); } else { g = tmpfile(); } }
不能正常工作的代码 不能工作的代码
#ifdef _WIN32 # define tmpfile w32_tmpfile #endif
FILE * w32_tmpfile ( void ) { code for Windows; }
else if (code == 200) { // Downloading whole file /* Write new file (plus allow reading once we finish) */ // FIXME Win32 native version fails here because // Microsoft's version of tmpfile() creates the file in C:\ g = fname ? fopen(fname, "w+") : tmpfile(); }
也许你在一开始就看到了这个bug,但是作者没有。所有的问题都出在注释上:
/* Write new file (plus allow reading once we finish) */ // FIXME Win32 native version fails here because // Microsoft's version of tmpfile() creates the file in C:\
/* Write new file (plus allow reading once we finish) */ // FIXME Win32 native version fails here because Microsoft's version of tmpfile() creates the file in C: //g = fname ? fopen(fname, "w+") : tmpfile(); if(NULL != fname) { g = fopen(fname, "w+"); } else { g = tmpfile(); }