mirror of https://github.com/encounter/SDL.git
Fixed some accidental uses of external C runtime functions
This commit is contained in:
parent
5d455cabf9
commit
345c161feb
|
@ -113,11 +113,11 @@ LoadNASLibrary(void)
|
|||
/* Copy error string so we can use it in a new SDL_SetError(). */
|
||||
const char *origerr = SDL_GetError();
|
||||
const size_t len = SDL_strlen(origerr) + 1;
|
||||
char *err = (char *) alloca(len);
|
||||
char *err = SDL_stack_alloc(char, len);
|
||||
SDL_strlcpy(err, origerr, len);
|
||||
SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s", nas_library, err);
|
||||
SDL_stack_free(err);
|
||||
retval = -1;
|
||||
SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s",
|
||||
nas_library, err);
|
||||
} else {
|
||||
retval = load_nas_syms();
|
||||
if (retval < 0) {
|
||||
|
|
|
@ -386,7 +386,7 @@ SDL_EVDEV_kbd_init(void)
|
|||
}
|
||||
|
||||
/* Allow inhibiting keyboard mute with env. variable for debugging etc. */
|
||||
if (getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) {
|
||||
if (SDL_getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) {
|
||||
/* Mute the keyboard so keystrokes only generate evdev events
|
||||
* and do not leak through to the console
|
||||
*/
|
||||
|
|
|
@ -245,7 +245,7 @@ SDL_GetBasePath(void)
|
|||
|
||||
if (retval != NULL) {
|
||||
/* try to shrink buffer... */
|
||||
char *ptr = (char *) SDL_realloc(retval, strlen(retval) + 1);
|
||||
char *ptr = (char *) SDL_realloc(retval, SDL_strlen(retval) + 1);
|
||||
if (ptr != NULL)
|
||||
retval = ptr; /* oh well if it failed. */
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ SDL_SYS_HapticInit(void)
|
|||
i = 0;
|
||||
for (j = 0; j < MAX_HAPTICS; ++j) {
|
||||
|
||||
snprintf(path, PATH_MAX, joydev_pattern, i++);
|
||||
SDL_snprintf(path, PATH_MAX, joydev_pattern, i++);
|
||||
MaybeAddDevice(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -621,7 +621,7 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
|
|||
ctx->m_eControllerType = (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType;
|
||||
|
||||
// Bytes 4-9: MAC address (big-endian)
|
||||
memcpy(ctx->m_rgucMACAddress, reply->deviceInfo.rgucMACAddress, sizeof(ctx->m_rgucMACAddress));
|
||||
SDL_memcpy(ctx->m_rgucMACAddress, reply->deviceInfo.rgucMACAddress, sizeof(ctx->m_rgucMACAddress));
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
|
|
@ -482,7 +482,7 @@ HIDAPI_UpdateDiscovery()
|
|||
if (buf.event.len > 0 &&
|
||||
!SDL_HIDAPI_discovery.m_bHaveDevicesChanged) {
|
||||
if (StrHasPrefix(buf.event.name, "hidraw") &&
|
||||
StrIsInteger(buf.event.name + strlen ("hidraw"))) {
|
||||
StrIsInteger(buf.event.name + SDL_strlen ("hidraw"))) {
|
||||
SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
|
||||
/* We found an hidraw change. We still continue to
|
||||
* drain the inotify fd to avoid leaving old
|
||||
|
@ -494,7 +494,7 @@ HIDAPI_UpdateDiscovery()
|
|||
remain -= len;
|
||||
|
||||
if (remain != 0) {
|
||||
memmove(&buf.storage[0], &buf.storage[len], remain);
|
||||
SDL_memmove(&buf.storage[0], &buf.storage[len], remain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -529,7 +529,7 @@ LINUX_InotifyJoystickDetect(void)
|
|||
while (remain > 0) {
|
||||
if (buf.event.len > 0) {
|
||||
if (StrHasPrefix(buf.event.name, "event") &&
|
||||
StrIsInteger(buf.event.name + strlen ("event"))) {
|
||||
StrIsInteger(buf.event.name + SDL_strlen ("event"))) {
|
||||
char path[PATH_MAX];
|
||||
|
||||
SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", buf.event.name);
|
||||
|
@ -547,7 +547,7 @@ LINUX_InotifyJoystickDetect(void)
|
|||
remain -= len;
|
||||
|
||||
if (remain != 0) {
|
||||
memmove (&buf.storage[0], &buf.storage[len], remain);
|
||||
SDL_memmove (&buf.storage[0], &buf.storage[len], remain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,14 +44,17 @@ static const char *sys_class_power_supply_path = "/sys/class/power_supply";
|
|||
static int
|
||||
open_power_file(const char *base, const char *node, const char *key)
|
||||
{
|
||||
const size_t pathlen = strlen(base) + strlen(node) + strlen(key) + 3;
|
||||
char *path = (char *) alloca(pathlen);
|
||||
int fd;
|
||||
const size_t pathlen = SDL_strlen(base) + SDL_strlen(node) + SDL_strlen(key) + 3;
|
||||
char *path = SDL_stack_alloc(char, pathlen);
|
||||
if (path == NULL) {
|
||||
return -1; /* oh well. */
|
||||
}
|
||||
|
||||
snprintf(path, pathlen, "%s/%s/%s", base, node, key);
|
||||
return open(path, O_RDONLY | O_CLOEXEC);
|
||||
fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
SDL_stack_free(path);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,20 +149,20 @@ check_proc_acpi_battery(const char * node, SDL_bool * have_battery,
|
|||
|
||||
ptr = &state[0];
|
||||
while (make_proc_acpi_key_val(&ptr, &key, &val)) {
|
||||
if (strcmp(key, "present") == 0) {
|
||||
if (strcmp(val, "yes") == 0) {
|
||||
if (SDL_strcmp(key, "present") == 0) {
|
||||
if (SDL_strcmp(val, "yes") == 0) {
|
||||
*have_battery = SDL_TRUE;
|
||||
}
|
||||
} else if (strcmp(key, "charging state") == 0) {
|
||||
} else if (SDL_strcmp(key, "charging state") == 0) {
|
||||
/* !!! FIXME: what exactly _does_ charging/discharging mean? */
|
||||
if (strcmp(val, "charging/discharging") == 0) {
|
||||
if (SDL_strcmp(val, "charging/discharging") == 0) {
|
||||
charge = SDL_TRUE;
|
||||
} else if (strcmp(val, "charging") == 0) {
|
||||
} else if (SDL_strcmp(val, "charging") == 0) {
|
||||
charge = SDL_TRUE;
|
||||
}
|
||||
} else if (strcmp(key, "remaining capacity") == 0) {
|
||||
} else if (SDL_strcmp(key, "remaining capacity") == 0) {
|
||||
char *endptr = NULL;
|
||||
const int cvt = (int) strtol(val, &endptr, 10);
|
||||
const int cvt = (int) SDL_strtol(val, &endptr, 10);
|
||||
if (*endptr == ' ') {
|
||||
remaining = cvt;
|
||||
}
|
||||
|
@ -168,9 +171,9 @@ check_proc_acpi_battery(const char * node, SDL_bool * have_battery,
|
|||
|
||||
ptr = &info[0];
|
||||
while (make_proc_acpi_key_val(&ptr, &key, &val)) {
|
||||
if (strcmp(key, "design capacity") == 0) {
|
||||
if (SDL_strcmp(key, "design capacity") == 0) {
|
||||
char *endptr = NULL;
|
||||
const int cvt = (int) strtol(val, &endptr, 10);
|
||||
const int cvt = (int) SDL_strtol(val, &endptr, 10);
|
||||
if (*endptr == ' ') {
|
||||
maximum = cvt;
|
||||
}
|
||||
|
@ -225,8 +228,8 @@ check_proc_acpi_ac_adapter(const char * node, SDL_bool * have_ac)
|
|||
|
||||
ptr = &state[0];
|
||||
while (make_proc_acpi_key_val(&ptr, &key, &val)) {
|
||||
if (strcmp(key, "state") == 0) {
|
||||
if (strcmp(val, "on-line") == 0) {
|
||||
if (SDL_strcmp(key, "state") == 0) {
|
||||
if (SDL_strcmp(val, "on-line") == 0) {
|
||||
*have_ac = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -315,7 +318,7 @@ static SDL_bool
|
|||
int_string(char *str, int *val)
|
||||
{
|
||||
char *endptr = NULL;
|
||||
*val = (int) strtol(str, &endptr, 0);
|
||||
*val = (int) SDL_strtol(str, &endptr, 0);
|
||||
return ((*str != '\0') && (*endptr == '\0'));
|
||||
}
|
||||
|
||||
|
@ -377,8 +380,8 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
|
|||
if (!next_string(&ptr, &str)) { /* remaining battery life percent */
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (str[strlen(str) - 1] == '%') {
|
||||
str[strlen(str) - 1] = '\0';
|
||||
if (str[SDL_strlen(str) - 1] == '%') {
|
||||
str[SDL_strlen(str) - 1] = '\0';
|
||||
}
|
||||
if (!int_string(str, &battery_percent)) {
|
||||
return SDL_FALSE;
|
||||
|
@ -392,7 +395,7 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
|
|||
|
||||
if (!next_string(&ptr, &str)) { /* remaining battery life time units */
|
||||
return SDL_FALSE;
|
||||
} else if (strcmp(str, "min") == 0) {
|
||||
} else if (SDL_strcmp(str, "min") == 0) {
|
||||
battery_time *= 60;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,14 +141,12 @@ static int get_dricount(void)
|
|||
|
||||
if (!(stat(KMSDRM_DRI_PATH, &sb) == 0
|
||||
&& S_ISDIR(sb.st_mode))) {
|
||||
printf("The path %s cannot be opened or is not available\n",
|
||||
KMSDRM_DRI_PATH);
|
||||
/*printf("The path %s cannot be opened or is not available\n", KMSDRM_DRI_PATH);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (access(KMSDRM_DRI_PATH, F_OK) == -1) {
|
||||
printf("The path %s cannot be opened\n",
|
||||
KMSDRM_DRI_PATH);
|
||||
/*printf("The path %s cannot be opened\n", KMSDRM_DRI_PATH);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -437,7 +437,7 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS,
|
|||
}
|
||||
|
||||
/* Get the list of displays supported by this plane. */
|
||||
supported_displays = (VkDisplayKHR*)malloc(sizeof(VkDisplayKHR) * supported_displays_count);
|
||||
supported_displays = (VkDisplayKHR*)SDL_malloc(sizeof(VkDisplayKHR) * supported_displays_count);
|
||||
vkGetDisplayPlaneSupportedDisplaysKHR(gpu, i,
|
||||
&supported_displays_count, supported_displays);
|
||||
|
||||
|
@ -458,8 +458,9 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS,
|
|||
}
|
||||
|
||||
/* Free the list of displays supported by this plane. */
|
||||
if (supported_displays)
|
||||
free(supported_displays);
|
||||
if (supported_displays) {
|
||||
SDL_free(supported_displays);
|
||||
}
|
||||
|
||||
/* If the display is not supported by this plane, iterate to the next plane. */
|
||||
if (!plane_supports_display) {
|
||||
|
|
Loading…
Reference in New Issue