Freeciv-3.3
Loading...
Searching...
No Matches
Macros | Functions | Variables
support.c File Reference
#include "fc_prehdrs.h"
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "unicode/ustring.h"
#include "fciconv.h"
#include "fcintl.h"
#include "fcthread.h"
#include "log.h"
#include "mem.h"
#include "netintf.h"
#include "support.h"

Go to the source code of this file.

Macros

#define VSNP_BUF_SIZE   (8096*1024)
 

Functions

static void icu_buffers_initial (void)
 
static void icu_buffers_increase (void)
 
static void fc_strAPI_init (void)
 
static void fc_strAPI_free (void)
 
int fc_strcasecmp (const char *str0, const char *str1)
 
int fc_strncasecmp (const char *str0, const char *str1, size_t n)
 
void make_escapes (const char *str, char *buf, size_t buf_len)
 
void remove_escapes (const char *str, bool full_escapes, char *buf, size_t buf_len)
 
size_t effectivestrlenquote (const char *str)
 
int fc_strncasequotecmp (const char *str0, const char *str1, size_t n)
 
charfc_strcasestr (const char *haystack, const char *needle)
 
int fc_strcoll (const char *str0, const char *str1)
 
int fc_stricoll (const char *str0, const char *str1)
 
FILEfc_fopen (const char *filename, const char *opentype)
 
int fc_remove (const char *filename)
 
int fc_stat (const char *filename, struct stat *buf)
 
fc_errno fc_get_errno (void)
 
const charfc_strerror (fc_errno err)
 
void fc_usleep (unsigned long usec)
 
charfc_strrep_resize (char *str, size_t *len, const char *search, const char *replace)
 
bool fc_strrep (char *str, size_t len, const char *search, const char *replace)
 
size_t fc_strlcpy (char *dest, const char *src, size_t n)
 
size_t fc_strlcat (char *dest, const char *src, size_t n)
 
int fc_vsnprintf (char *str, size_t n, const char *format, va_list ap)
 
int fc_snprintf (char *str, size_t n, const char *format,...)
 
int cat_snprintf (char *str, size_t n, const char *format,...)
 
int fc_gethostname (char *buf, size_t len)
 
bool is_reg_file_for_access (const char *name, bool write_access)
 
int fc_break_lines (char *str, size_t desired_len)
 
bool fc_isalnum (char c)
 
bool fc_isalpha (char c)
 
bool fc_isdigit (char c)
 
bool fc_isprint (char c)
 
bool fc_isspace (char c)
 
bool fc_isupper (char c)
 
char fc_toupper (char c)
 
char fc_tolower (char c)
 
const charfc_basename (const char *path)
 
struct tmfc_localtime (const time_t *timep, struct tm *result)
 
int fc_at_quick_exit (void(*func)(void))
 
void fc_support_init (void)
 
void fc_support_free (void)
 
bool are_support_services_available (void)
 

Variables

static bool support_initialized = FALSE
 
static int icu_buffer_uchars = 0
 
static UCharicu_buffer1 = nullptr
 
static UCharicu_buffer2 = nullptr
 
fc_mutex icu_buffer_mutex
 
static charvsnprintf_buf = nullptr
 
static fc_mutex vsnprintf_mutex
 
static fc_mutex localtime_mutex
 

Macro Definition Documentation

◆ VSNP_BUF_SIZE

#define VSNP_BUF_SIZE   (8096*1024)

vsnprintf() replacement using a big malloc()ed internal buffer, originally by David Pfitzner dwp@m.nosp@m.so.a.nosp@m.nu.ed.nosp@m.u.au

Parameter n specifies the maximum number of characters to produce. This includes the trailing null, so n should be the actual number of characters allocated (or sizeof for char array). If truncation occurs, the result will still be null-terminated. (I'm not sure whether all native vsnprintf() functions null-terminate on truncation; this does so even if calls native function.)

Return value: if there is no truncation, returns the number of characters printed, not including the trailing null. If truncation does occur, returns the number of characters which would have been produced without truncation. (Linux man page says returns -1 on truncation, but glibc seems to do as above nevertheless; configure tests this.)

[glibc is correct. Viz.

PRINTF(3) Linux Programmer's Manual PRINTF(3)

(Thus until glibc 2.0.6. Since glibc 2.1 these functions follow the C99 standard and return the number of characters (excluding the trailing '\0') which would have been written to the final string if enough space had been available.)]

The method is simply to malloc (first time called) a big internal buffer, longer than any result is likely to be (for non-malicious usage), then vsprintf to that buffer, and copy the appropriate number of characters to the destination. Thus, this is not 100% safe. But somewhat safe, and at least safer than using raw snprintf! :-) (And of course if you have the native version it is safe.)

Before rushing to provide a 100% safe replacement version, consider the following advantages of this method:

  • It is very simple, so not likely to have many bugs (other than arguably the core design bug regarding absolute safety), nor need maintenance.
  • It uses native vsprintf() (which is required), thus exactly duplicates the native format-string parsing/conversions.
  • It is very portable. Eg, it does not require mprotect(), nor does it do any of its own parsing of the format string, nor use any tricks to go through the va_list twice.

See also fc_utf8_vsnprintf_trunc(), fc_utf8_vsnprintf_rep().

Definition at line 885 of file support.c.

Function Documentation

