Freeciv-3.1
|
#include <freeciv_config.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
Go to the source code of this file.
Macros | |
#define | TRUE true |
#define | FALSE false |
#define | bool unsigned int |
#define | true 1 |
#define | false 0 |
#define | __bool_true_false_are_defined 1 |
#define | fc__attribute(x) |
#define | fc__warn_unused_result |
#define | fc__fallthrough |
#define | RETURN_VALUE_AFTER_EXIT(_val_) |
#define | VAR_ARG_CONST const |
#define | sz_strlcpy(dest, src) ((void) fc_strlcpy((dest), (src), sizeof(dest))) |
#define | sz_strlcat(dest, src) ((void) fc_strlcat((dest), (src), sizeof(dest))) |
Typedefs | |
typedef int | fc_errno |
Functions | |
int | fc_strcasecmp (const char *str0, const char *str1) |
int | fc_strncasecmp (const char *str0, const char *str1, size_t n) |
int | fc_strncasequotecmp (const char *str0, const char *str1, size_t n) |
void | fc_support_init (void) |
void | fc_support_free (void) |
bool | are_support_services_available (void) |
size_t | effectivestrlenquote (const char *str) |
char * | fc_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) |
FILE * | fc_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 char * | fc_strerror (fc_errno err) |
void | fc_usleep (unsigned long usec) |
bool | fc_strrep (char *str, size_t len, const char *search, const char *replace) |
char * | fc_strrep_resize (char *str, size_t *len, const char *search, const char *replace) fc__warn_unused_result |
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_snprintf (char *str, size_t n, const char *format,...) fc__attribute((__format__(__printf__ |
int | fc__attribute ((nonnull(1, 3))) |
int | fc_vsnprintf (char *str, size_t n, const char *format, va_list ap) fc__attribute((nonnull(1 |
int int | cat_snprintf (char *str, size_t n, const char *format,...) fc__attribute((__format__(__printf__ |
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 char * | fc_basename (const char *path) |
struct tm * | fc_localtime (const time_t *timep, struct tm *result) |
static bool | is_bigendian (void) |
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) |
int | fc_at_quick_exit (void(*func)(void)) |
#define sz_strlcat | ( | dest, | |
src | |||
) | ((void) fc_strlcat((dest), (src), sizeof(dest))) |
#define sz_strlcpy | ( | dest, | |
src | |||
) | ((void) fc_strlcpy((dest), (src), sizeof(dest))) |
bool are_support_services_available | ( | void | ) |
Is the support module currently in usable state?
Definition at line 1378 of file support.c.
Referenced by audio_shutdown_atexit().
int int cat_snprintf | ( | char * | str, |
size_t | n, | ||
const char * | format, | ||
... | |||
) |
size_t effectivestrlenquote | ( | const char * | str | ) |
Count length of string without possible surrounding quotes.
Definition at line 359 of file support.c.
Referenced by conn_by_user_prefix(), and player_by_name_prefix().
int fc__attribute | ( | (nonnull(1, 3)) | ) |
int fc_at_quick_exit | ( | void(*)(void) | func | ) |
Set quick_exit() callback if possible.
Definition at line 1326 of file support.c.
Referenced by client_main().
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 1296 of file support.c.
Referenced by cmdhelp_new().
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 1144 of file support.c.
Referenced by astr_break_lines(), create_races_dialog(), manual_command(), option_widget_new(), show_help_command(), show_help_intro(), show_help_option(), show_nationsets(), show_ruleset_info(), and show_settings_one().
FILE * fc_fopen | ( | const char * | filename, |
const char * | opentype | ||
) |
Wrapper function for fopen() with filename conversion to local encoding on Windows.
Definition at line 506 of file support.c.
Referenced by fc_querysocket(), fz_from_file(), img_save_ppm(), log_civ_score_now(), log_real(), manual_command(), netfile_download_file(), rank_users(), read_init_script_real(), save_script_lua(), script_server_load_file(), write_chatline_content(), and write_init_script().
fc_errno fc_get_errno | ( | void | ) |
Returns last error code.
Definition at line 593 of file support.c.
Referenced by begin_lanserver_scan(), fc_init_network(), fc_nonblock(), fileinfolist(), find_next_free_port(), fz_strerror(), get_lanserver_announcement(), main(), make_dir(), read_from_connection(), send_lanserver_response(), server_accept_connection(), server_open_socket(), server_sniff_all_input(), and try_to_connect().
int fc_gethostname | ( | char * | buf, |
size_t | len | ||
) |
Call gethostname() if supported, else just returns -1.
Definition at line 1016 of file support.c.
Referenced by establish_new_connection(), and send_lanserver_response().
bool fc_isalnum | ( | char | c | ) |
Wrapper function to work around broken libc implementations. See above.
Definition at line 1205 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().
bool fc_isalpha | ( | char | c | ) |
Wrapper function to work around broken libc implementations. See above.
Definition at line 1216 of file support.c.
Referenced by extract_sequence_text(), fc_vsnprintcf(), and is_legal_table_entry_name().
bool fc_isdigit | ( | char | c | ) |
Wrapper function to work around broken libc implementations. See above.
Definition at line 1227 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().
bool fc_isprint | ( | char | c | ) |
bool fc_isspace | ( | char | c | ) |
Wrapper function to work around broken libc implementations. See above.
Definition at line 1249 of file support.c.
Referenced by check_include(), conn_pattern_from_string(), extract_sequence_text(), fc_break_lines(), find_option(), get_token_entry_name(), get_token_eol(), get_token_value(), get_token_white_char(), is_plain_public_message(), load_city_name_list(), remove_trailing_spaces(), skip_leading_spaces(), str_to_float(), str_to_int(), and str_to_uint().
bool fc_isupper | ( | char | c | ) |
Wrapper function to work around broken libc implementations. See above.
Definition at line 1260 of file support.c.
Referenced by is_good_password().
struct tm * fc_localtime | ( | const time_t * | timep, |
struct tm * | result | ||
) |
Thread safe localtime() replacement
Definition at line 1310 of file support.c.
Referenced by real_luaconsole_append(), real_output_window_append(), and send_pending_events().
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 556 of file support.c.
Referenced by handle_single_want_hack_reply(), and save_dialog_response_callback().
int fc_snprintf | ( | char * | str, |
size_t | n, | ||
const char * | format, | ||
... | |||
) |
int fc_stat | ( | const char * | filename, |
struct stat * | buf | ||
) |
Wrapper function for stat() with filename conversion to local encoding on Windows.
Definition at line 575 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().
int fc_strcasecmp | ( | const char * | str0, |
const char * | str1 | ||
) |
Compare strings like strcmp(), but ignoring case.
Definition at line 189 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_kill(), api_effects_city_bonus(), api_effects_player_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(), 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(), conn_by_user(), conn_pattern_from_string(), 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(), edit_impr::genus_menu(), get_lan_server_list(), 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_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(), lookup_req_list(), main(), mapimg_define(), message_options_load(), metaconnection_command(), 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(), 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_combat_bonus_name_3_1(), rscompat_names(), rscompat_old_effect_3_1(), rscompat_postprocess(), rscompat_req_name_3_1(), rscompat_req_type_name_3_1(), rscompat_req_vec_adjust_3_1(), save_game_ruleset(), secfile_lookup_enum_data(), server_player_name_is_allowed(), set_ai_level_named(), setting_ruleset_one(), settings_game_load(), settings_list_cmp(), sg_load_game(), 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(), unit_class_by_rule_name(), unit_type_by_rule_name(), universal_by_rule_name(), and universal_value_from_str().
char * fc_strcasestr | ( | const char * | haystack, |
const char * | needle | ||
) |
Return the needle in the haystack (or NULL). Naive implementation.
Definition at line 439 of file support.c.
Referenced by property_filter_match().
int fc_strcoll | ( | const char * | str0, |
const char * | str1 | ||
) |
Wrapper function for strcoll().
Definition at line 472 of file support.c.
Referenced by cmp_func(), compare_file_name_ptrs(), compare_fileinfo_name(), compare_strings(), compare_strings_ptrs(), compare_strings_strvec(), and sort_advance_names().
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 610 of file support.c.
Referenced by begin_lanserver_scan(), fc_init_network(), fc_nonblock(), fileinfolist(), find_next_free_port(), fz_strerror(), get_lanserver_announcement(), main(), read_from_connection(), send_lanserver_response(), server_accept_connection(), server_open_socket(), server_sniff_all_input(), and try_to_connect().
int fc_stricoll | ( | const char * | str0, |
const char * | str1 | ||
) |
Wrapper function for stricoll().
Definition at line 486 of file support.c.
Referenced by cmp_name().
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 832 of file support.c.
Referenced by boot_help_texts(), client_start_server(), 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(), load_ruleset_units(), meswin_add(), rebuild_citydlg_title_str(), req_text_insert(), req_text_insert_nl(), setting_bitwise_to_str(), tile_info_pollution(), and universal_name_translation().
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 787 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(), 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(), name_and_sort_items(), plrdata_slot_replace(), popup_load_game_dialog(), popup_newcity_dialog(), property_page_set_store_value(), req_vec_problem_new_transl(), research_pretty_name(), scan_score_log(), secfile_lookup_bitwise_enum_default_full(), secfile_lookup_bitwise_enum_full(), secfile_lookup_enum_data(), secfile_lookup_enum_default_data(), send_ruleset_choices(), 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().
int fc_strncasecmp | ( | const char * | str0, |
const char * | str1, | ||
size_t | n | ||
) |
Compare strings like strncmp(), but ignoring case. ie, only compares first n chars.
Definition at line 238 of file support.c.
Referenced by api_fcdb_option(), check_player_or_user_name(), command_named(), delegate_command(), entry_from_token(), extract_sequence_text(), fc_strcasestr(), fcdb_command(), handle_event(), is_guest_name(), log_parse_level_str(), lookup_option(), lua_command(), mapimg_command(), reset_command(), setting_match_prefix_base(), show_help(), show_list(), show_settings(), text_tag_init_from_sequence(), and vote_command().
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 379 of file support.c.
Referenced by conn_by_user_prefix(), and player_by_name_prefix().
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 731 of file support.c.
Referenced by 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 693 of file support.c.
Referenced by html_special_chars().
void fc_support_free | ( | void | ) |
Free misc resources allocated by the support module.
Definition at line 1356 of file support.c.
Referenced by libfreeciv_free().
void fc_support_init | ( | void | ) |
Initialize support module.
Definition at line 1338 of file support.c.
Referenced by libfreeciv_init().
char fc_tolower | ( | char | c | ) |
Wrapper function to work around broken libc implementations. See above.
Definition at line 1282 of file support.c.
Referenced by cmdarg_compare(), events_init(), fc_strncasequotecmp(), and load_city_name_list().
char fc_toupper | ( | char | c | ) |
Wrapper function to work around broken libc implementations. See above.
Definition at line 1271 of file support.c.
Referenced by capitalized_string(), and server_player_set_name_full().
void fc_usleep | ( | unsigned long | usec | ) |
Suspend execution for the specified number of microseconds.
Definition at line 640 of file support.c.
Referenced by client_start_server(), move_unit_map_canvas(), put_nuke_mushroom_pixmaps(), and timer_usleep_since_start().
int fc_vsnprintf | ( | char * | str, |
size_t | n, | ||
const char * | format, | ||
va_list | ap | ||
) |
|
inlinestatic |
Return whether the program is currently running on a bigendian system.
Definition at line 207 of file support.h.
Referenced by create_sprite(), create_surfaces(), get_first_pixel(), get_smaller_surface_rect(), getpixel(), load_gfxfile(), pixmap_put_overlay_tile_draw(), sprite_get_bounding_box(), and surface_get_pixbuf().
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 1129 of file support.c.
Referenced by fz_from_file(), lua_command(), manual_command(), read_init_script_real(), and write_init_script().
void make_escapes | ( | const char * | str, |
char * | buf, | ||
size_t | buf_len | ||
) |
Copies a string and convert the following characters:
Definition at line 297 of file support.c.
Referenced by entry_to_file().
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:
Definition at line 333 of file support.c.
Referenced by entry_from_token().