Feature #214 ยป 0028-support.c-Replace-NULLs-with-nullptrs.patch
| utility/support.c | ||
|---|---|---|
|
static bool support_initialized = FALSE;
|
||
|
static int icu_buffer_uchars = 0;
|
||
|
static UChar *icu_buffer1 = NULL;
|
||
|
static UChar *icu_buffer2 = NULL;
|
||
|
static UChar *icu_buffer1 = nullptr;
|
||
|
static UChar *icu_buffer2 = nullptr;
|
||
|
fc_mutex icu_buffer_mutex;
|
||
|
#ifndef HAVE_WORKING_VSNPRINTF
|
||
|
static char *vsnprintf_buf = NULL;
|
||
|
static char *vsnprintf_buf = nullptr;
|
||
|
static fc_mutex vsnprintf_mutex;
|
||
|
#endif /* HAVE_WORKING_VSNPRINTF */
|
||
| ... | ... | |
|
****************************************************************************/
|
||
|
static void icu_buffers_initial(void)
|
||
|
{
|
||
|
if (icu_buffer1 == NULL) {
|
||
|
if (icu_buffer1 == nullptr) {
|
||
|
icu_buffer_uchars = 1024;
|
||
|
icu_buffer1 = fc_malloc((icu_buffer_uchars + 1) * sizeof(UChar));
|
||
|
icu_buffer2 = fc_malloc((icu_buffer_uchars + 1) * sizeof(UChar));
|
||
| ... | ... | |
|
****************************************************************************/
|
||
|
static void fc_strAPI_free(void)
|
||
|
{
|
||
|
if (icu_buffer1 != NULL) {
|
||
|
if (icu_buffer1 != nullptr) {
|
||
|
free(icu_buffer1);
|
||
|
icu_buffer1 = NULL;
|
||
|
icu_buffer1 = nullptr;
|
||
|
free(icu_buffer2);
|
||
|
icu_buffer2 = NULL;
|
||
|
icu_buffer2 = nullptr;
|
||
|
icu_buffer_uchars = 0;
|
||
|
}
|
||
|
fc_mutex_destroy(&icu_buffer_mutex);
|
||
| ... | ... | |
|
bool enough_mem = FALSE;
|
||
|
int ret;
|
||
|
if (str0 == NULL) {
|
||
|
if (str0 == nullptr) {
|
||
|
return -1;
|
||
|
}
|
||
|
if (str1 == NULL) {
|
||
|
if (str1 == nullptr) {
|
||
|
return 1;
|
||
|
}
|
||
| ... | ... | |
|
bool enough_mem = FALSE;
|
||
|
int ret;
|
||
|
if (str0 == NULL) {
|
||
|
if (str0 == nullptr) {
|
||
|
return -1;
|
||
|
}
|
||
|
if (str1 == NULL) {
|
||
|
if (str1 == nullptr) {
|
||
|
return 1;
|
||
|
}
|
||
| ... | ... | |
|
size_t len1;
|
||
|
size_t cmplen;
|
||
|
if (str0 == NULL) {
|
||
|
if (str0 == nullptr) {
|
||
|
return -1;
|
||
|
}
|
||
|
if (str1 == NULL) {
|
||
|
if (str1 == nullptr) {
|
||
|
return 1;
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
/************************************************************************//**
|
||
|
Return the needle in the haystack (or NULL).
|
||
|
Return the needle in the haystack (or nullptr).
|
||
|
Naive implementation.
|
||
|
****************************************************************************/
|
||
|
char *fc_strcasestr(const char *haystack, const char *needle)
|
||
| ... | ... | |
|
size_t needles;
|
||
|
const char *p;
|
||
|
if (NULL == needle || '\0' == *needle) {
|
||
|
if (needle == nullptr || '\0' == *needle) {
|
||
|
return (char *)haystack;
|
||
|
}
|
||
|
if (NULL == haystack || '\0' == *haystack) {
|
||
|
return NULL;
|
||
|
if (haystack == nullptr || '\0' == *haystack) {
|
||
|
return nullptr;
|
||
|
}
|
||
|
haystacks = strlen(haystack);
|
||
|
needles = strlen(needle);
|
||
|
if (haystacks < needles) {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
for (p = haystack; p <= &haystack[haystacks - needles]; p++) {
|
||
| ... | ... | |
|
return (char *)p;
|
||
|
}
|
||
|
}
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
#endif /* HAVE_STRCASESTR */
|
||
|
}
|
||
| ... | ... | |
|
#ifdef HAVE_FOPEN_S
|
||
|
if (fopen_s(&result, real_filename, opentype) != 0) {
|
||
|
result = NULL;
|
||
|
result = nullptr;
|
||
|
}
|
||
|
#else /* HAVE_FOPEN_S */
|
||
|
result = fopen(real_filename, opentype);
|
||
| ... | ... | |
|
static char buf[256];
|
||
|
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||
|
NULL, err, 0, buf, sizeof(buf), NULL)) {
|
||
|
nullptr, err, 0, buf, sizeof(buf), nullptr)) {
|
||
|
fc_snprintf(buf, sizeof(buf),
|
||
|
_("error %ld (failed FormatMessage)"), err);
|
||
|
}
|
||
| ... | ... | |
|
ts.tv_nsec = usec * 1000;
|
||
|
}
|
||
|
nanosleep(&ts, NULL);
|
||
|
nanosleep(&ts, nullptr);
|
||
|
#else /* HAVE_NANOSLEEP */
|
||
|
#ifdef HAVE_USLEEP
|
||
|
usleep(usec);
|
||
| ... | ... | |
|
tv.tv_usec = usec;
|
||
|
/* FIXME: an interrupt can cause an EINTR return here. In that case we
|
||
|
* need to have another select call. */
|
||
|
fc_select(0, NULL, NULL, NULL, &tv);
|
||
|
fc_select(0, nullptr, nullptr, nullptr, &tv);
|
||
|
#endif /* FREECIV_MSWINDOWS */
|
||
|
#endif /* HAVE_SNOOZE */
|
||
|
#endif /* HAVE_USLEEP */
|
||
| ... | ... | |
|
{
|
||
|
size_t len_max;
|
||
|
fc_assert_ret_val(str != NULL, NULL);
|
||
|
fc_assert_ret_val(len != NULL, NULL);
|
||
|
fc_assert_ret_val(str != nullptr, nullptr);
|
||
|
fc_assert_ret_val(len != nullptr, nullptr);
|
||
|
if (search == NULL || replace == NULL) {
|
||
|
if (search == nullptr || replace == nullptr) {
|
||
|
return str;
|
||
|
}
|
||
| ... | ... | |
|
fc_strrep(str, (*len), search, replace);
|
||
|
/* Should never happen */
|
||
|
fc_assert_ret_val_msg(success, NULL,
|
||
|
fc_assert_ret_val_msg(success, nullptr,
|
||
|
"Can't replace '%s' by '%s' in '%s'. Too small "
|
||
|
"size after reallocation: " SIZE_T_PRINTF ".",
|
||
|
search, replace, str, *len);
|
||
| ... | ... | |
|
size_t len_search, len_replace;
|
||
|
char *s, *p;
|
||
|
fc_assert_ret_val(str != NULL, FALSE);
|
||
|
fc_assert_ret_val(str != nullptr, FALSE);
|
||
|
if (search == NULL || replace == NULL) {
|
||
|
if (search == nullptr || replace == nullptr) {
|
||
|
return TRUE;
|
||
|
}
|
||
| ... | ... | |
|
len_replace = strlen(replace);
|
||
|
s = str;
|
||
|
while (s != NULL) {
|
||
|
while (s != nullptr) {
|
||
|
p = strstr(s, search);
|
||
|
if (p == NULL) {
|
||
|
if (p == nullptr) {
|
||
|
/* Nothing found */
|
||
|
break;
|
||
|
}
|
||
| ... | ... | |
|
int dlen;
|
||
|
UErrorCode err_code = U_ZERO_ERROR;
|
||
|
fc_assert_ret_val(NULL != dest, -1);
|
||
|
fc_assert_ret_val(NULL != src, -1);
|
||
|
fc_assert_ret_val(dest != nullptr, -1);
|
||
|
fc_assert_ret_val(src != nullptr, -1);
|
||
|
fc_assert_ret_val(0 < n, -1);
|
||
|
if (icu_buffer_uchars == 0) {
|
||
| ... | ... | |
|
fc_mutex_allocate(&vsnprintf_mutex);
|
||
|
if (vsnprintf_buf == NULL) {
|
||
|
if (vsnprintf_buf == nullptr) {
|
||
|
vsnprintf_buf = malloc(VSNP_BUF_SIZE);
|
||
|
if (vsnprintf_buf == NULL) {
|
||
|
if (vsnprintf_buf == nullptr) {
|
||
|
fprintf(stderr, "Could not allocate %i bytes for vsnprintf() "
|
||
|
"replacement.", VSNP_BUF_SIZE);
|
||
|
fc_mutex_release(&vsnprintf_mutex);
|
||
| ... | ... | |
|
it does snprintf() to the end of an existing string.
|
||
|
Like fc_strlcat(), n is the total length available for str, including
|
||
|
existing contents and trailing NULL. If there is no extra room
|
||
|
existing contents and trailing nullptr. If there is no extra room
|
||
|
available in str, does not change the string.
|
||
|
Also like fc_strlcat, returns the final length that str would have
|
||
|
Also like fc_strlcat(), returns the final length that str would have
|
||
|
had without truncation, or -1 if the end of the buffer is reached.
|
||
|
I.e., if return is >= n, truncation occurred.
|
||
| ... | ... | |
|
}
|
||
|
console_buf[0] = '\0';
|
||
|
console_thread = (HANDLE) CreateThread(NULL, 0, windows_console_thread,
|
||
|
NULL, 0, NULL);
|
||
|
console_thread = (HANDLE) CreateThread(nullptr, 0, windows_console_thread,
|
||
|
nullptr, 0, nullptr);
|
||
|
#else /* FREECIV_MSWINDOWS */
|
||
|
static bool initialized = FALSE;
|
||
| ... | ... | |
|
return console_buf;
|
||
|
}
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
#else /* FREECIV_MSWINDOWS */
|
||
|
if (!feof(stdin)) { /* input from server operator */
|
||
|
static char *bufptr = console_buf;
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
#endif /* FREECIV_MSWINDOWS */
|
||
|
}
|
||
| ... | ... | |
|
support_initialized = FALSE;
|
||
|
#ifndef HAVE_WORKING_VSNPRINTF
|
||
|
if (vsnprintf_buf != NULL) {
|
||
|
if (vsnprintf_buf != nullptr) {
|
||
|
free(vsnprintf_buf);
|
||
|
vsnprintf_buf = NULL;
|
||
|
vsnprintf_buf = nullptr;
|
||
|
}
|
||
|
fc_mutex_destroy(&vsnprintf_mutex);
|
||
|
#endif /* HAVE_WORKING_VSNPRINTF */
|
||