ronantakizawa/codereview-bench huggingface dataset:
Repository: libsdl-org/SDL
File: src/video/haiku/SDL_bmodes.cc (C++)

Code before:
    BScreen bscreen;
    BRect rc = bscreen.Frame();
    rect->x = (int)rc.left;
    rect->y = (int)rc.top;
    rect->w = (int)rc.Width() + 1;
    rect->h = (int)rc.Height() + 1;
    return true;
}

bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
{
    // Get the current screen
    BScreen bscreen;

    // Iterate through all of the modes
    SDL_DisplayMode mode;
    display_mode this_bmode;
    display_mode *bmodes;
    uint32 count, i;

    // Get graphics-hardware supported modes
    bscreen.GetModeList(&bmodes, &count);
    bscreen.GetMode(&this_bmode);

    for (i = 0; i < count; ++i) {
        // FIXME: Apparently there are errors with colorspace changes
        if (bmodes[i].space == this_bmode.space) {
            _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
            SDL_AddFullscreenDisplayMode(display, &mode);
        }
    }
    free(bmodes); // This should NOT be SDL_free()
    return true;
}


bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
    // Get the current screen
    BScreen bscreen;
    if (!bscreen.IsValid()) {
        return SDL_SetError("Invalid screen");
    }

    // Set the mode using the driver data
    display_mode *bmode = _ExtractBMode(mode);


    // FIXME: Is the first option always going to be the right one?
    uint32 c = 0, i;
    display_mode *bmode_list;

Review comment (suggestion):
```suggestion
        if (bscreen.GetMode(&this_bmode) == B_OK) {
```

Code after:
    BScreen bscreen;
    BRect rc = bscreen.Frame();
    rect->x = (int)rc.left;
    rect->y = (int)rc.top;
    rect->w = (int)rc.Width() + 1;
    rect->h = (int)rc.Height() + 1;
    return true;
}

bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
{
    // Get the current screen
    BScreen bscreen;

    // Iterate through all of the modes
    SDL_DisplayMode mode;
    display_mode this_bmode;
    display_mode *bmodes;
    uint32 count, i;
    bool r = false;

    // Get graphics-hardware supported modes
    if (bscreen.GetModeList(&bmodes, &count) == B_OK)
    {
        if (bscreen.GetMode(&this_bmode) == B_OK)
        {
            for (i = 0; i < count; ++i) {
                // FIXME: Apparently there are errors with colorspace changes
                if (bmodes[i].space == this_bmode.space) {
                    _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
                    SDL_AddFullscreenDisplayMode(display, &mode);
                }
            }
            r = true;
        }
        free(bmodes); // This should NOT be SDL_free()
    }

    return r;
}


bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
    // Get the current screen
    BScreen bscreen;
    if (!bscreen.IsValid()) {
        return SDL_SetError("Invalid screen");
    }

    // Set the mode using the driver data
Repository: libsdl-org/SDL
File: src/video/haiku/SDL_bmodes.cc (C++)

Code before:
    return;
}


bool HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
{
    BScreen bscreen;
    BRect rc = bscreen.Frame();
    rect->x = (int)rc.left;
    rect->y = (int)rc.top;
    rect->w = (int)rc.Width() + 1;
    rect->h = (int)rc.Height() + 1;
    return true;
}

bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
{
    // Get the current screen
    BScreen bscreen;

    // Iterate through all of the modes
    SDL_DisplayMode mode;
    display_mode this_bmode;
    display_mode *bmodes;
    uint32 count, i;

    // Get graphics-hardware supported modes
    bscreen.GetModeList(&bmodes, &count);
    bscreen.GetMode(&this_bmode);

    for (i = 0; i < count; ++i) {
        // FIXME: Apparently there are errors with colorspace changes
        if (bmodes[i].space == this_bmode.space) {
            _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
            SDL_AddFullscreenDisplayMode(display, &mode);
        }
    }
    free(bmodes); // This should NOT be SDL_free()
    return true;
}


bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
    // Get the current screen
    BScreen bscreen;
    if (!bscreen.IsValid()) {
        return SDL_SetError("Invalid screen");
    }

    // Set the mode using the driver data

