Skip to content

Commit

Permalink
Use SDL_bool instead an int return code in the SDL API
Browse files Browse the repository at this point in the history
Most SDL functions used to indicate success or failure using an int return code. These functions have been changed to return SDL_bool.

Here is a coccinelle patch to change code that previously compared the return value to 0 and changes it to a boolean test:
@ bool_return_type @
identifier func =~ "^(IMG_SaveAVIF|IMG_SaveAVIF_IO|IMG_SaveJPG|IMG_SaveJPG_IO|IMG_SavePNG|IMG_SavePNG_IO)$"
@@
(
  func(
  ...
  )
- == 0
|
- func(
+ !func(
  ...
  )
- < 0
|
- func(
+ !func(
  ...
  )
- != 0
|
- func(
+ !func(
  ...
  )
- == -1
)
  • Loading branch information
slouken committed Aug 27, 2024
1 parent c9d7d4b commit f5f1b1b
Show file tree
Hide file tree
Showing 26 changed files with 544 additions and 549 deletions.
12 changes: 6 additions & 6 deletions examples/showimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,19 @@ int main(int argc, char *argv[])
SDL_Surface *surface = IMG_Load(argv[i]);
if (surface) {
const char *ext = SDL_strrchr(saveFile, '.');
SDL_bool saved = SDL_FALSE;
if (ext && SDL_strcasecmp(ext, ".avif") == 0) {
result = IMG_SaveAVIF(surface, saveFile, 90);
saved = IMG_SaveAVIF(surface, saveFile, 90);
} else if (ext && SDL_strcasecmp(ext, ".bmp") == 0) {
result = SDL_SaveBMP(surface, saveFile);
saved = SDL_SaveBMP(surface, saveFile);
} else if (ext && SDL_strcasecmp(ext, ".jpg") == 0) {
result = IMG_SaveJPG(surface, saveFile, 90);
saved = IMG_SaveJPG(surface, saveFile, 90);
} else if (ext && SDL_strcasecmp(ext, ".png") == 0) {
result = IMG_SavePNG(surface, saveFile);
saved = IMG_SavePNG(surface, saveFile);
} else {
SDL_SetError("Unknown save file type");
result = -1;
}
if (result < 0) {
if (!saved) {
SDL_Log("Couldn't save %s: %s\n", saveFile, SDL_GetError());
result = 3;
}
Expand Down
Loading

0 comments on commit f5f1b1b

Please sign in to comment.