-
Notifications
You must be signed in to change notification settings - Fork 151
FileFlush and FileTruncate functions #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I have no idea why Travis keeps failing, i can compile and run the compiler and the RTL in Windows without problems. |
|
Jeff, thanks for your help!
I think, i will close this PR and start a new one. JK |
Well, you don't have to close this PR. My opinion, is that if you are going to use the PR as a development tool, it would be nice just to keep the whole discussion here. You can force push your changes and basically overwrite what you already have. Even if you close the PR, github seems to keep the history forever anyway, and I will probably reference your new PR to here. Anyway, I'm not sure what your remote name is, but would be something like As for the device drivers, as I mentioned, the FLUSH function is already in |
This Linux stuff is driving me crazy, maybe i should restrict my code to Windows and leave the rest to someone with more experience of the other targets. |
Yes, my opinion, the main reason for selecting one single thing to improve on, and then taking that one single thing to the finish line. For example, FLUSH command (which is first commit), added through |
Thanks for the guidance, i hope i got it right now. |
@jklwn4, @jklwn3 The changes are minor, and if it is OK with you, I can make the changes and push to this pull request:
There's one other change could make, but it's not currently needed. Just thought I would mention in case it is needed in future: many of the file functions have a Sorry, I haven't looked at the SetEof addition yet (or perhaps |
Go ahead, make the necessary changes and push it! In general feel free to "fine tune" my PRs whenever and whereever necessary. Yes, i was impatient. Should i make a separate PR for each change or new feature? This is likely to result in a lot of PRs, but if this is easier/better for you to handle, i will do it. JK later: regarding SETEOF vs. FILETRUNCATE, i would prefer SETEOF, because it is shorter and it is as self-explanatory as FILETRUNCATE (EOF = end of file, a user is already familiar with the meaning of EOF). |
Reading more about fflush, i realize that this doesnt ensure the file to be written to disk. It flushes internal C buffers to the underlying file system, but it doesn´t flush the file system´s buffers. You must use FlushFileBuffers (handle) in Windows and fsync (fp) in Linux to do that. So this is still missing and should be added! The more, the return value of fflush should be tested for success or error. JK |
Thanks for working on this, unicode filename support in Windows is sorely missing! Re: the strategy of just implementing wide versions of certain rtlib functions (eg FILELEN): note that will break support for Windows 95/98/ME, unless people link against unicows.lib and distribute unicows.dll with their programs. Wouldn't it only be a small step to use overloading instead of #ifdefing a different set of functions, as Jeff said, and preserve Win 95/98/ME support? Just earlier this year I ported my FB program to Win 95 and 98 after a user asked for it. But I feel like a jerk for mentioning this, since Win ME was released 19 years ago, and I'm just causing trouble... There's a quirk when the Windows ANSI codepage is set to Japanese: \ and the yen symbol are the same character! This breaks a lot of file path stuff. So make sure that everything is tested on a computer set to Japanese codepage. |
Well, i didn´t expect that Windows 95 is still in use these days. Windows XP - yes, but Windows 95? Jeff, what do you think, should we still support Windows 95? This would indeed require a slightly different approach from what i proposed. Thanks for the hint (\ vs. yen), but how could we avoid it and how could we test it? Looks like we need a Japanese ;-) ? JK |
I'm not actually aware of anything we need to do to avoid breaking because of the Japanese codepage. I think it means converting from ANSI to UTF16 and back again is lossy, and ANSI->UTF16 might break paths? I'd be happy to run the tests under a Japanese codepage on my Win XP VM, since I already installed it. I think that there are far more Win 98 machines than Win 95. |
There is no conversion ANSI -> UTF16 and back again, it´s only ANSI -> UTF16 in Windows. Only the place of the conversion may differ. If we pass an ANSI string to a ...A Windows API function, this ANSI string is converted to UTF16 by Windows internally and the corresponding ...W Windows API function is called. That is, all ...A functions are merely wrappers of the corresponding ...W functions. So if we call only the ...W functions from FB and convert ANSI to UTF16 in FB, the conversion takes place in FB and no conversion is needed in Windows anymore. The result should be the same and there are no superfluous conversions. Feel free to test the code of #180 with a Japanes code page and tell me if there are problems or not. JK |
- change flush function naming same as other extended file functions - FileFlush() in inc/file.bi - fb_FileFlush() in src/rtlib/file_flush.c - use 'filenumber' instead of 'handle' in inc/file.bi - add prototype to for fb_FileFlush() to src/rtlib/fb_file.h
- no need to check for FB_FILE_TYPE_NORMAL, if device has pfnFlush function ptr set, then it's OK to call - besides, OPEN "CON" is FB_FILE_TYPE_CONSOLE, and calling pfnFlush is OK - FB_UNLOCK() must be after the call to pfnFlush, so fb_FileFlush retains locks until after fflush() call
force pushed for rebase on to current fbc/master Adds the FileFlush function. |
That's interesting. github appears to display the commits by The Next, there is the
I think once the truncate function is added, this will be next pull request to merge to fbc/master. |
Jeff, i don´t know, if you noticed my above comment:
|
- FileFlush has code (for fflush) in the device driver to flush application buffers - FileFlush if passed non-zero flag, will also call platform specific code to flush system buffer - FileTruncate removed from file device driver - FileTruncate added to platform specific code
@rversteegen, thanks, I did notice that. |
Thanks Jeff, i see the new statements follow the naming convention of file.bi. Could we have (additional) short forms of the "FILE..." statements in file.bi too? Obviously FILELEN must remain FILELEN, but FILEFLUSH could be just FLUSH, the same applies to TRUNCATE, EXISTS, etc., you don´t have FILEOPEN, FILEKILL, FILECLOSE, etc., you have OPEN, KILL, CLOSE, etc. |
@jklwn, I did notice your comment. Yes, it requires adding platform specific code, which I've done in the last several commits. My understanding is this:
So, I've added the
For the I have not added the explicit call to Because we are adding platform specific code, have to watch for breaking builds for platforms not yet tested. Hoping that the generic unix implementation will work on all platforms other than linux, dos, win, which were tested. So, looks like a few more tests to do, and another self review of the code before merging in. |
I don´t see, how this could happen, when ftello is followed immediately by ftruncate (just as we coded). |
i disagree in this point. I would let it default the other way round. When using FILEFLUSH i must have a special reason for doing so, because normally i would let the the system take care for saving my data to a device. So when using FILEFLUSH, i would expect the data to be written to the (physical) device immediately by default. The additional parameter could be used to only flush the application buffers. Maybe in order to speed things up, because FlushFileBuffers and fsync block the application until the data is actually written to the device. |
I can see that. But not in this pull request. It would be unfair to users to force a whole bunch of new common / short names in to the global name space. In fact, there are users that would like to see a method of having all fbc keywords in a namespace. For quirk keywords, this is challenging as it would require a pseudo namespace created by the compiler, but it's not impossible. Perhaps a combination of |
You have to look deeper to see the issue. And, actually I should have said 2^31-1 since
If Actually, effective if I didn't include the following test in the test-suite as it generates a ~2GiB file. Since it's possible to use
Running this test on commit b67995c results in failures on mingw-w64/mingw32, mingw-w64/mingw64, and mingw (org). I fixed mingw-w64 by using correct On DOS, the test fails, but for a different reason, file positioning and ftruncate are 32-bit only. On Linux based tests, it generally passes, because the mapping of Anyway, I think I have a reasonable fix coming up in the next set of commits. |
I tried your way, the other way around, and it feels backwards; passing a flag to do something less. There are a couple of patterns I am following with this design:
Also like
|
Accepted I don´t share your concern about new names in the global namespace. Adding reasonable and useful new features requires adding new reserved key words, that´s a fact. You don´t ask for too much of FreeBASIC users in this respect, i think. |
One last comment: "FileTruncate" might be missleading, because it can make a file smaller and larger as well. "Truncate" implies making smaller only. I would prefer something like my initial proposal "Seteof" (Set end of file), which implies both. |
This PR is not ready now, commit by commit i will add more file/path related functions for wide string file/path names in Windows.
JK