Review comment (suggestion):
```suggestion
    bool result = false;
```
Usually the name for the return value is result or retval

Code after:
    return;
}


bool HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
{
    BScreen bscreen;
    BRect rc = bscreen.Frame();
    rect->x = (int)rc.left;
    rect->y = (int)rc.top;
    rect->w = (int)rc.Width() + 1;
    rect->h = (int)rc.Height() + 1;
    return true;
}

bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
{
    // Get the current screen
    BScreen bscreen;

    // Iterate through all of the modes
    SDL_DisplayMode mode;
    display_mode this_bmode;
    display_mode *bmodes;
    uint32 count, i;
    bool r = false;

    // Get graphics-hardware supported modes
    if (bscreen.GetModeList(&bmodes, &count) == B_OK)
    {
        if (bscreen.GetMode(&this_bmode) == B_OK)
        {
            for (i = 0; i < count; ++i) {
                // FIXME: Apparently there are errors with colorspace changes
                if (bmodes[i].space == this_bmode.space) {
                    _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
                    SDL_AddFullscreenDisplayMode(display, &mode);
                }
            }
            r = true;
        }
        free(bmodes); // This should NOT be SDL_free()
    }

    return r;
}


bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
    // Get the current screen
Repository: libsdl-org/SDL
File: src/joystick/ps2/SDL_sysjoystick.c (C)

Code before:
// Function to get the player index of a joystick
static int PS2_JoystickGetDevicePlayerIndex(int device_index)
{
    return -1;
}

// Function to set the player index of a joystick
static void PS2_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
}

// Function to return the stable GUID for a plugged in device
static SDL_GUID PS2_JoystickGetDeviceGUID(int device_index)
{
    // the GUID is just the name for now
    const char *name = PS2_JoystickGetDeviceName(device_index);
    return SDL_CreateJoystickGUIDForName(name);
}

// Function to get the current instance id of the joystick located at device_index
static SDL_JoystickID PS2_JoystickGetDeviceInstanceID(int device_index)
{
    return device_index + 1;
}

static void PS2_WaitPadReady(int port, int slot) {
    int state;
    do {
        state = padGetState(port, slot);
    } while ((state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1));
}

