mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-18 02:38:27 +00:00
Changed 'freesrc' parameter from int to SDL_bool
This commit is contained in:
parent
32d529bf70
commit
bea99d48f2
7 changed files with 28 additions and 25 deletions
|
@ -594,9 +594,6 @@ extern DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
|
||||||
* be valid pointers. The entire data portion of the file is then loaded into
|
* be valid pointers. The entire data portion of the file is then loaded into
|
||||||
* memory and decoded if necessary.
|
* memory and decoded if necessary.
|
||||||
*
|
*
|
||||||
* If `freesrc` is non-zero, the data source gets automatically closed and
|
|
||||||
* freed before the function returns.
|
|
||||||
*
|
|
||||||
* Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and
|
* Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and
|
||||||
* 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and
|
* 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and
|
||||||
* A-law and mu-law (8 bits). Other formats are currently unsupported and
|
* A-law and mu-law (8 bits). Other formats are currently unsupported and
|
||||||
|
@ -643,11 +640,11 @@ extern DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* \param src The data source for the WAVE data
|
* \param src The data source for the WAVE data
|
||||||
* \param freesrc If non-zero, SDL will _always_ free the data source
|
* \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning, even in the case of an error
|
||||||
* \param spec An SDL_AudioSpec that will be filled in with the wave file's
|
* \param spec An SDL_AudioSpec that will be filled in with the wave file's
|
||||||
* format details
|
* format details
|
||||||
* \param audio_buf A pointer filled with the audio data, allocated by the
|
* \param audio_buf A pointer filled with the audio data, allocated by the
|
||||||
* function.
|
* function
|
||||||
* \param audio_len A pointer filled with the length of the audio data buffer
|
* \param audio_len A pointer filled with the length of the audio data buffer
|
||||||
* in bytes
|
* in bytes
|
||||||
* \returns This function, if successfully called, returns `spec`, which will
|
* \returns This function, if successfully called, returns `spec`, which will
|
||||||
|
@ -669,7 +666,7 @@ extern DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
|
||||||
* \sa SDL_LoadWAV
|
* \sa SDL_LoadWAV
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW(SDL_RWops * src,
|
extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW(SDL_RWops * src,
|
||||||
int freesrc,
|
SDL_bool freesrc,
|
||||||
SDL_AudioSpec * spec,
|
SDL_AudioSpec * spec,
|
||||||
Uint8 ** audio_buf,
|
Uint8 ** audio_buf,
|
||||||
Uint32 * audio_len);
|
Uint32 * audio_len);
|
||||||
|
|
|
@ -530,14 +530,14 @@ extern DECLSPEC int SDLCALL SDL_RWclose(SDL_RWops *context);
|
||||||
*
|
*
|
||||||
* \param src the SDL_RWops to read all available data from
|
* \param src the SDL_RWops to read all available data from
|
||||||
* \param datasize if not NULL, will store the number of bytes read
|
* \param datasize if not NULL, will store the number of bytes read
|
||||||
* \param freesrc if non-zero, calls SDL_RWclose() on `src` before returning
|
* \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning, even in the case of an error
|
||||||
* \returns the data, or NULL if there was an error.
|
* \returns the data, or NULL if there was an error.
|
||||||
*
|
*
|
||||||
* \since This function is available since SDL 3.0.0.
|
* \since This function is available since SDL 3.0.0.
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops *src,
|
extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops *src,
|
||||||
size_t *datasize,
|
size_t *datasize,
|
||||||
int freesrc);
|
SDL_bool freesrc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load all the data from a file path.
|
* Load all the data from a file path.
|
||||||
|
|
|
@ -228,7 +228,7 @@ extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
|
||||||
* will result in a memory leak.
|
* will result in a memory leak.
|
||||||
*
|
*
|
||||||
* \param src the data stream for the surface
|
* \param src the data stream for the surface
|
||||||
* \param freesrc non-zero to close the stream after being read
|
* \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning, even in the case of an error
|
||||||
* \returns a pointer to a new SDL_Surface structure or NULL if there was an
|
* \returns a pointer to a new SDL_Surface structure or NULL if there was an
|
||||||
* error; call SDL_GetError() for more information.
|
* error; call SDL_GetError() for more information.
|
||||||
*
|
*
|
||||||
|
@ -238,7 +238,7 @@ extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
|
||||||
* \sa SDL_LoadBMP
|
* \sa SDL_LoadBMP
|
||||||
* \sa SDL_SaveBMP_RW
|
* \sa SDL_SaveBMP_RW
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, int freesrc);
|
extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, SDL_bool freesrc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a BMP image from a file.
|
* Load a BMP image from a file.
|
||||||
|
|
|
@ -2075,9 +2075,9 @@ static int WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 *
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AudioSpec *SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
|
SDL_AudioSpec *SDL_LoadWAV_RW(SDL_RWops *src, SDL_bool freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
|
||||||
{
|
{
|
||||||
int result;
|
int result = -1;
|
||||||
WaveFile file;
|
WaveFile file;
|
||||||
|
|
||||||
SDL_zero(file);
|
SDL_zero(file);
|
||||||
|
@ -2085,16 +2085,16 @@ SDL_AudioSpec *SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec,
|
||||||
/* Make sure we are passed a valid data source */
|
/* Make sure we are passed a valid data source */
|
||||||
if (src == NULL) {
|
if (src == NULL) {
|
||||||
/* Error may come from RWops. */
|
/* Error may come from RWops. */
|
||||||
return NULL;
|
goto done;
|
||||||
} else if (spec == NULL) {
|
} else if (spec == NULL) {
|
||||||
SDL_InvalidParamError("spec");
|
SDL_InvalidParamError("spec");
|
||||||
return NULL;
|
goto done;
|
||||||
} else if (audio_buf == NULL) {
|
} else if (audio_buf == NULL) {
|
||||||
SDL_InvalidParamError("audio_buf");
|
SDL_InvalidParamError("audio_buf");
|
||||||
return NULL;
|
goto done;
|
||||||
} else if (audio_len == NULL) {
|
} else if (audio_len == NULL) {
|
||||||
SDL_InvalidParamError("audio_len");
|
SDL_InvalidParamError("audio_len");
|
||||||
return NULL;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
*audio_buf = NULL;
|
*audio_buf = NULL;
|
||||||
|
@ -2113,13 +2113,19 @@ SDL_AudioSpec *SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
if (freesrc) {
|
if (!freesrc) {
|
||||||
SDL_RWclose(src);
|
|
||||||
} else {
|
|
||||||
SDL_RWseek(src, file.chunk.position, SDL_RW_SEEK_SET);
|
SDL_RWseek(src, file.chunk.position, SDL_RW_SEEK_SET);
|
||||||
}
|
}
|
||||||
WaveFreeChunkData(&file.chunk);
|
WaveFreeChunkData(&file.chunk);
|
||||||
SDL_free(file.decoderdata);
|
SDL_free(file.decoderdata);
|
||||||
|
|
||||||
return spec;
|
done:
|
||||||
|
if (freesrc && src) {
|
||||||
|
SDL_RWclose(src);
|
||||||
|
}
|
||||||
|
if (result == 0) {
|
||||||
|
return spec;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -550,12 +550,12 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumble,(SDL_Joystick *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumbleTriggers,(SDL_Joystick *a),(a),return)
|
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumbleTriggers,(SDL_Joystick *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(int,SDL_JoystickIsHaptic,(SDL_Joystick *a),(a),return)
|
SDL_DYNAPI_PROC(int,SDL_JoystickIsHaptic,(SDL_Joystick *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(SDL_Surface*,SDL_LoadBMP,(const char *a),(a),return)
|
SDL_DYNAPI_PROC(SDL_Surface*,SDL_LoadBMP,(const char *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(SDL_Surface*,SDL_LoadBMP_RW,(SDL_RWops *a, int b),(a,b),return)
|
SDL_DYNAPI_PROC(SDL_Surface*,SDL_LoadBMP_RW,(SDL_RWops *a, SDL_bool b),(a,b),return)
|
||||||
SDL_DYNAPI_PROC(void*,SDL_LoadFile,(const char *a, size_t *b),(a,b),return)
|
SDL_DYNAPI_PROC(void*,SDL_LoadFile,(const char *a, size_t *b),(a,b),return)
|
||||||
SDL_DYNAPI_PROC(void*,SDL_LoadFile_RW,(SDL_RWops *a, size_t *b, int c),(a,b,c),return)
|
SDL_DYNAPI_PROC(void*,SDL_LoadFile_RW,(SDL_RWops *a, size_t *b, SDL_bool c),(a,b,c),return)
|
||||||
SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_LoadFunction,(void *a, const char *b),(a,b),return)
|
SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_LoadFunction,(void *a, const char *b),(a,b),return)
|
||||||
SDL_DYNAPI_PROC(void*,SDL_LoadObject,(const char *a),(a),return)
|
SDL_DYNAPI_PROC(void*,SDL_LoadObject,(const char *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(SDL_AudioSpec*,SDL_LoadWAV_RW,(SDL_RWops *a, int b, SDL_AudioSpec *c, Uint8 **d, Uint32 *e),(a,b,c,d,e),return)
|
SDL_DYNAPI_PROC(SDL_AudioSpec*,SDL_LoadWAV_RW,(SDL_RWops *a, SDL_bool b, SDL_AudioSpec *c, Uint8 **d, Uint32 *e),(a,b,c,d,e),return)
|
||||||
SDL_DYNAPI_PROC(int,SDL_LockAudioDevice,(SDL_AudioDeviceID a),(a),return)
|
SDL_DYNAPI_PROC(int,SDL_LockAudioDevice,(SDL_AudioDeviceID a),(a),return)
|
||||||
SDL_DYNAPI_PROC(void,SDL_LockJoysticks,(void),(),)
|
SDL_DYNAPI_PROC(void,SDL_LockJoysticks,(void),(),)
|
||||||
SDL_DYNAPI_PROC(int,SDL_LockMutex,(SDL_Mutex *a),(a),return)
|
SDL_DYNAPI_PROC(int,SDL_LockMutex,(SDL_Mutex *a),(a),return)
|
||||||
|
|
|
@ -666,7 +666,7 @@ void SDL_DestroyRW(SDL_RWops *area)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load all the data from an SDL data stream */
|
/* Load all the data from an SDL data stream */
|
||||||
void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, int freesrc)
|
void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
|
||||||
{
|
{
|
||||||
static const Sint64 FILE_CHUNK_SIZE = 1024;
|
static const Sint64 FILE_CHUNK_SIZE = 1024;
|
||||||
Sint64 size;
|
Sint64 size;
|
||||||
|
|
|
@ -193,7 +193,7 @@ static void CorrectAlphaChannel(SDL_Surface *surface)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface *SDL_LoadBMP_RW(SDL_RWops *src, int freesrc)
|
SDL_Surface *SDL_LoadBMP_RW(SDL_RWops *src, SDL_bool freesrc)
|
||||||
{
|
{
|
||||||
SDL_bool was_error;
|
SDL_bool was_error;
|
||||||
Sint64 fp_offset = 0;
|
Sint64 fp_offset = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue