41 #include <fc_config.h>
50 #ifdef FREECIV_MSWINDOWS
79 char *dest =
new char[strlen(str) + 1];
91 auto left = QString::fromUtf8(str0);
92 auto right = QString::fromUtf8(str1);
93 return left.compare(right, Qt::CaseInsensitive);
102 auto left = QString::fromUtf8(str0);
103 auto right = QString::fromUtf8(str1);
104 return left.leftRef(n).compare(right.leftRef(n), Qt::CaseInsensitive);
119 const char *
const max = buf + buf_len - 2;
121 while (*str !=
'\0' && dest < max) {
155 copy.reserve(str.length());
158 for (
const auto &c : str) {
159 if (escape && full_escapes) {
160 switch (c.unicode()) {
171 }
else if (c ==
'\\') {
180 copy.replace(
"\\\n",
"\n");
198 if (str[0] ==
'"' && str[
len - 1] ==
'"') {
211 auto left = QString::fromUtf8(str0);
212 auto right = QString::fromUtf8(str1);
213 if (left.startsWith(QLatin1String(
"\""))
214 && left.endsWith(QLatin1String(
"\""))) {
215 left = left.mid(1, left.length() - 2);
217 if (right.startsWith(QLatin1String(
"\""))
218 && right.endsWith(QLatin1String(
"\""))) {
219 right = right.mid(1, right.length() - 2);
221 return left.leftRef(n).compare(right.leftRef(n), Qt::CaseInsensitive);
229 return strcoll(str0, str1);
240 #if defined(ENABLE_NLS) && defined(HAVE__STRICOLL)
241 return _stricoll(str0, str1);
242 #elif defined(ENABLE_NLS) && defined(HAVE_STRICOLL)
243 return stricoll(str0, str1);
244 #elif defined(ENABLE_NLS) && defined(HAVE_STRCASECOLL)
245 return strcasecoll(str0, str1);
255 FILE *
fc_fopen(
const char *filename,
const char *opentype)
257 #ifdef FREECIV_MSWINDOWS
259 char *filename_in_local_encoding =
262 result = fopen(filename_in_local_encoding, opentype);
263 free(filename_in_local_encoding);
266 return fopen(filename, opentype);
276 #ifdef FREECIV_MSWINDOWS
278 char *filename_in_local_encoding =
281 result = remove(filename_in_local_encoding);
282 free(filename_in_local_encoding);
285 return remove(filename);
293 int fc_stat(
const char *filename,
struct stat *buf)
295 #ifdef FREECIV_MSWINDOWS
297 char *filename_in_local_encoding =
300 result = stat(filename_in_local_encoding, buf);
301 free(filename_in_local_encoding);
304 return stat(filename, buf);
313 #ifdef FREECIV_MSWINDOWS
314 return GetLastError();
330 #ifdef FREECIV_MSWINDOWS
331 static char buf[256];
333 if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
334 | FORMAT_MESSAGE_IGNORE_INSERTS,
335 nullptr, err, 0, buf,
sizeof(buf),
nullptr)) {
336 fc_snprintf(buf,
sizeof(buf),
_(
"error %ld (failed FormatMessage)"),
341 static char buf[256];
349 void fc_usleep(
unsigned long usec) { QThread::usleep(usec); }
359 size_t len_search, len_replace;
363 if (search ==
nullptr || replace ==
nullptr) {
367 len_search = qstrlen(search);
368 len_replace = qstrlen(replace);
371 while (s !=
nullptr) {
372 p = strstr(s, search);
378 if (
len < (strlen(str) + len_replace - len_search + 1)) {
383 memmove(p + len_replace, p + len_search, qstrlen(p + len_search) + 1);
384 memcpy(p, replace, len_replace);
418 auto source = QString::fromUtf8(src);
423 size_t cut_at = n - 1;
426 encoded = source.leftRef(cut_at--).toUtf8();
427 }
while (cut_at > 0 && encoded.size() + 1 > n);
437 memcpy(dest, encoded.data(), encoded.size() + 1);
438 return encoded.size() + 1;
452 start = qstrlen(dest);
456 return fc_strlcpy(dest + start, src, n - start) + start;
511 #define VSNP_BUF_SIZE (64 * 1024)
523 r = vsnprintf(str, n, format, ap);
544 va_start(ap, format);
577 va_start(ap, format);
580 return (-1 == ret ? -1 : ret +
len);
588 auto name = QHostInfo::localHostName();
599 size_t slen =
static_cast<size_t>(qstrlen(str));
605 bool double_break =
false;
606 if (str && *str !=
'\0' && slen > desired_len) {
612 for (c = str; c < str + desired_len; c++) {
625 for (c = str + desired_len; c > str; c--) {
626 if (QChar::isSpace(*c)) {
639 for (c = str + desired_len + 1; *c !=
'\0'; c++) {
640 if (QChar::isSpace(*c)) {
659 #ifdef HAVE_AT_QUICK_EXIT
660 return at_quick_exit(
func);
char * local_to_internal_string_buffer(const char *text, char *buf, size_t bufsz)
char * internal_to_local_string_malloc(const char *text)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
int fc_gethostname(char *buf, size_t len)
Call gethostname() if supported, else just returns -1.
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
void make_escapes(const char *str, char *buf, size_t buf_len)
Copies a string and convert the following characters:
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
void fc_usleep(unsigned long usec)
Suspend execution for the specified number of microseconds.
char * real_fc_strdup(const char *str, const char *called_as, int line, const char *file)
Function used by fc_strdup macro, strdup() replacement No need to check return value.
size_t fc_strlcat(char *dest, const char *src, size_t n)
fc_strlcat() provides utf-8 version of (non-standard) function strlcat() It is intended as more user-...
bool fc_strrep(char *str, size_t len, const char *search, const char *replace)
Replace 'search' by 'replace' within 'str'.
int cat_snprintf(char *str, size_t n, const char *format,...)
cat_snprintf is like a combination of fc_snprintf and fc_strlcat; it does snprintf to the end of an e...
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
const char * fc_strerror(fc_errno err)
Return a string which describes a given error (errno-style.) The string is converted as necessary fro...
QString remove_escapes(const QString &str, bool full_escapes)
Copies a string.
int fc_break_lines(char *str, size_t desired_len)
Replace the spaces by line breaks when the line lenght is over the desired one.
int fc_strcoll(const char *str0, const char *str1)
Wrapper function for strcoll().
int fc_stat(const char *filename, struct stat *buf)
Wrapper function for stat() with filename conversion to local encoding on Windows.
int fc_at_quick_exit(void(*func)())
Set quick_exit() callback if possible.
int fc_strncasequotecmp(const char *str0, const char *str1, size_t n)
Compare strings like strncasecmp() but ignoring surrounding quotes in either string.
FILE * fc_fopen(const char *filename, const char *opentype)
Wrapper function for fopen() with filename conversion to local encoding on Windows.
size_t effectivestrlenquote(const char *str)
Count length of string without possible surrounding quotes.
int fc_stricoll(const char *str0, const char *str1)
Wrapper function for stricoll().
int fc_remove(const char *filename)
Wrapper function for remove() with filename conversion to local encoding on Windows.
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Compare strings like strncmp(), but ignoring case.
fc_errno fc_get_errno()
Returns last error code.