static void PS2_InitializePad(int port, int slot) {
    int modes;
    int i;
    int actuators;
    char actAlign[6];

    PS2_WaitPadReady(port, slot);

    // How many different modes can this device operate in?
    modes = padInfoMode(port, slot, PAD_MODETABLE, -1);

    // Verify that the controller has a DUAL SHOCK mode
    for (i = 0; i < modes; i++) {
        if (padInfoMode(port, slot, PAD_MODETABLE, i) == PAD_TYPE_DUALSHOCK) {
            break;
        }
    }
    if (i >= modes) {
        // This is no Dual Shock controller

Review comment (suggestion):
```suggestion
static void PS2_WaitPadReady(int port, int slot)
{
```

Code after:
// Function to get the player index of a joystick
static int PS2_JoystickGetDevicePlayerIndex(int device_index)
{
    return -1;
}

// Function to set the player index of a joystick
static void PS2_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
}

// Function to return the stable GUID for a plugged in device
static SDL_GUID PS2_JoystickGetDeviceGUID(int device_index)
{
    // the GUID is just the name for now
    const char *name = PS2_JoystickGetDeviceName(device_index);
    return SDL_CreateJoystickGUIDForName(name);
}

// Function to get the current instance id of the joystick located at device_index
static SDL_JoystickID PS2_JoystickGetDeviceInstanceID(int device_index)
{
    return device_index + 1;
}

static void PS2_WaitPadReady(int port, int slot)
{
    int state = padGetState(port, slot);
    while ((state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1)) {
        SDL_Delay(1);
        state = padGetState(port, slot);
    }
}

static void PS2_InitializePad(int port, int slot)
{
    int modes;
    int i;
    char actAlign[6];

    PS2_WaitPadReady(port, slot);

    // How many different modes can this device operate in?
    modes = padInfoMode(port, slot, PAD_MODETABLE, -1);

    // Verify that the controller has a DUAL SHOCK mode
    for (i = 0; i < modes; i++) {
        if (padInfoMode(port, slot, PAD_MODETABLE, i) == PAD_TYPE_DUALSHOCK) {
            break;
        }
    }
Repository: libsdl-org/SDL
File: src/joystick/SDL_gamepad.c (C)

Code before:

    if (!mapping) {
        mapping = s_pDefaultMapping;
    }
    return mapping;
}

bool SDL_PrivateIsGamepadPlatformMatch(const char *platform, size_t platform_len)
{
#ifdef SDL_PLATFORM_MACOS
    // We also accept the older SDL2 platform name for macOS
    if (SDL_strncasecmp(platform, "Mac OS X", platform_len) == 0) {
        return true;
    }
#endif

    return SDL_strncasecmp(platform, SDL_GetPlatform(), platform_len) == 0;
}

/*
 * Add or update an entry into the Mappings Database
 */
int SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio)
{
    int gamepads = 0;
    char *buf, *line, *line_end, *tmp, *comma, platform[64];
    size_t db_size;
    size_t platform_len;

    buf = (char *)SDL_LoadFile_IO(src, &db_size, closeio);
    if (!buf) {
        SDL_SetError("Could not allocate space to read DB into memory");
        return -1;
    }
    line = buf;

    SDL_LockJoysticks();

    PushMappingChangeTracking();

    while (line < buf + db_size) {
        line_end = SDL_strchr(line, '\n');
        if (line_end) {
            *line_end = '\0';
        } else {
            line_end = buf + db_size;
        }

        // Extract and verify the platform
        tmp = SDL_strstr(line, SDL_GAMEPAD_PLATFORM_FIELD);
        if (tmp) {

Review comment (suggestion):
```suggestion
    char *buf, *line, *line_end, *tmp, *comma, *platform;
```

Code after:

    if (!mapping) {
        mapping = s_pDefaultMapping;
    }
    return mapping;
}

bool SDL_PrivateIsGamepadPlatformMatch(const char *platform, size_t platform_len)
{
#ifdef SDL_PLATFORM_MACOS
    // We also accept the older SDL2 platform name for macOS
    if (SDL_strncasecmp(platform, "Mac OS X", platform_len) == 0) {
        return true;
    }
#endif

    return SDL_strncasecmp(platform, SDL_GetPlatform(), platform_len) == 0;
}

/*
 * Add or update an entry into the Mappings Database
 */
int SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio)
{
    int gamepads = 0;
    char *buf, *line, *line_end, *tmp, *comma, *platform;
    size_t db_size;
    size_t platform_len;

    buf = (char *)SDL_LoadFile_IO(src, &db_size, closeio);
    if (!buf) {
        SDL_SetError("Could not allocate space to read DB into memory");
        return -1;
    }
    line = buf;

    SDL_LockJoysticks();

    PushMappingChangeTracking();

    while (line < buf + db_size) {
        line_end = SDL_strchr(line, '\n');
        if (line_end) {
            *line_end = '\0';
        } else {
            line_end = buf + db_size;
        }

        // Extract and verify the platform
        tmp = SDL_strstr(line, SDL_GAMEPAD_PLATFORM_FIELD);
        if (tmp) {
Repository: libsdl-org/SDL
File: src/joystick/SDL_gamepad.c (C)

Code before:
        return -1;
    }
    line = buf;

    SDL_LockJoysticks();

    PushMappingChangeTracking();

    while (line < buf + db_size) {
        line_end = SDL_strchr(line, '\n');
        if (line_end) {
            *line_end = '\0';
        } else {
            line_end = buf + db_size;
        }

        // Extract and verify the platform
        tmp = SDL_strstr(line, SDL_GAMEPAD_PLATFORM_FIELD);
        if (tmp) {
            tmp += SDL_GAMEPAD_PLATFORM_FIELD_SIZE;
            comma = SDL_strchr(tmp, ',');
            if (comma) {
                platform_len = comma - tmp + 1;
                if (platform_len + 1 < SDL_arraysize(platform)) {
                    SDL_strlcpy(platform, tmp, platform_len);
                    if (SDL_PrivateIsGamepadPlatformMatch(platform, platform_len) &&
                        SDL_AddGamepadMapping(line) > 0) {
                        gamepads++;
                    }
                }
            }
        }

        line = line_end + 1;
    }

    PopMappingChangeTracking();

    SDL_UnlockJoysticks();

    SDL_free(buf);
    return gamepads;
}

int SDL_AddGamepadMappingsFromFile(const char *file)
{
    SDL_IOStream *stream = SDL_IOFromFile(file, "rb");
    if (!stream) {
        return -1;
    }
    return SDL_AddGamepadMappingsFromIO(stream, true);

Review comment (suggestion):
```suggestion
            platform = tmp;
            if (SDL_PrivateIsGamepadPlatformMatch(platform, platform_len) &&
```

Code after:
        return -1;
    }
    line = buf;

    SDL_LockJoysticks();

    PushMappingChangeTracking();

    while (line < buf + db_size) {
        line_end = SDL_strchr(line, '\n');
        if (line_end) {
            *line_end = '\0';
        } else {
            line_end = buf + db_size;
        }

        // Extract and verify the platform
        tmp = SDL_strstr(line, SDL_GAMEPAD_PLATFORM_FIELD);
        if (tmp) {
            tmp += SDL_GAMEPAD_PLATFORM_FIELD_SIZE;
            comma = SDL_strchr(tmp, ',');
            if (comma) {
                platform = tmp;
                platform_len = comma - platform;
                if (SDL_PrivateIsGamepadPlatformMatch(platform, platform_len) &&
                    SDL_AddGamepadMapping(line) > 0) {
                    gamepads++;
                }
            }
        }

        line = line_end + 1;
    }

    PopMappingChangeTracking();

    SDL_UnlockJoysticks();

    SDL_free(buf);
    return gamepads;
}

int SDL_AddGamepadMappingsFromFile(const char *file)
{
    SDL_IOStream *stream = SDL_IOFromFile(file, "rb");
    if (!stream) {
        return -1;
    }
    return SDL_AddGamepadMappingsFromIO(stream, true);
}
Repository: libsdl-org/SDL
File: src/video/SDL_bmp.c (C)

Code before:
    }

    was_error = false;

