fopen - C - fopen_s cannot write to a file made by CreateFile -
i have main.c function , subfunction called within it. in subfunction have used createfile
make file. use closehandle
close handle file. when use fopen_s
after (within subfunction) works both read , write modes. if use fopen_s
in main function afterwards, can open read access, or else error code 13 - permission denied. parameters of createfile function follows:
happend = createfile(centraldatafilepath, // open central data file file_append_data, // open writing file_share_read|file_share_write, // allow multiple readers null, // no security open_always, // open or create file_attribute_normal, // normal file null); // no attr. template
and use fopen_s
follows:
file *f2; errno_t errorcode3 = 0; errorcode3 = fopen_s(&f2, centraldatafilepath, "a+"); fclose(f2);
i don't know if createfile has this, seems permission of file changes after exit subfunction? need able write file, know why getting permission denied error, , how fix it?
as described here:
files opened
fopen_s
,_wfopen_s
not sharable.
function failed because can't lock file writing. need use _fsopen
instead. try this:
f2 = _fsopen(centraldatafilepath, "a+", _sh_denyno);
Comments
Post a Comment