SDL_RWFromFile problem writing a file

Good morning.

I have a problem with SDL_RWFromFile with the “w” option.
Whether the file already exists or not it always gives me the error “the file exists” and therefore a NULL pointer.
And yet if the file does not exist it is indeed created.

SDL_RWops *dst = SDL_RWFromFile(destPath, "wb");

I tried to find an answer on the forum but I can’t find a post corresponding to this problem.

Thanks for your help.

I specify that my objective is to copy a file.
and opening the source file does not pose a problem.

SDL_RWops	*src	= SDL_RWFromFile(srcPath, "rb");

That could be a bug, but it could also be an issue with permissions or a read-only filesystem. What OS?

What does SDL_GetError() say?

Are you able to open the same file for writing using traditional C stdlib?

Thanks for taking time to respond to me.

I’m on Windows and MinGW, not mingw-w64

The error message returned SDL_GetError(): Couldn’t open data/data.am

And yes it works correctly with fopen(destPath, "wb"); but I prefer to use the SDL functions.

So why does the error message say that it cannot open the file even though it is correctly created?

What happens if you specify the file as data\\data.am ?

Strange that fopen() works, but not SDL_RWFromFile()

Hello.
The problem is the same with data\data.am.

Yes I find it strange, especially since I have a function to write a file in which I use SDL_RWFromFile.

So I’m going to try reading the entire source file then creating the destination file using the function that works.

it does not work.
if I wrote my files directly in the “data” directory, it works but copying a file from a directory to “data” does not work.

I tend to trust SDL but either I didn’t understand something or there is information missing in the documentation.

Many apologies for the inconvenience.
I’m just stupid.

In the function that calls file copy, I create the destination file without closing it.

Sorry again for the inconvenience.

And thank you for the time you took to help me.

LOL that’s OK, happens to everyone. Glad you figured it out.