Forum > Suggestions

RTL: FileCreateNew ()

(1/2) > >>

joho:
I may have missed it, but it'd nice if the RTL had FileCreateNew (). The intended behavior is like FileCreate, except that the call will fail if the file to be created already exists. This can, of course, be emulate by a call to FileOpen () followed by FileCreate () if FileOpen failed due to "File not found". But there are native OS functions for FileCreateNew () on a few platforms AFAIK.

molly:
Forgive my ignorance but what benefit would that have over using fileexists ?

Thaddy:
But we have that functionality in multiple ways, not only FileExists.
E.g. on linux we have https://www.freepascal.org/docs-html/rtl/baseunix/fpopen.html which can do exactly what you asked: if you include the O_Excl flag it will fail if the file already exists. E.g.
--- Code: ---O_Creat or O_Excl
--- End code ---

joho:

--- Quote from: molly on September 03, 2017, 09:07:10 am ---Forgive my ignorance but what benefit would that have over using fileexists ?

--- End quote ---

There's no benefit, but it makes sense to be able to do it in one call (IMHO). I simulate it now by first doing a FileOpen and then if that fails, FileCreate. But it's nice to have it as an API function.

joho:

--- Quote from: Thaddy on September 03, 2017, 10:21:58 am ---But we have that functionality in multiple ways, not only FileExists.
E.g. on linux we have https://www.freepascal.org/docs-html/rtl/baseunix/fpopen.html which can do exactly what you asked: if you include the O_Excl flag it will fail if the file already exists. E.g.
--- Code: ---O_Creat or O_Excl
--- End code ---

--- End quote ---

But things like this should not require specific platforms, specific flags, or whatever ... if there's FileCreateNew () in the RTL, it can isolate OS-specific constructs from the programmer. Isn't that, after all, part of the reason for having complexity in the RTL instead of going directly to the OS specific stuff with IFDEFs ... ?

Navigation

[0] Message Index

[#] Next page

Go to full version