Saturday 15 March 2014

c - Can fopen fail if the file already exists (in write mode)? -



c - Can fopen fail if the file already exists (in write mode)? -

i wish open new file using fopen("/temp/abc.txt", "w")

i want if file exists, fopen should fail can retry changing name. ex - rename abc_1.txt.

access() not preferred way because there possibility file gets created after access() phone call check , before fopen().

what improve way handle this?

in c11, fopen supports new mode modifier "x" require. i'm not aware of portable ways in before standards, however.

most operating systems back upwards such flag in platform-specific file-opening primitives. on posix systems can achieved o_excl, while on windows can achieved create_always.

c file

No comments:

Post a Comment