I'm trying to use function fgets, but it always reads from standard input.
Here is the test code:
{ FILE *reg_file = fopen("1.txt", "r"); if (!reg_file) { perror(""); printf("Can't open file "%s"\n", "1.txt"); exit(1); } { char buf[100]; while (fgets(buf, 100, reg_file)) { printf("%s", buf); } exit(1); } }
The same code works correctly when compiled without Wine. One starange thing here that I do not see call to function fopen in the log. End of the log for the test application, called with --debugmsg +all, critical sections call are removed (note, the mail client wrapped the lines)
0806eff8:Call kernel32.GetCommandLineA() ret=40021019 0806eff8:Ret kernel32.GetCommandLineA() retval=40350358 ret=40021019 0806eff8:Call kernel32.GetStartupInfoA(405a6e4c) ret=40021039 0806eff8:Ret kernel32.GetStartupInfoA() retval=400c6934 ret=40021039 0806eff8:Call ntdll.__wine_get_main_args(40024ea4) ret=40021053 0806eff8:Ret ntdll.__wine_get_main_args() retval=00000001 ret=40021053 0806eff8:Call kernel32.GetModuleHandleA(00000000) ret=4002106a 0806eff8:Ret kernel32.GetModuleHandleA() retval=40020000 ret=4002106a 0806eff8:Call msvcrt.fgets(405a6db4 "\344\307\016@",00000064,08050f70) ret=4001e21b 0806eff8:trace:msvcrt:MSVCRT_fgets :file(0x8050f70) fd (0) str (0x405a6db4) len (100) 0806eff8:Call kernel32.ReadFile(00000004,405a6bbf,00000001,405a6b98,00000000) ret=406878e6 0806eff8:trace:file:ReadFile 4 0x405a6bbf 1 0x405a6b98 (nil) 0806eff8: get_handle_fd( handle=4, access=80000000 ) 0806eff8: *fd* 4 -> 8 0806eff8: get_handle_fd() = 0 { fd=-1, type=1, flags=0 } 0806eff8: set_handle_info( handle=4, flags=0, mask=0, fd=10 ) 0806eff8: set_handle_info() = 0 { old_flags=1, cur_fd=10 }
#here I entered line with character W
0806eff8:Ret kernel32.ReadFile() retval=00000001 ret=406878e6 0806eff8:Call kernel32.ReadFile(00000004,405a6bbf,00000001,405a6b98,00000000) ret=406878e6 0806eff8:trace:file:ReadFile 4 0x405a6bbf 1 0x405a6b98 (nil) 0806eff8: get_handle_fd( handle=4, access=80000000 ) 0806eff8: get_handle_fd() = 0 { fd=10, type=1, flags=0 } 0806eff8:Ret kernel32.ReadFile() retval=00000001 ret=406878e6 0806eff8:trace:msvcrt:MSVCRT_fgets :got 'W ' 0806eff8:Ret msvcrt.fgets() retval=405a6db4 ret=4001e21b 0806eff8:Call kernel32.WriteFile(00000008,405a646c,00000002,405a6428,00000000) ret=4068818b 0806eff8:trace:file:WriteFile 8 0x405a646c 2 0x405a6428 (nil) 0806eff8: get_handle_fd( handle=8, access=40000000 ) 0806eff8: *fd* 8 -> 9 0806eff8: get_handle_fd() = 0 { fd=-1, type=1, flags=0 } 0806eff8: set_handle_info( handle=8, flags=0, mask=0, fd=11 ) 0806eff8: set_handle_info() = 0 { old_flags=1, cur_fd=11 } 0806eff8:Ret kernel32.WriteFile() retval=00000001 ret=4068818b 0806eff8:Call msvcrt.fgets(405a6db4 "W\n",00000064,08050f70) ret=4001e21b 0806eff8:trace:msvcrt:MSVCRT_fgets :file(0x8050f70) fd (0) str (0x405a6db4) len (100) 0806eff8:Call kernel32.ReadFile(00000004,405a6bbf,00000001,405a6b98,00000000) ret=406878e6 0806eff8:trace:file:ReadFile 4 0x405a6bbf 1 0x405a6b98 (nil) 0806eff8: get_handle_fd( handle=4, access=80000000 ) 0806eff8: get_handle_fd() = 0 { fd=10, type=1, flags=0 }
#here I entered ^D to close stdin
0806eff8:Ret kernel32.ReadFile() retval=00000001 ret=406878e6 0806eff8:trace:msvcrt:_read :EOF 0806eff8:trace:msvcrt:MSVCRT_fgets :nothing read 0806eff8:Ret msvcrt.fgets() retval=00000000 ret=4001e21b 0806eff8:Call msvcrt.exit(00000001) ret=4001e229 0806eff8:trace:msvcrt:MSVCRT_exit (1) 0806eff8:trace:msvcrt:_lock (13) 0806eff8:trace:msvcrt:_lock (17) 0806eff8:trace:msvcrt:_lock : creating lock #13 0806eff8:trace:msvcrt:_unlock (17) 0806eff8:trace:msvcrt:__MSVCRT__call_atexit 0 atext functions to call 0806eff8:trace:msvcrt:_unlock (13) 0806eff8:Call kernel32.ExitProcess(00000001) ret=40686022 0806eff8:trace:module:MODULE_InitDLL (regedit,PROCESS_DETACH,0x1) - CALL 0806eff8:trace:module:MODULE_InitDLL (0x403509b0,PROCESS_DETACH,0x1) - RETURN 1 0806eff8:trace:module:MODULE_InitDLL (msvcrt.dll,PROCESS_DETACH,0x1) - CALL 0806eff8:Call PE DLL (proc=0x4068b1c0,module=4067c000,type=0,res=0x1) 0806eff8:trace:msvcrt:MSVCRT_Init (0x4067c000, DLL_PROCESS_DETACH, 0x1) pid(134659496), tid(134672376), tls(0) 0806eff8:trace:msvcrt:msvcrt_free_mt_locks : uninitializing all mtlocks 0806eff8:trace:msvcrt:_fcloseall :closed (0) handles 0806eff8:trace:msvcrt:msvcrt_free_console :Closing console handles 0806eff8:Call kernel32.CloseHandle(00000004) ret=406810d3 0806eff8: close_handle( handle=4 ) 0806eff8: close_handle() = 0 { fd=10 } 0806eff8:Ret kernel32.CloseHandle() retval=00000001 ret=406810d3 0806eff8:Call kernel32.CloseHandle(ffffffff) ret=406810de 0806eff8: close_handle( handle=-1 ) 0806eff8: close_handle() = INVALID_HANDLE { fd=0 } 0806eff8:Ret kernel32.CloseHandle() retval=00000000 ret=406810de 0806eff8:Call kernel32.FreeEnvironmentStringsA(403504b0) ret=406832ef 0806eff8:Ret kernel32.FreeEnvironmentStringsA() retval=00000001 ret=406832ef 0806eff8:Call kernel32.FreeEnvironmentStringsW(403513d0) ret=406832fa 0806eff8:trace:heap:RtlFreeHeap (40350000,00000002,403513d0): returning TRUE 0806eff8:Ret kernel32.FreeEnvironmentStringsW() retval=00000001 ret=406832fa 0806eff8:Call kernel32.TlsFree(00000000) ret=4068b545 0806eff8:Ret kernel32.TlsFree() retval=00000001 ret=4068b545 0806eff8:trace:msvcrt:MSVCRT_Init finished process free 0806eff8:Ret PE DLL (proc=0x4068b1c0,module=4067c000,type=0,res=0x1) retval=1 0806eff8:trace:module:MODULE_InitDLL (0x40350d1c,PROCESS_DETACH,0x1) - RETURN 1 0806eff8:trace:module:MODULE_InitDLL (advapi32.dll,PROCESS_DETACH,0x1) - CALL 0806eff8:trace:module:MODULE_InitDLL (0x40350bf0,PROCESS_DETACH,0x1) - RETURN 1 0806eff8:trace:module:MODULE_InitDLL (kernel32.dll,PROCESS_DETACH,0x1) - CALL 0806eff8:Call PE DLL (proc=0x406247fc,module=40615000,type=0,res=0x1) 0806eff8:Ret PE DLL (proc=0x406247fc,module=40615000,type=0,res=0x1) retval=1 0806eff8:trace:module:MODULE_InitDLL (0x40350e2c,PROCESS_DETACH,0x1) - RETURN 1 0806eff8:trace:module:MODULE_InitDLL (ntdll.dll,PROCESS_DETACH,0x1) - CALL 0806eff8:trace:module:MODULE_InitDLL (0x403508ac,PROCESS_DETACH,0x1) - RETURN 1 0806eff8: terminate_process( handle=-1, exit_code=1 ) 0806eff8: terminate_process() = 0 { self=1 } 0806eff8: *killed* exit_code=1 /home/apalamarchuk/.wine/user.reg: saving key \User\apalamarchuk /home/apalamarchuk/.wine/system.reg: saving key \Machine /home/apalamarchuk/.wine/userdef.reg: saving key \User\.Default Server: exiting (pid=9451)
The bug, probably, is very simple and somebody can give me a clue basing on the trace.
I have fresh CVS Wine.
Thanks, Andriy Palamarchuk
__________________________________________________ Do You Yahoo!? Try FREE Yahoo! Mail - the world's greatest free email! http://mail.yahoo.com/
On Mon, 11 Mar 2002, Andriy Palamarchuk wrote:
I'm trying to use function fgets, but it always reads from standard input.
I can't duplicate your results.
---cat.c--- #include <stdio.h> #include <stdlib.h> int main() { FILE *reg_file = fopen("1.txt", "r"); if (!reg_file) { perror(""); printf("Can't open file "%s"\n", "1.txt"); exit(1); } { char buf[100]; while (fgets(buf, 100, reg_file)) { printf("%s", buf); } exit(1); } }
---cat.spec--- name cat type win32 mode cuiexe init main
import kernel32.dll import ntdll.dll import msvcrt.dll
I used winemaker on the source, then added msvcrt.dll to the spec.
[whit@giftie cat]$ ./cat No such file or directory Can't open file "1.txt" [whit@giftie cat]$ echo 1.txt >'1.txt' [whit@giftie cat]$ ./cat 1.txt [whit@giftie cat]$ echo high their >'1.txt' [whit@giftie cat]$ ./cat high their
Lawson
Probable user head space error. - Dennis A. Moore
________________________________________________________________ GET INTERNET ACCESS FROM JUNO! Juno offers FREE or PREMIUM Internet access for less! Join Juno today! For your FREE software, visit: http://dl.www.juno.com/get/web/.
On Mon, 11 Mar 2002, Andriy Palamarchuk wrote:
I'm trying to use function fgets, but it always reads from standard input.
Here is the test code:
Here it is compiled with lcc.exe:
[whit@giftie cat]$ wine lcc.exe -- -c cat.c fixme:console:SetConsoleCtrlHandler (0x425d48,1) - no error checking or testing yet fixme:console:SetConsoleCtrlHandler (0x425d48,0) - no error checking or testing yet [whit@giftie cat]$ wine lcclnk.exe cat.obj [whit@giftie cat]$ wine cat.exe high their [whit@giftie cat]$ echo 'oops!' >'1.txt' [whit@giftie cat]$ wine cat.exe oops!
[whit@giftie cat]$ cat cat.c >1.txt [whit@giftie cat]$ wine cat.exe #include <stdio.h> #include <stdlib.h> int main() { FILE *reg_file = fopen("1.txt", "r"); if (!reg_file) { perror(""); printf("Can't open file "%s"\n", "1.txt"); exit(1); } { char buf[100]; while (fgets(buf, 100, reg_file)) { printf("%s", buf); } exit(1); } }
[whit@giftie cat]$ cat /dev/vcc/4|fold|trail>oof
Lawson ---oof---
________________________________________________________________ GET INTERNET ACCESS FROM JUNO! Juno offers FREE or PREMIUM Internet access for less! Join Juno today! For your FREE software, visit: http://dl.www.juno.com/get/web/.