◆ are_support_services_available()

bool are_support_services_available ( void  )

Is the support module currently in usable state?

Definition at line 1369 of file support.c.

Referenced by audio_shutdown_atexit().

◆ cat_snprintf()

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 existing string.

Like fc_strlcat(), n is the total length available for str, including 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 had without truncation, or -1 if the end of the buffer is reached. I.e., if return is >= n, truncation occurred.

See also cat_utf8_snprintf(), cat_utf8_snprintf_rep().

Definition at line 986 of file support.c.

Referenced by append_city_buycost_string(), boot_help_texts(), cardinal_index_str(), chatline_autocomplete(), conn_description(), cr_entry_attack(), cr_entry_defense(), create_command_newcomer(), delegate_command(), dem_line_item(), endgame_report_dialog_player(), fc__attribute(), fcdb_command(), format_time_duration(), fz_from_file(), get_city_dialog_illness_text(), get_city_dialog_production_full(), get_city_mapview_production(), get_infrastructure_text(), helptext_advance(), helptext_building(), helptext_extra(), helptext_extra_for_terrain_str(), helptext_goods(), helptext_government(), helptext_nation(), helptext_road_bonus_str(), helptext_specialist(), helptext_terrain(), helptext_unit(), helptext_unit_upkeep_str(), helptext_unitclass(), historian_generic(), inf_log_str(), init_city_report_game_data(), insert_allows_single(), insert_client_build_info(), insert_generated_text(), insert_veteran_help(), log_real(), mapimg_client_define(), mapimg_command(), mapimg_def2str(), mapimg_generate_name(), mapimg_show(), player_color_ftstr(), popup_advanced_terrain_dialog(), popup_unit_info(), production_help(), qtg_insert_client_build_info(), real_bodyguard_log(), real_city_log(), real_diplo_log(), real_tech_log(), real_unit_log(), redraw_unit_info_label(), report_achievements(), report_demographics(), report_top_cities(), report_wonders_of_the_world(), report_wonders_of_the_world_long(), req_text_insert(), secfile_insert_bitwise_enum_full(), secfile_insert_enum_data_full(), sg_save_map_startpos(), show_conn_popup(), show_connections(), show_help_command_list(), show_help_option_list(), show_players(), show_settings_one(), specialists_abbreviation_string(), specialists_string(), tile_get_info_text(), tileset_lookup_sprite_tags(), tileset_setup_road(), unit_select_dialog_popup(), universal_name_translation(), update_intel_dialog(), usdlg_get_unit_descr(), utype_values_string(), and valid_index_str().

◆ effectivestrlenquote()

size_t effectivestrlenquote ( const char str)

Count length of string without possible surrounding quotes.

Definition at line 356 of file support.c.

Referenced by conn_by_user_prefix(), and player_by_name_prefix().

◆ fc_at_quick_exit()