done:
    if (was_error) {
        if (src) {
            SDL_SeekIO(src, fp_offset, SDL_IO_SEEK_SET);
        }
        SDL_DestroySurface(surface);
        surface = NULL;
    }
    if (closeio && src) {
        SDL_CloseIO(src);
    }
    return surface;
}

typedef struct {
    SDL_Surface *surface;
    SDL_Surface *intermediate_surface;
    bool save32bit;
    bool saveLegacyBMP;
} SaveBmpState;

static void deinit_SaveBmpState(SaveBmpState *state)
{
    if (state->intermediate_surface && state->intermediate_surface != state->surface) {
        SDL_DestroySurface(state->intermediate_surface);
    }
}

static bool init_SaveBmpState(SaveBmpState *state, SDL_Surface *surface)
{
    state->surface = surface;
    state->intermediate_surface = NULL;
    state->save32bit = false;
    state->saveLegacyBMP = false;

    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
        SDL_InvalidParamError("surface");
        return false;
    }

#ifdef SAVE_32BIT_BMP
    // We can save alpha information in a 32-bit BMP
    if (SDL_BITSPERPIXEL(surface->format) >= 8 &&
        (SDL_ISPIXELFORMAT_ALPHA(surface->format) ||
         (surface->map.info.flags & SDL_COPY_COLORKEY))) {
        state->save32bit = true;
    }

Review comment (suggestion):
```suggestion
static void FreeSaveBmpState(SaveBmpState *state)
```

Code after:
    }

    was_error = false;

done:
    if (was_error) {
        if (src) {
            SDL_SeekIO(src, fp_offset, SDL_IO_SEEK_SET);
        }
        SDL_DestroySurface(surface);
        surface = NULL;
    }
    if (closeio && src) {
        SDL_CloseIO(src);
    }
    return surface;
}

