add SDL_bsearch

This commit is contained in:
Ozkan Sezer 2022-04-25 23:55:50 +03:00 committed by Ozkan Sezer
parent 0b2a55ea7d
commit e9ff4fdd49
17 changed files with 52 additions and 6 deletions

View File

@ -848,7 +848,7 @@ if(SDL_LIBC)
endforeach() endforeach()
set(HAVE_SIGNAL_H 1) set(HAVE_SIGNAL_H 1)
foreach(_FN foreach(_FN
malloc calloc realloc free qsort abs memset memcpy memmove memcmp malloc calloc realloc free bsearch qsort abs memset memcpy memmove memcmp
wcslen _wcsdup wcsdup wcsstr wcscmp wcsncmp _wcsicmp _wcsnicmp wcslen _wcsdup wcsdup wcsstr wcscmp wcsncmp _wcsicmp _wcsnicmp
strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
_ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
@ -885,7 +885,7 @@ if(SDL_LIBC)
int main(void) { return 0; }" HAVE_MPROTECT) int main(void) { return 0; }" HAVE_MPROTECT)
foreach(_FN foreach(_FN
strtod malloc calloc realloc free getenv setenv putenv unsetenv strtod malloc calloc realloc free getenv setenv putenv unsetenv
qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat bsearch qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
_strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r _strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r
itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp

2
configure vendored
View File

@ -17717,7 +17717,7 @@ fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi fi
for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat _wcsdup wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll _Exit for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv bsearch qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat _wcsdup wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll _Exit
do : do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

View File

@ -337,7 +337,7 @@ dnl Checks for library functions.
AC_DEFINE(HAVE_MPROTECT, 1, [ ]) AC_DEFINE(HAVE_MPROTECT, 1, [ ])
],[]), ],[]),
) )
AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat _wcsdup wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll _Exit) AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv bsearch qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat _wcsdup wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll _Exit)
AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"]) AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf trunc truncf fmod fmodf log logf log10 log10f lround lroundf pow powf round roundf scalbn scalbnf sin sinf sqrt sqrtf tan tanf) AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf trunc truncf fmod fmodf log logf log10 log10f lround lroundf pow powf round roundf scalbn scalbnf sin sinf sqrt sqrtf tan tanf)

View File

@ -88,6 +88,7 @@
#cmakedefine HAVE_UNSETENV 1 #cmakedefine HAVE_UNSETENV 1
#endif #endif
#cmakedefine HAVE_QSORT 1 #cmakedefine HAVE_QSORT 1
#cmakedefine HAVE_BSEARCH 1
#cmakedefine HAVE_ABS 1 #cmakedefine HAVE_ABS 1
#cmakedefine HAVE_BCOPY 1 #cmakedefine HAVE_BCOPY 1
#cmakedefine HAVE_MEMSET 1 #cmakedefine HAVE_MEMSET 1

View File

@ -92,6 +92,7 @@
#undef HAVE_UNSETENV #undef HAVE_UNSETENV
#endif #endif
#undef HAVE_QSORT #undef HAVE_QSORT
#undef HAVE_BSEARCH
#undef HAVE_ABS #undef HAVE_ABS
#undef HAVE_BCOPY #undef HAVE_BCOPY
#undef HAVE_MEMSET #undef HAVE_MEMSET

View File

@ -60,6 +60,7 @@
#define HAVE_SETENV 1 #define HAVE_SETENV 1
#define HAVE_UNSETENV 1 #define HAVE_UNSETENV 1
#define HAVE_QSORT 1 #define HAVE_QSORT 1
#define HAVE_BSEARCH 1
#define HAVE_ABS 1 #define HAVE_ABS 1
#define HAVE_BCOPY 1 #define HAVE_BCOPY 1
#define HAVE_MEMSET 1 #define HAVE_MEMSET 1

View File

@ -69,6 +69,7 @@
#define HAVE_PUTENV 1 #define HAVE_PUTENV 1
#define HAVE_UNSETENV 1 #define HAVE_UNSETENV 1
#define HAVE_QSORT 1 #define HAVE_QSORT 1
#define HAVE_BSEARCH 1
#define HAVE_ABS 1 #define HAVE_ABS 1
#define HAVE_BCOPY 1 #define HAVE_BCOPY 1
#define HAVE_MEMSET 1 #define HAVE_MEMSET 1

View File

@ -60,6 +60,7 @@
#define HAVE_SETENV 1 #define HAVE_SETENV 1
#define HAVE_UNSETENV 1 #define HAVE_UNSETENV 1
#define HAVE_QSORT 1 #define HAVE_QSORT 1
#define HAVE_BSEARCH 1
#define HAVE_ABS 1 #define HAVE_ABS 1
#define HAVE_BCOPY 1 #define HAVE_BCOPY 1
#define HAVE_MEMSET 1 #define HAVE_MEMSET 1

View File

@ -63,6 +63,7 @@
#define HAVE_PUTENV 1 #define HAVE_PUTENV 1
#define HAVE_UNSETENV 1 #define HAVE_UNSETENV 1
#define HAVE_QSORT 1 #define HAVE_QSORT 1
#define HAVE_BSEARCH 1
#define HAVE_ABS 1 #define HAVE_ABS 1
#define HAVE_BCOPY 1 #define HAVE_BCOPY 1
#define HAVE_MEMSET 1 #define HAVE_MEMSET 1