int fc_at_quick_exit ( void(*)(void func)

Set quick_exit() callback if possible.

Definition at line 1317 of file support.c.

Referenced by client_main().

◆ fc_basename()

const char * fc_basename ( const char path)

basename() replacement that always takes const parameter. POSIX basename() modifies its parameter, GNU one does not. Ideally we would like to use GNU one, when available, directly without extra string copies.

Definition at line 1287 of file support.c.

Referenced by cmdhelp_new().

◆ fc_break_lines()

int fc_break_lines ( char str,
size_t  desired_len 
)

Replace the spaces by line breaks when the line length is over the desired one. 'str' is modified. Returns number of lines in modified s.

Definition at line 1135 of file support.c.

Referenced by astr_break_lines(), create_races_dialog(), manual_commands(), manual_settings(), option_widget_new(), show_help_command(), show_help_intro(), show_help_option(), show_nationsets(), show_ruleset_info(), and show_settings_one().

◆ fc_fopen()

FILE * fc_fopen ( const char filename,
const char opentype 
)

◆ fc_get_errno()

fc_errno fc_get_errno ( void  )

◆ fc_gethostname()

int fc_gethostname ( char buf,
size_t  len 
)

Call gethostname() if supported, else just returns -1.

Definition at line 1007 of file support.c.

Referenced by establish_new_connection(), and send_lanserver_response().

◆ fc_isalnum()

bool fc_isalnum ( char  c)

Wrapper function to work around broken libc implementations. See above.

Definition at line 1196 of file support.c.

Referenced by find_option(), get_token_value(), handle_stdin_input_real(), is_legal_table_entry_name(), is_secfile_entry_name_valid(), and year_suffix().

◆ fc_isalpha()

bool fc_isalpha ( char  c)

Wrapper function to work around broken libc implementations. See above.

Definition at line 1207 of file support.c.

Referenced by extract_sequence_text(), fc_vsnprintcf(), and is_legal_table_entry_name().

◆ fc_isdigit()

bool fc_isdigit ( char  c)

Wrapper function to work around broken libc implementations. See above.

Definition at line 1218 of file support.c.

Referenced by entry_from_token(), extract_escapes(), get_token_value(), is_good_password(), is_valid_username(), str_to_float(), str_to_int(), and str_to_uint().

◆ fc_isprint()

bool fc_isprint ( char  c)

Wrapper function to work around broken libc implementations. See above.

Definition at line 1229 of file support.c.

◆ fc_isspace()

bool fc_isspace ( char  c)

◆ fc_isupper()

bool fc_isupper ( char  c)

Wrapper function to work around broken libc implementations. See above.

Definition at line 1251 of file support.c.

Referenced by is_good_password().

◆ fc_localtime()

struct tm * fc_localtime ( const time_t timep,
struct tm result 
)

Thread safe localtime() replacement

Definition at line 1301 of file support.c.

Referenced by real_luaconsole_append(), real_output_window_append(), and send_pending_events().

◆ fc_remove()

int fc_remove ( const char filename)

Wrapper function for gzopen() with filename conversion to local encoding on Windows. Wrapper function for remove() with filename conversion to local encoding on Windows.

Definition at line 555 of file support.c.

Referenced by handle_single_want_hack_reply(), and save_dialog_response_callback().

◆ fc_snprintf()

int fc_snprintf ( char str,
size_t  n,
const char format,
  ... 
)

See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().

Definition at line 960 of file support.c.

Referenced by action_requires_confirmation(), activate_gui(), requirers_dlg::add(), effect_edit::add_effect_to_list(), ai_init(), aifill(), anim_load(), append_impr_or_unit_to_menu(), append_impr_or_unit_to_menu_item(), auth_user(), backtrace_print(), begin_lanserver_scan(), beta_message(), boot_help_texts(), city_dialog::buy(), buy_callback(), trade_generator::calculate(), calendar_text(), choice_dialog_add(), choice_dialog_get_nth_button(), city_add_improvement_with_gov_notice(), city_dialog_update_building(), city_dialog_update_counters(), city_dialog_update_information(), city_dialog_update_information(), city_improvement_name_translation(), city_link(), city_model_set(), city_model_set_depr(), city_name_suggestion(), city_production_cost_str(), city_store_set(), city_tile_link(), citylog_map_data(), citylog_map_line(), cityrep_buy(), requirers_dlg::clear(), client_diplomacy_clause_string(), client_main(), client_start_server(), cmafec_get_result_descr(), cmdhelp_display(), col_citizens(), col_diplstate(), col_government(), col_idle(), compat_load_020600(), compat_load_030000(), conn_description(), conn_pattern_from_string(), conn_pattern_to_string(), convert_first_passwd_callback(), convert_passwd_callback(), convert_portnr_callback(), convert_string(), copy_chars_to_utf8_str(), cr_entry_angry(), cr_entry_build_cost(), cr_entry_build_slots(), cr_entry_building(), cr_entry_content(), cr_entry_continent(), cr_entry_corruption(), cr_entry_culture(), cr_entry_foodplus(), cr_entry_gold(), cr_entry_growturns(), cr_entry_happy(), cr_entry_history(), cr_entry_hstate_concise(), cr_entry_hstate_verbose(), cr_entry_luxury(), cr_entry_output(), cr_entry_performance(), cr_entry_plague_risk(), cr_entry_pollution(), cr_entry_present(), cr_entry_prodplus(), cr_entry_resources(), cr_entry_science(), cr_entry_size(), cr_entry_specialist(), cr_entry_supported(), cr_entry_trade_routes(), cr_entry_tradeplus(), cr_entry_unhappy(), cr_entry_waste(), cr_entry_workers(), create_ai_menu(), create_change_menu(), create_city_options_widget_list(), create_clause_menu(), create_command_newcomer(), create_command_pregame(), create_conn_menu(), create_dead_players_menu_item(), create_display_menu(), create_display_menu_item(), create_governor_menu(), create_happiness_dialog(), fc_client::create_main_page(), create_plrdlg_display_menu_item(), create_present_supported_units_widget_list(), create_ruleset_file(), create_select_menu(), create_show_menu(), create_toggle_menu_item(), create_units_order_widgets(), create_wl_menu(), create_wl_menu(), dai_city_log(), dai_player_load_relations(), dai_player_save_relations(), dai_unit_log(), city_item::data(), default_title_for_player(), deprecate_signal(), describe_vote(), desired_settable_options_update(), disband_all_units(), eco_report::disband_units(), city_widget::display_list_menu(), download_modpack_list(), download_modpack_recursive(), economy_report_dialog_popup(), economy_report_update(), edit_buffer_copy(), edit_buffer_get_status_string(), effect_edit::edit_reqs(), editinfobox_create(), editinfobox_refresh(), effect_save(), entry_path(), establish_new_connection(), event_cache_save(), events_init(), expand_dir(), explain_why_no_action_enabled(), fc_git_revision(), fc_strerror(), fc_vsnprintcf(), fileinfolist_infix(), find_next_free_port(), fix_enabler_item::fix_enabler_item(), form_chat_name(), found_new_tech(), freeciv_datafile_version(), freeciv_name_version(), fz_strerror(), city_widget::gen_production_labels(), generate_save_name(), get_challenge_filename(), get_challenge_fullname(), get_city_dialog_airlift_text(), get_city_dialog_airlift_value(), get_city_dialog_production(), get_city_dialog_production_row(), get_city_growth_string(), get_city_mapview_name_and_growth(), get_city_mapview_trade_routes(), get_city_table_header(), get_culture_info(), get_data_dirs(), get_full_nation(), get_full_username(), get_gold_info(), get_gui_specific_themes_directories(), get_help_item_spec(), get_lan_server_list(), get_locale_dir(), get_luxury_info(), get_prod_complete_string(), get_researching_info(), get_scenario_dirs(), get_science_info(), get_tax_info(), get_tile_output_text(), get_unique_guest_name(), get_units_disband_info(), get_units_upgrade_info(), get_usable_themes_in_directory(), gui_event_loop(), gui_event_loop(), gui_load_theme(), handle_login_request(), handle_tile_info(), city_model::headerData(), help_update_terrain(), helptext_advance(), helptext_extra(), helptext_extra_for_terrain_str(), helptext_unit(), helptext_unit_upkeep_str(), historian_generic(), host_factory_bind(), huts_help(), illegal_action_msg(), img_filename(), img_new(), img_playerstr(), impr_factory_bind(), init_city_report_game_data(), init_move_fragments(), init_options_button(), inputline_return(), insert_generated_text(), interpret_tilde(), interpret_tilde_alloc(), intro_expose(), intro_expose(), is_allowed_city_name(), is_allowed_to_take(), is_good_password(), is_tech_needed(), is_universal_needed(), load_action_blocked_by_list(), load_action_post_success_force(), load_city_thresholds_sprites(), load_command(), load_gfxnumber(), load_install_info_list(), load_install_info_lists(), load_muuk_as_action_auto(), load_river_sprites(), load_ruleset_governments(), load_ruleset_terrain(), load_ruleset_veteran(), log_real(), log_write(), lookup_req_list(), lua_command(), main(), makeup_connection_name(), manual_improvements(), manual_start(), mapimg_checkplayers(), mapimg_client_define(), mapimg_client_save(), mapimg_colortest(), mapimg_generate_name(), mapimg_get_format_default(), mapimg_get_format_list(), mapimg_help(), menu_entry_init(), menu_entry_init(), menu_unit_goto_and_add_accel(), menus_rename(), modinst_setup_widgets(), modinst_setup_widgets(), modinst_setup_widgets(), impr_item::mouseDoubleClickEvent(), name_and_sort_items(), netfile_add_form_int(), netfile_download_file(), netfile_download_file_core(), network_list_callback(), objprop_refresh_widget(), option_widget_new(), option_widget_update(), options_dialogs_set(), options_dialogs_update(), phasemode_help(), player_name_check(), plocation_name(), popup_advanced_terrain_dialog(), popup_bribe_stack_dialog(), popup_bribe_stack_dialog(), popup_bribe_unit_dialog(), popup_bribe_unit_dialog(), popup_change_research_goal_dialog(), popup_city_cma_dialog(), popup_conn_list_dialog(), popup_connection_dialog(), popup_diplomacy_dialog(), popup_diplomatic_objects(), popup_find_dialog(), popup_hurry_production_dialog(), popup_incite_dialog(), popup_incite_dialog(), popup_join_game_dialog(), popup_minimap_window(), popup_musicset_suggestion_dialog(), popup_players_nations_dialog(), popup_sell_impr_callback(), popup_soundset_suggestion_dialog(), popup_spaceship_dialog(), popup_terrain_info_dialog(), popup_theme_suggestion_dialog(), popup_tileset_suggestion_dialog(), popup_unit_info(), popup_unitinfo_window(), popup_upgrade_unit_callback(), popup_war_dialog(), popup_worklist_editor(), qtg_get_gui_specific_themes_directories(), rally_set_tile(), rates_set_values(), read_init_script_real(), real_activeunits_report_dialog_update(), real_bodyguard_log(), real_city_log(), real_city_report_dialog_update_city(), real_conn_list_dialog_update(), real_diplo_log(), real_economy_report_dialog_update(), real_info_city_report_dialog_update(), real_menus_init(), real_menus_update(), real_science_report_dialog_update(), real_tech_log(), real_unit_log(), real_units_report_dialog_update(), really_handle_city_buy(), rebuild_citydlg_title_str(), redraw_army_city_dialog(), redraw_city_dialog(), redraw_happiness_city_dialog(), redraw_info_city_dialog(), redraw_misc_city_dialog(), redraw_supported_units_city_dialog(), redraw_unit_info_label(), tab_enabler::refresh(), refresh_city_names(), req_edit::refresh_item(), refresh_production_label(), refresh_worklist_count_label(), register_bg_actions(), rename_worklist_editor_callback(), report_achievements(), report_demographics(), report_scroll_mouse_motion_handler(), report_top_cities(), req_vec_change_translation(), req_vec_fix_problem::req_vec_fix_problem(), request_action_confirmation(), research_advance_name_translation(), research_advance_rule_name(), research_pretty_name(), rgbcolor_from_hex(), rgbcolor_to_hex(), ruler_title_for_player(), ruleset_purge_redundant_reqs_effects(), ruleset_purge_redundant_reqs_enablers(), sanity_check_ruleset_data(), save_action_blocked_by(), save_action_post_success_force(), save_actions_ruleset(), save_buildings_ruleset(), save_cities_ruleset(), save_effects_ruleset(), save_game_auto(), save_game_ruleset(), save_governments_ruleset(), save_muuk_action_auto(), save_nation(), save_nations_ruleset(), save_ruleset(), save_styles_ruleset(), save_techs_ruleset(), save_terrain_ruleset(), save_units_ruleset(), scan_score_log(), scenario_list_callback(), score_tooltip(), scroll_mouse_motion_handler(), sdl_get_tile_defense_info_text(), secfile_insert_include(), secfile_insert_long_comment(), secfile_log(), secfile_save(), sell_all_improvements(), eco_report::sell_buildings(), sell_imprvm_dlg_callback(), eco_report::sell_redundant(), send_client_wants_hack(), send_lanserver_response(), send_pending_events(), server_player_name_is_allowed(), server_player_set_name_full(), server_sniff_all_input(), set_cma_hscrollbars(), set_indicator_icons(), set_ruleset(), set_rulesetdir(), help_widget::set_topic_terrain(), settable_options_load(), setting_bitwise_to_str(), setting_bool_to_str(), setting_enum_to_str(), setting_int_to_str(), setting_str_to_str(), settings_ruleset(), mpgui::setup(), ruledit_gui::setup(), setup_app_actions(), setup_langname(), setup_menus(), sex_name_mnemonic(), sg_load_player_cities(), sg_load_player_cities(), sg_load_player_main(), sg_load_player_main(), sg_load_player_units(), sg_load_player_units(), sg_load_player_vision(), sg_load_player_vision(), sg_load_savefile(), sg_save_map_altitude(), sg_save_map_owner(), sg_save_map_worked(), sg_save_player_cities(), sg_save_player_main(), sg_save_player_units(), sg_save_player_vision(), sg_save_random(), sg_save_ruledata(), map_view::shortcut_pressed(), show_full_citybar(), show_help_command(), show_info_popup(), show_info_popup(), show_main_page(), show_new_turn_info(), show_players(), show_scenarios(), show_tileset_error(), start_command(), strvec_to_str(), switch_lang(), fc_client::switch_page(), tab_misc::tab_misc(), team_pretty_name(), team_slot_create_default_name(), technology_load(), technology_load(), technology_save(), text_tag_init_from_sequence(), text_tag_initv(), text_tag_replace_text(), text_tag_start_sequence(), text_tag_stop_sequence(), textcalfrag(), textyear(), tgt_extra_descr(), themespec_fullname(), tile_link(), tileset_lookup_sprite_tags(), tileset_setup_citizen_types(), tileset_setup_city_tiles(), tileset_setup_extra(), tileset_setup_nation_flag(), tileset_setup_road(), tileset_setup_specialist_type(), tileset_setup_tile_type(), tileset_setup_unit_direction(), tileset_setup_unit_type_from_tag(), tilespec_fullname(), timing_log_init(), treaty_save(), ui_main(), unit_achieved_rank_string(), unit_firepower_if_not_one(), unit_link(), unit_select_dialog_popup(), unit_tile_link(), unit_tired_attack_string(), unit_upgrade_info(), unit_veteran_level_string(), units_orders_city_dlg_callback(), units_report_command_callback(), req_edit::univ_value_edit(), universal_name_translation(), universal_rule_name(), city_dialog::update_counters_table(), update_diplomacy_dialog(), update_goto_dialog(), city_dialog::update_info_label(), update_info_label(), update_infra_dialog(), update_intel_dialog(), city_dialog::update_nation_table(), update_network_page(), eco_report::update_report(), update_server_list(), fc_client::update_server_list(), fc_client::update_sidebar_tooltips(), update_start_page_buttons(), update_turn_done_tooltip(), update_turn_done_tooltip(), city_dialog::update_units(), pregamevote::update_vote(), unittype_item::upgrade_units(), usdlg_get_unit_descr(), usdlg_tab_append_activity(), usdlg_tab_append_utype(), user_username(), utype_values_string(), utype_values_translation(), valid_ruleset_filename(), value_units(), vdo_log(), voteinfo_gui_update(), write_chatline_content(), write_command(), and year_suffix().

◆ fc_stat()

int fc_stat ( const char filename,
struct stat buf 
)

Wrapper function for stat() with filename conversion to local encoding on Windows.

Definition at line 574 of file support.c.

Referenced by fileinfolist_infix(), fileinfoname(), get_usable_themes_in_directory(), is_reg_file_for_access(), load_install_info_lists(), lua_command(), script_server_load_file(), and secfile_load().

◆ fc_strAPI_free()

static void fc_strAPI_free ( void  )
static

Free string handling API resources

Definition at line 171 of file support.c.

Referenced by fc_support_free().

◆ fc_strAPI_init()

static void fc_strAPI_init ( void  )
static

Initialize string handling API

Definition at line 160 of file support.c.

Referenced by fc_strcasecmp(), fc_strlcpy(), fc_strncasecmp(), and fc_support_init().

◆ fc_strcasecmp()

int fc_strcasecmp ( const char str0,
const char str1 
)

Compare strings like strcmp(), but ignoring case. UTF8 aware.

Definition at line 186 of file support.c.

Referenced by achievement_by_rule_name(), action_by_rule_name(), advance_by_rule_name(), ai_level_help(), ai_level_name_update_cb(), ai_type_by_name(), api_edit_trait_mod_set(), api_edit_unit_hitpoints(), api_edit_unit_kill(), api_effects_city_bonus(), api_effects_player_bonus(), api_effects_tile_bonus(), api_effects_unit_bonus(), api_effects_unit_vs_tile_bonus(), api_effects_world_bonus(), api_find_role_unit_type(), api_methods_nation_trait_default(), api_methods_nation_trait_max(), api_methods_nation_trait_min(), api_methods_player_has_flag(), api_methods_player_trait(), api_methods_player_trait_base(), api_methods_player_trait_current_mod(), api_methods_unit_type_has_flag(), api_methods_unit_type_has_role(), api_utilities_str2dir(), blocked_by_old_name_3_3(), boot_help_texts(), cancelvote_command(), check_leader_names(), check_sprite_type(), city_list_find_name(), city_name_compare(), city_style_by_rule_name(), client_main(), cmdarg_compare(), cmdlevel_command(), compar_event_message_texts(), compat_load_020400(), compat_load_020500(), compat_load_020600(), compat_load_030000(), compat_load_030100(), compat_load_030200(), compat_load_030300(), conn_by_user(), conn_pattern_from_string(), counter_by_rule_name(), counter_by_translated_name(), create_diplomacy_dialog(), delegate_command(), diplrel_by_rule_name(), disaster_by_rule_name(), download_modpack_list(), download_modpack_recursive(), tab_achievement::edit_type(), effect_edit::effect_type_menu(), event_cache_load(), extra_type_by_rule_name(), fc_cmp(), fc_stricoll(), gen_action_name_update_cb(), edit_impr::genus_menu(), get_lan_server_list(), get_tag_score(), goods_by_rule_name(), government_by_rule_name(), handle_login_request(), improvement_by_rule_name(), init_character_encodings(), is_default_city_name(), is_on_allowed_list(), is_valid_username(), load_action_range_max(), load_building_names(), load_city_name_list(), load_install_info_list(), load_ruleset_buildings(), load_ruleset_effects(), load_ruleset_game(), load_ruleset_nations(), load_ruleset_techs(), load_ruleset_terrain(), load_ruleset_units(), load_tech_names(), load_terrain_names(), load_unit_names(), lookup_cbonus_list(), lookup_option_level(), main(), mapimg_define(), message_options_load(), metaconnection_command(), modpack_file_from_ruleset_cache(), modpack_file_from_tileset_cache(), modpack_tileset_target(), multiplier_by_rule_name(), effect_edit::multiplier_menu(), nation_by_rule_name(), nation_group_by_rule_name(), nation_leader_by_name(), nation_set_by_rule_name(), ordered_gfx_fextensions(), output_type_by_identifier(), player_by_name(), player_by_user(), player_by_user_delegated(), player_name_check(), playercolor_command(), req_from_str(), req_edit::req_range_menu(), req_edit::req_type_menu(), rscompat_effect_name_3_3(), rscompat_names(), rscompat_universal_name_3_3(), rscompat_utype_flag_name_3_3(), save_game_ruleset(), secfile_lookup_enum_data(), server_player_name_is_allowed(), set_ai_level_named(), setcompat_name_generic(), setcompat_S3_2_val_from_S3_1(), setting_bitwise_secfile_str(), setting_ruleset_one(), settings_game_load(), settings_list_cmp(), sex_by_name(), sg_load_game(), sg_load_player_cities(), sg_load_player_cities(), sg_load_player_city(), sg_load_player_main(), sg_load_player_main(), sg_load_player_unit(), sg_load_player_unit(), sg_load_player_vision_city(), sg_load_savefile(), sg_load_savefile(), sg_load_treaties(), sg_load_treaties(), specialist_by_rule_name(), style_by_rule_name(), team_slot_by_rule_name(), tech_class_by_rule_name(), technology_load(), technology_load(), terrain_by_rule_name(), tileset_read_toplevel(), tileset_setup_extra(), trade_route_cancelling_type_by_name(), trade_route_type_by_name(), ui_name_old_name_3_3(), unit_class_by_rule_name(), unit_type_by_rule_name(), universal_by_rule_name(), and universal_value_from_str().

◆ fc_strcasestr()

char * fc_strcasestr ( const char haystack,
const char needle 
)

Return the needle in the haystack (or nullptr). Naive implementation.

Definition at line 437 of file support.c.

Referenced by property_filter_match().

◆ fc_strcoll()

int fc_strcoll ( const char str0,
const char str1 
)

◆ fc_strerror()

const char * fc_strerror ( fc_errno  err)

Return a string which describes a given error (errno-style.) The string is converted as necessary from the local_encoding to internal_encoding, for inclusion in translations. May be subsequently converted back to local_encoding for display.

Note that this is not the reentrant form.

Definition at line 609 of file support.c.

Referenced by begin_lanserver_scan(), fc_init_network(), fc_nonblock(), fileinfolist(), find_next_free_port(), fz_strerror(), get_lanserver_announcement(), read_from_connection(), send_lanserver_response(), server_accept_connection(), server_open_socket(), server_sniff_all_input(), setup_interrupt_handlers(), and try_to_connect().

◆ fc_stricoll()

int fc_stricoll ( const char str0,
const char str1 
)

Wrapper function for stricoll().

Definition at line 485 of file support.c.

Referenced by cmp_name().

◆ fc_strlcat()

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-friendly version of strncat(), in particular easier to use safely and correctly, and ensuring nul-terminated results while being able to detect truncation.

Definition at line 822 of file support.c.

Referenced by boot_help_texts(), client_start_server(), get_city_dialog_production_full(), get_effect_req_text(), handle_page_msg_part(), handle_ruleset_description_part(), helptext_building(), helptext_goods(), helptext_government(), helptext_specialist(), historian_generic(), load_ruleset_nations(), meswin_add(), rebuild_citydlg_title_str(), req_text_insert(), req_text_insert_nl(), setting_bitwise_to_str(), tile_info_pollution(), and universal_name_translation().

◆ fc_strlcpy()

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-friendly version of strncpy(), in particular easier to use safely and correctly, and ensuring nul-terminated results while being able to detect truncation.

n is the full size of the destination buffer, including space for trailing nul, and including the pre-existing string for fc_strlcat(). Thus can eg use sizeof(buffer), or exact size malloc-ed.

Result is always nul-terminated, whether or not truncation occurs, and the return value is the strlen the destination would have had without truncation. I.e., a return value >= input n indicates truncation occurred.

Not sure about the asserts below, but they are easier than trying to ensure correct behaviour on strange inputs. In particular note that n == 0 is prohibited (e.g., since there must at least be room for a nul); could consider other options.

Definition at line 777 of file support.c.

Referenced by astr_vadd_at(), capitalized_string(), client_conn_close_callback(), client_option_font_set(), client_option_str_set(), client_start_server(), cmafec_preset_add(), compat_load_030200(), configure_single(), conn_pattern_from_string(), create_clause_menu(), desired_settable_options_update(), edit_buffer_get_status_string(), extract_sequence_text(), fc_basename(), fc_strlcat(), fc_utf8_validate_rep_len(), find_option(), fit_nationset_to_players(), get_city_dialog_production(), get_city_dialog_production_full(), get_city_dialog_production_row(), get_city_mapview_name_and_growth(), get_common_prefix(), get_full_nation(), get_full_username(), get_prod_complete_string(), get_server_address(), get_tokens(), get_unique_guest_name(), handle_chat_msg_req(), handle_ruleset_nation(), handle_ruleset_summary(), helptext_advance(), helptext_unit(), is_allowed_to_take(), load_ruleset_game(), loud_strlcpy(), main(), mapimg_def2str(), mapimg_define(), musicspec_load(), name_and_sort_items(), plrdata_slot_replace(), popup_load_game_dialog(), popup_newcity_dialog(), popup_worklist_editor(), property_page_set_store_value(), req_vec_problem_new_transl(), research_pretty_name(), ruleset_cache_sendclient_cb(), scan_score_log(), secfile_lookup_bitwise_enum_default_full(), secfile_lookup_bitwise_enum_full(), secfile_lookup_enum_data(), secfile_lookup_enum_default_data(), server_player_name_is_allowed(), server_player_set_name_full(), settable_options_load(), setting_bitwise_to_str(), setting_bitwise_validate_base(), setting_bool_to_str(), setting_enum_to_str(), setting_game_set(), setting_set_to_default(), setting_str_set(), setting_str_to_str(), settings_game_load(), sg_save_map_startpos(), team_pretty_name(), tileset_lookup_sprite_tags(), tileset_read_toplevel(), tileset_use_preferred_theme(), try_to_connect(), update_cma_preset_list(), and user_username().

◆ fc_strncasecmp()

int fc_strncasecmp ( const char str0,
const char str1,
size_t  n 
)

◆ fc_strncasequotecmp()

int fc_strncasequotecmp ( const char str0,
const char str1,
size_t  n 
)

Compare strings like strncasecmp() but ignoring surrounding quotes in either string.

Definition at line 377 of file support.c.

Referenced by conn_by_user_prefix(), and player_by_name_prefix().

◆ fc_strrep()

bool fc_strrep ( char str,
size_t  len,
const char search,
const char replace 
)

Replace 'search' by 'replace' within 'str'. sizeof(str) should be large enough for the modified value of 'str'. Returns TRUE if the replacement was successful.

Definition at line 720 of file support.c.

Referenced by fc_strrep_resize().

◆ fc_strrep_resize()

char * fc_strrep_resize ( char str,
size_t len,
const char search,
const char replace 
)

Replace 'search' by 'replace' within 'str'. If needed 'str' is resized using realloc() to fit the modified string. The new pointer to the string is returned.

Definition at line 681 of file support.c.

Referenced by html_special_chars().

◆ fc_support_free()

void fc_support_free ( void  )

Free misc resources allocated by the support module.

Definition at line 1347 of file support.c.

Referenced by libfreeciv_free().

◆ fc_support_init()

void fc_support_init ( void  )

Initialize support module.

Definition at line 1329 of file support.c.

Referenced by libfreeciv_init().

◆ fc_tolower()

char fc_tolower ( char  c)

Wrapper function to work around broken libc implementations. See above.

Definition at line 1273 of file support.c.

Referenced by cmdarg_compare(), events_init(), fc_strncasequotecmp(), and load_city_name_list().

◆ fc_toupper()

char fc_toupper ( char  c)

Wrapper function to work around broken libc implementations. See above.

Definition at line 1262 of file support.c.

Referenced by capitalized_string(), and server_player_set_name_full().

◆ fc_usleep()

void fc_usleep ( unsigned long  usec)

Suspend execution for the specified number of microseconds.

Definition at line 639 of file support.c.

Referenced by client_start_server(), move_unit_map_canvas(), put_nuke_mushroom_pixmaps(), and timer_usleep_since_start().

◆ fc_vsnprintf()

int fc_vsnprintf ( char str,
size_t  n,
const char format,
va_list  ap 
)

Definition at line 886 of file support.c.

Referenced by astr_vadd_at(), cat_snprintf(), cmdhelp_add(), con_dump(), con_write(), CONV_FUNC_STATIC(), create_event(), deprecation_pending(), fc__attribute(), fc_snprintf(), fc_utf8_vsnprintf_rep(), fc_utf8_vsnprintf_trunc(), fz_fprintf(), global_worklist_load(), global_worklist_save(), inf_log_str(), luaconsole_vprintf(), luascript_log_vargs(), mapimg_log(), output_window_vprintf(), package_event_full(), real_bodyguard_log(), real_city_log(), real_diplo_log(), real_tech_log(), real_unit_log(), req_vec_problem_new(), rgbcolor_load(), rgbcolor_save(), ruleset_error_real(), script_client_output(), script_server_cmd_reply(), secfile_entry_delete(), secfile_entry_lookup(), secfile_insert_bitwise_enum_full(), secfile_insert_bitwise_enum_vec_full(), secfile_insert_bool_full(), secfile_insert_bool_vec_full(), secfile_insert_comment(), secfile_insert_enum_data_full(), secfile_insert_enum_vec_data_full(), secfile_insert_filereference(), secfile_insert_float_full(), secfile_insert_int_full(), secfile_insert_int_vec_full(), secfile_insert_plain_enum_full(), secfile_insert_plain_enum_vec_full(), secfile_insert_str_full(), secfile_insert_str_vec_full(), secfile_log(), secfile_lookup_bitwise_enum_default_full(), secfile_lookup_bitwise_enum_full(), secfile_lookup_bitwise_enum_vec_full(), secfile_lookup_bool(), secfile_lookup_bool_default(), secfile_lookup_bool_vec(), secfile_lookup_enum_data(), secfile_lookup_enum_default_data(), secfile_lookup_enum_vec_data(), secfile_lookup_float(), secfile_lookup_float_default(), secfile_lookup_int(), secfile_lookup_int_def_min_max(), secfile_lookup_int_default(), secfile_lookup_int_default_min_max(), secfile_lookup_int_vec(), secfile_lookup_plain_enum_default_full(), secfile_lookup_plain_enum_full(), secfile_lookup_plain_enum_vec_full(), secfile_lookup_str(), secfile_lookup_str_default(), secfile_lookup_str_vec(), secfile_section_lookup(), section_entry_lookup(), tileset_error(), vcmd_reply_prefix(), vdo_log(), worklist_load(), worklist_load(), and worklist_save().

◆ icu_buffers_increase()

static void icu_buffers_increase ( void  )
static

Make string comparison buffers bigger

Definition at line 146 of file support.c.

Referenced by fc_strcasecmp(), fc_strlcpy(), and fc_strncasecmp().

◆ icu_buffers_initial()

static void icu_buffers_initial ( void  )
static

Initial allocation of string comparison buffers.

Definition at line 130 of file support.c.

Referenced by fc_strAPI_init().

◆ is_reg_file_for_access()

bool is_reg_file_for_access ( const char name,
bool  write_access 
)

Returns TRUE iff the file is a regular file or a link to a regular file or write_access is TRUE and the file doesn't exists yet.

Definition at line 1120 of file support.c.

Referenced by fz_from_file(), lua_command(), manual_start(), read_init_script_real(), and write_init_script().

◆ make_escapes()

void make_escapes ( const char str,
char buf,
size_t  buf_len 
)

Copies a string and convert the following characters:

Definition at line 294 of file support.c.

Referenced by entry_to_file().

◆ remove_escapes()

void remove_escapes ( const char str,
bool  full_escapes,
char buf,
size_t  buf_len 
)

Copies a string. Backslash followed by a genuine newline always removes the newline. If full_escapes is TRUE:

  • '
    ' -> newline translation.
  • Other '\?' sequences (any character '?') are just passed through with the '\' removed (eg, includes '\', '"'). See also make_escapes().

Definition at line 330 of file support.c.

Referenced by entry_from_token().

Variable Documentation

◆ icu_buffer1

UChar* icu_buffer1 = nullptr
static

◆ icu_buffer2

UChar* icu_buffer2 = nullptr
static

◆ icu_buffer_mutex

fc_mutex icu_buffer_mutex

Definition at line 116 of file support.c.

Referenced by fc_strAPI_free(), fc_strAPI_init(), fc_strcasecmp(), fc_strlcpy(), and fc_strncasecmp().

◆ icu_buffer_uchars

int icu_buffer_uchars = 0
static

◆ localtime_mutex

fc_mutex localtime_mutex
static

Definition at line 124 of file support.c.

Referenced by fc_localtime(), fc_support_free(), and fc_support_init().

◆ support_initialized

bool support_initialized = FALSE
static

Definition at line 111 of file support.c.

Referenced by are_support_services_available(), fc_support_free(), and fc_support_init().

◆ vsnprintf_buf

char* vsnprintf_buf = nullptr
static

Definition at line 119 of file support.c.

Referenced by fc_support_free(), and fc_vsnprintf().

◆ vsnprintf_mutex

fc_mutex vsnprintf_mutex
static

Definition at line 120 of file support.c.

Referenced by fc_support_free(), fc_support_init(), and fc_vsnprintf().