typedef struct {
    SDL_Surface *surface;
    SDL_Surface *intermediate_surface;
    bool save32bit;
    bool saveLegacyBMP;
} BMPSaveState;

static void FreeBMPSaveState(BMPSaveState *state)
{
    if (state->intermediate_surface && state->intermediate_surface != state->surface) {
        SDL_DestroySurface(state->intermediate_surface);
    }
}

static bool InitBMPSaveState(BMPSaveState *state, SDL_Surface *surface)
{
    state->surface = surface;
    state->intermediate_surface = NULL;
    state->save32bit = false;
    state->saveLegacyBMP = false;

    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
        return SDL_InvalidParamError("surface");
    }

#ifdef SAVE_32BIT_BMP
    // We can save alpha information in a 32-bit BMP
    if (SDL_BITSPERPIXEL(surface->format) >= 8 &&
        (SDL_ISPIXELFORMAT_ALPHA(surface->format) ||
         (surface->map.info.flags & SDL_COPY_COLORKEY))) {
        state->save32bit = true;
    }
#endif // SAVE_32BIT_BMP
Repository: libsdl-org/SDL
File: src/video/SDL_bmp.c (C)

Code before:
            SDL_SeekIO(src, fp_offset, SDL_IO_SEEK_SET);
        }
        SDL_DestroySurface(surface);
        surface = NULL;
    }
    if (closeio && src) {
        SDL_CloseIO(src);
    }
    return surface;
}

typedef struct {
    SDL_Surface *surface;
    SDL_Surface *intermediate_surface;
    bool save32bit;
    bool saveLegacyBMP;
} SaveBmpState;

static void deinit_SaveBmpState(SaveBmpState *state)
{
    if (state->intermediate_surface && state->intermediate_surface != state->surface) {
        SDL_DestroySurface(state->intermediate_surface);
    }
}

static bool init_SaveBmpState(SaveBmpState *state, SDL_Surface *surface)
{
    state->surface = surface;
    state->intermediate_surface = NULL;
    state->save32bit = false;
    state->saveLegacyBMP = false;

    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
        SDL_InvalidParamError("surface");
        return false;
    }

#ifdef SAVE_32BIT_BMP
    // We can save alpha information in a 32-bit BMP
    if (SDL_BITSPERPIXEL(surface->format) >= 8 &&
        (SDL_ISPIXELFORMAT_ALPHA(surface->format) ||
         (surface->map.info.flags & SDL_COPY_COLORKEY))) {
        state->save32bit = true;
    }
#endif // SAVE_32BIT_BMP

    if (surface->palette && !state->save32bit) {
        if (SDL_BITSPERPIXEL(surface->format) == 8) {
            state->intermediate_surface = surface;
        } else {
            SDL_SetError("%u bpp BMP files not supported",

Review comment (suggestion):
```suggestion
static bool InitSaveBmpState(SaveBmpState *state, SDL_Surface *surface)
```

Code after:
            SDL_SeekIO(src, fp_offset, SDL_IO_SEEK_SET);
        }
        SDL_DestroySurface(surface);
        surface = NULL;
    }
    if (closeio && src) {
        SDL_CloseIO(src);
    }
    return surface;
}

typedef struct {
    SDL_Surface *surface;
    SDL_Surface *intermediate_surface;
    bool save32bit;
    bool saveLegacyBMP;
} BMPSaveState;

static void FreeBMPSaveState(BMPSaveState *state)
{
    if (state->intermediate_surface && state->intermediate_surface != state->surface) {
        SDL_DestroySurface(state->intermediate_surface);
    }
}

static bool InitBMPSaveState(BMPSaveState *state, SDL_Surface *surface)
{
    state->surface = surface;
    state->intermediate_surface = NULL;
    state->save32bit = false;
    state->saveLegacyBMP = false;

    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
        return SDL_InvalidParamError("surface");
    }