View File

@ -106,6 +106,7 @@
#define HAVE_SETENV 1 #define HAVE_SETENV 1
#define HAVE_PUTENV 1 #define HAVE_PUTENV 1
#define HAVE_QSORT 1 #define HAVE_QSORT 1
#define HAVE_BSEARCH 1
#define HAVE_ABS 1 #define HAVE_ABS 1
#define HAVE_BCOPY 1 #define HAVE_BCOPY 1
#define HAVE_MEMSET 1 #define HAVE_MEMSET 1

View File

@ -65,6 +65,7 @@
#define HAVE_PUTENV 1 #define HAVE_PUTENV 1
#define HAVE_UNSETENV 1 #define HAVE_UNSETENV 1
#define HAVE_QSORT 1 #define HAVE_QSORT 1
#define HAVE_BSEARCH 1
#define HAVE_ABS 1 #define HAVE_ABS 1
#define HAVE_BCOPY 1 #define HAVE_BCOPY 1
#define HAVE_MEMSET 1 #define HAVE_MEMSET 1

View File

@ -137,6 +137,7 @@ typedef unsigned int uintptr_t;
#define HAVE_FREE 1 #define HAVE_FREE 1
#define HAVE_ALLOCA 1 #define HAVE_ALLOCA 1
#define HAVE_QSORT 1 #define HAVE_QSORT 1
#define HAVE_BSEARCH 1
#define HAVE_ABS 1 #define HAVE_ABS 1
#define HAVE_MEMSET 1 #define HAVE_MEMSET 1
#define HAVE_MEMCPY 1 #define HAVE_MEMCPY 1

View File

@ -123,6 +123,7 @@ typedef unsigned int uintptr_t;
#define HAVE_FREE 1 #define HAVE_FREE 1
#define HAVE_ALLOCA 1 #define HAVE_ALLOCA 1
#define HAVE_QSORT 1 #define HAVE_QSORT 1
#define HAVE_BSEARCH 1
#define HAVE_ABS 1 #define HAVE_ABS 1
#define HAVE_MEMSET 1 #define HAVE_MEMSET 1
#define HAVE_MEMCPY 1 #define HAVE_MEMCPY 1

View File

@ -463,6 +463,7 @@ extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite); extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)); extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
extern DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
extern DECLSPEC int SDLCALL SDL_abs(int x); extern DECLSPEC int SDLCALL SDL_abs(int x);

View File

@ -865,3 +865,4 @@
#define SDL_EncloseFPoints SDL_EncloseFPoints_REAL #define SDL_EncloseFPoints SDL_EncloseFPoints_REAL
#define SDL_IntersectFRectAndLine SDL_IntersectFRectAndLine_REAL #define SDL_IntersectFRectAndLine SDL_IntersectFRectAndLine_REAL
#define SDL_RenderGetWindow SDL_RenderGetWindow_REAL #define SDL_RenderGetWindow SDL_RenderGetWindow_REAL
#define SDL_bsearch SDL_bsearch_REAL

View File

@ -936,3 +936,4 @@ SDL_DYNAPI_PROC(void,SDL_UnionFRect,(const SDL_FRect *a, const SDL_FRect *b, SDL
SDL_DYNAPI_PROC(SDL_bool,SDL_EncloseFPoints,(const SDL_FPoint *a, int b, const SDL_FRect *c, SDL_FRect *d),(a,b,c,d),return) SDL_DYNAPI_PROC(SDL_bool,SDL_EncloseFPoints,(const SDL_FPoint *a, int b, const SDL_FRect *c, SDL_FRect *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_IntersectFRectAndLine,(const SDL_FRect *a, float *b, float *c, float *d, float *e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(SDL_bool,SDL_IntersectFRectAndLine,(const SDL_FRect *a, float *b, float *c, float *d, float *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_RenderGetWindow,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_RenderGetWindow,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(void*,SDL_bsearch,(const void *a, const void *b, size_t c, size_t d, int (*e)(const void *, const void *)),(a,b,c,d,e),return)

View File

@ -534,5 +534,38 @@ extern void qsortG(void *base, size_t nmemb, size_t size,
#endif /* HAVE_QSORT */ #endif /* HAVE_QSORT */
void *
SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compare)(const void *, const void *))
{
#if defined(HAVE_BSEARCH)
return bsearch(key, base, nmemb, size, compare);
#else
/* SDL's replacement: Taken from the Public Domain C Library (PDCLib):
Permission is granted to use, modify, and / or redistribute at will.
*/
const void *pivot;
size_t corr;
int rc;
while (nmemb) {
/* algorithm needs -1 correction if remaining elements are an even number. */
corr = nmemb % 2;
nmemb /= 2;
pivot = (const char *)base + (nmemb * size);
rc = compare(key, pivot);
if (rc > 0) {
base = (const char *)pivot + size;
/* applying correction */
nmemb -= (1 - corr);
} else if (rc == 0) {
return (void *)pivot;
}
}
return NULL;
#endif /* HAVE_BSEARCH */
}
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */