|
From: Earnie <ea...@us...> - 2011-03-21 16:14:18
|
Paul Leder wrote: > I'd like to handle Unix-style as well as DOS-style line endings on the > MinGW version of my code. Does anyone have any thoughts on this? > > The problem is that I'd prefer to open input files in text mode. When > your open a NL-only file in text mode, however, fpos/fseek don't work on > the file. If you get a file position, and then seek to it, you end up > somewhere else in the file. This works for CR/NL files, of course, but > not NL-only files. > I think you're backwards here, or I'm understanding you backwards. The text mode I/O will remove the CR making fpos/fseek worthless. You want to open the files in binary mode and handle the dangling CR at the end of the strings. > I've also tried fgetpos/fsetpos, but they have exactly the same problem. > > I've also tried _setmode, to set the file mode to binary before the fpos > and back to text after the fseek. This works for NL-only files, but > fails for CR/NL files. MSDN also says that you should call _setmode > before doing any file I/O, so I wouldn't want to do this anyway. > Yea, you need to leave them in binary mode. > AFAICT, if I want to deal with "text" files that are NL-only, and I want > to fpos/fseek on those files, then I must open them in binary mode. > Unfortunately, when I do this, I get other errors in my code, which I > haven't looked at yet. I guess I may just have to fix these instead. > Yes, you should fix the other errors. It is a long known issue. The other errors may be related to dangling CR which will remain in the strings when read. > I suppose one point of view is that you shouldn't open NL-only files in > "text" mode on Windows, because they're not what Windows considers to be > "text". Now that I've written it down, I suppose that's the only logical > answer. > The only problem I know for NL only files is notepad because it reads the data in binary mode expecting to find a CR to put the data on the next line and some versions of MSVC editor. I've never heard of fpos/fseek having an issue with NL only files, rather the reverse. But things may have changed for newer versions of the OS and/or MSVCRT? -- Earnie -- http://www.for-my-kids.com |