#ifdef SAVE_32BIT_BMP
    // We can save alpha information in a 32-bit BMP
    if (SDL_BITSPERPIXEL(surface->format) >= 8 &&
        (SDL_ISPIXELFORMAT_ALPHA(surface->format) ||
         (surface->map.info.flags & SDL_COPY_COLORKEY))) {
        state->save32bit = true;
    }
#endif // SAVE_32BIT_BMP

    if (surface->palette && !state->save32bit) {
        if (SDL_BITSPERPIXEL(surface->format) == 8) {
            state->intermediate_surface = surface;
        } else {
            SDL_SetError("%u bpp BMP files not supported",
                         SDL_BITSPERPIXEL(surface->format));
Repository: libsdl-org/SDL
File: src/video/SDL_bmp.c (C)

Code before:
        state->intermediate_surface = SDL_ConvertSurface(surface, pixel_format);
        if (!state->intermediate_surface) {
            SDL_SetError("Couldn't convert image to %d bpp",
                         (int)SDL_BITSPERPIXEL(pixel_format));
            goto error;
        }
    }

    if (state->save32bit) {
        state->saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, false);
    }
    return true;
error:
    deinit_SaveBmpState(state);
    return false;
}

SDL_Surface *SDL_LoadBMP(const char *file)
{
    SDL_IOStream *stream = SDL_IOFromFile(file, "rb");
    if (!stream) {
        return NULL;
    }
    return SDL_LoadBMP_IO(stream, true);
}
static bool SDL_SaveBMP_state_IO(SaveBmpState *state, SDL_IOStream *dst, bool closeio)
{
    bool was_error = true;
    Sint64 fp_offset, new_offset;
    int i, pad;
    Uint8 *bits;

    // The Win32 BMP file header (14 bytes)
    char magic[2] = { 'B', 'M' };
    Uint32 bfSize;
    Uint16 bfReserved1;
    Uint16 bfReserved2;
    Uint32 bfOffBits;

    // The Win32 BITMAPINFOHEADER struct (40 bytes)
    Uint32 biSize;
    Sint32 biWidth;
    Sint32 biHeight;
    Uint16 biPlanes;
    Uint16 biBitCount;
    Uint32 biCompression;
    Uint32 biSizeImage;
    Sint32 biXPelsPerMeter;
    Sint32 biYPelsPerMeter;
    Uint32 biClrUsed;
    Uint32 biClrImportant;

Review comment (suggestion):
```suggestion
static bool SDL_SaveBMP_IO_Internal(SaveBmpState *state, SDL_IOStream *dst, bool closeio)
```

Code after:
        if (!state->intermediate_surface) {
            SDL_SetError("Couldn't convert image to %d bpp",
                         (int)SDL_BITSPERPIXEL(pixel_format));
            goto error;
        }
    }

    if (state->save32bit) {
        state->saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, false);
    }
    return true;
error:
    FreeBMPSaveState(state);
    return false;
}

SDL_Surface *SDL_LoadBMP(const char *file)
{
    SDL_IOStream *stream = SDL_IOFromFile(file, "rb");
    if (!stream) {
        return NULL;
    }
    return SDL_LoadBMP_IO(stream, true);
}
static bool SDL_SaveBMP_IO_Internal(BMPSaveState *state, SDL_IOStream *dst, bool closeio)
{
    bool was_error = true;
    Sint64 fp_offset, new_offset;
    int i, pad;
    Uint8 *bits;

    // The Win32 BMP file header (14 bytes)
    char magic[2] = { 'B', 'M' };
    Uint32 bfSize;
    Uint16 bfReserved1;
    Uint16 bfReserved2;
    Uint32 bfOffBits;

    // The Win32 BITMAPINFOHEADER struct (40 bytes)
    Uint32 biSize;
    Sint32 biWidth;
    Sint32 biHeight;
    Uint16 biPlanes;
    Uint16 biBitCount;
    Uint32 biCompression;
    Uint32 biSizeImage;
    Sint32 biXPelsPerMeter;
    Sint32 biYPelsPerMeter;
    Uint32 biClrUsed;
    Uint32 biClrImportant;