Crossfire Server, Branches 1.12
R18729
|
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <stdio.h>
#include <autoconf.h>
#include <stdarg.h>
#include "global.h"
Go to the source code of this file.
Macros | |
#define | DIGIT(x) |
#define | MAXPATHLEN 4096 |
#define | MAXTMPRETRY 10 |
#define | MBASE ('z'-'a'+1+10) |
Functions | |
void | close_and_delete (FILE *fp, int compressed) |
int | isqrt (int n) |
void | make_path_to_file (const char *filename) |
FILE * | open_and_uncompress (const char *name, int flag, int *compressed) |
static FILE * | open_and_uncompress_file (const char *ext, const char *uncompressor, const char *name, int flag, int *compressed) |
void | remove_directory (const char *path) |
int | snprintf (char *dest, int max, const char *format,...) |
int | strcasecmp (const char *s1, const char *s2) |
const char * | strcasestr_local (const char *s, const char *find) |
char * | strdup_local (const char *str) |
char * | strerror_local (int errnum, char *buf, size_t size) |
int | strncasecmp (const char *s1, const char *s2, int n) |
long | strtol (register char *str, char **ptr, register int base) |
char * | tempnam_local (const char *dir, const char *pfx) |
FILE * | tempnam_secure (const char *dir, const char *pfx, char **filename) |
Variables | |
static unsigned int | curtmp = 0 |
const char * | uncomp [NROF_COMPRESS_METHODS][3] |
This file contains various functions that are not really unique for crossfire, but rather provides what should be standard functions for systems that do not have them. In this way, most of the nasty system dependent stuff is contained here, with the program calling these functions.
Definition in file porting.c.
#define DIGIT | ( | x | ) |
#define MAXPATHLEN 4096 |
Referenced by tempnam_local().
#define MAXTMPRETRY 10 |
Referenced by tempnam_secure().
void close_and_delete | ( | FILE * | fp, |
int | compressed | ||
) |
Closes specified file.
fp | file to close. |
compressed | whether the file was compressed or not. Set by open_and_uncompress(). |
Definition at line 748 of file porting.c.
References pclose.
Referenced by add_score(), check_login(), display_high_score(), display_motd(), forbid_play(), init_artifacts(), init_attackmess(), init_book_archive(), init_experience(), init_formulae(), init_msgfile(), init_regions(), init_startup(), load_archetypes(), load_original_map(), load_overlay_map(), load_settings(), load_temporary_map(), load_treasures(), load_unique_objects(), metaserver2_init(), read_client_images(), send_news(), send_rules(), and verify_player().
int isqrt | ( | int | n | ) |
Computes the square root. Based on (n+1)^2 = n^2 + 2n + 1 given that 1^2 = 1, then 2^2 = 1 + (2 + 1) = 1 + 3 = 4 3^2 = 4 + (4 + 1) = 4 + 5 = 1 + 3 + 5 = 9 4^2 = 9 + (6 + 1) = 9 + 7 = 1 + 3 + 5 + 7 = 16 ... In other words, a square number can be express as the sum of the series n^2 = 1 + 3 + ... + (2n-1)
n | number of which to compute the root. |
Definition at line 573 of file porting.c.
Referenced by expand_lighted_sight(), find_ingred_cost(), fix_flesh_item(), get_rangevector(), get_rangevector_from_mapcoord(), play_sound_map(), roguelike_place_room(), spell_failure(), stand_in_light(), and value_limit().
void make_path_to_file | ( | const char * | filename | ) |
Checks if any directories in the given path doesn't exist, and creates if necessary.
filename | file path we'll want to access. Can be NULL. |
Definition at line 764 of file porting.c.
References llevDebug, llevError, LOG(), MAX_BUF, mkdir, S_ISDIR, SAVE_DIR_MODE, and strerror_local().
Referenced by create_destination(), key_change_class(), process_map(), save_map(), save_player(), and write_map_page().
FILE* open_and_uncompress | ( | const char * | name, |
int | flag, | ||
int * | compressed | ||
) |
open_and_uncompress() first searches for the original filename. If it exist, then it opens it and returns the file-pointer.
If not, it does two things depending on the flag. If the flag is set, it tries to create the original file by appending a compression suffix to name and uncompressing it. If the flag is not set, it creates a pipe that is used for reading the file (NOTE - you can not use fseek on pipes).
The compressed pointer is set to nonzero if the file is compressed (and thus, fp is actually a pipe.) It returns 0 if it is a normal file.
name | the base file name without compression extension | |
flag | only used for compressed files:
| |
[out] | compressed | set to zero if the file was uncompressed |
Definition at line 724 of file porting.c.
References NROF_COMPRESS_METHODS, and open_and_uncompress_file().
Referenced by add_score(), check_login(), display_high_score(), display_motd(), forbid_play(), init_artifacts(), init_attackmess(), init_book_archive(), init_experience(), init_formulae(), init_msgfile(), init_regions(), init_startup(), load_archetypes(), load_original_map(), load_overlay_map(), load_settings(), load_temporary_map(), load_treasures(), load_unique_objects(), metaserver2_init(), read_client_images(), send_news(), send_rules(), and verify_player().
|
static |
Open and possibly uncompress a file.
ext | the extension if the file is compressed. | |
uncompressor | the command to uncompress the file if the file is compressed. | |
name | the base file name without compression extension | |
flag | only used for compressed files:
| |
[out] | compressed | set to zero if the file was uncompressed |
Definition at line 621 of file porting.c.
References llevError, LOG(), MAX_BUF, popen, S_ISREG, snprintf(), unlink, WEXITSTATUS, and WIFEXITED.
Referenced by open_and_uncompress().
void remove_directory | ( | const char * | path | ) |
This function removes everything in the directory, and the directory itself.
Errors are LOG() to error level.
path | directory to remove. |
Definition at line 192 of file porting.c.
References closedir(), dirent::d_name, llevError, LOG(), MAX_BUF, opendir(), readdir(), remove_directory(), S_ISDIR, snprintf(), and unlink.
Referenced by delete_character(), and remove_directory().
int snprintf | ( | char * | dest, |
int | max, | ||
const char * | format, | ||
... | |||
) |
Formats to a string, in a size-safe way.
dest | where to write. |
max | max length of dest. |
format | format specifier, and arguments. |
Definition at line 498 of file porting.c.
Referenced by add_author(), add_exit_to_item(), add_region_link(), add_required_parameter(), add_score(), adjust_sign_msg(), animate_weapon(), apply_anim_suffix(), apply_builder_floor(), apply_builder_wall(), apply_changes_to_player(), artifact_msg(), attempt_steal(), calc_alch_danger(), can_pay(), cast_consecrate(), cast_create_town_portal(), cfapi_map_set_map_property(), cfapi_object_get_property(), cfpython_globalEventListener(), cfpython_runPluginCommand(), change_book(), check_login(), check_path(), check_pick(), check_race_restrictions(), checkbanned(), checkdm(), clean_path(), command_banish(), command_bowmode(), command_cointoss(), command_help(), command_loadtest(), command_me(), command_party(), command_players(), command_rename_item(), command_reset(), command_title(), command_use(), communicate(), content_recipe_value(), convert_newline(), copy_message(), create_items_path(), create_overlay_pathname(), create_pathname(), create_singularity(), create_template_pathname(), dead_player(), deep_swamp_type_process(), delete_character(), describe_item(), describe_monster(), describe_resistance(), describe_shop(), display_high_score(), display_motd(), display_who_entry(), do_map_index(), do_parameters(), do_region_kills(), do_server(), do_talk_npc(), do_tell(), do_tiled_map_picture(), dragon_ability_gain(), dragon_eat_flesh(), draw_one_high_score(), dump_alchemy(), dump_alchemy_costs(), dump_gods(), dump_unused_maps(), enter_fixed_template_map(), enter_random_map(), enter_random_template_map(), enter_unique_map(), esrv_draw_look(), eventListener(), examine(), find_ingred_cost(), find_maps(), find_style(), fix_flesh_item(), fix_tiled_map(), flush_output_element(), food_type_apply(), forbid_play(), form_party(), format_time(), get_exit_seed(), get_levelnumber(), get_split_ob(), get_who_escape_code_value(), getPluginProperty(), give_artifact_abilities(), god_enchants_weapon(), god_examines_item(), god_info_msg(), gravestone_text(), help_topics(), i18n_init(), infect_object(), init_anim(), init_artifacts(), init_attackmess(), init_book_archive(), init_clocks(), init_dynamic(), init_emergency_mappath(), init_experience(), init_formulae(), init_msgfile(), init_races(), init_regions(), init_startup(), initPlugins(), is_defined_recipe(), key_change_class(), key_confirm_quit(), keyplace(), kill_object(), kill_player(), load_archetypes(), load_dir(), load_map_header(), load_materials(), load_original_map(), load_settings(), load_temporary_map(), load_treasures(), load_unique_objects(), lock_and_hide_doors(), magic_wall(), main(), make_formula_book(), make_map_floor(), make_map_walls(), map_remove_unique_files(), metaserver2_init(), metaserver2_updates(), metaserver_update(), mon_desc(), mon_info_msg(), move_symptom(), msgfile_msg(), npc_say(), nstrtok(), open_and_uncompress_file(), path_combine(), perceive_self(), pick_up_object(), place_chest(), place_exits(), place_monsters(), place_treasure(), player_lvl_adj(), poison_type_apply(), postInitPlugin(), pray(), print_los(), print_shop_string(), process_map(), put_decor(), put_doors(), put_score(), query_base_name(), query_short_name(), query_weight(), rangetostring(), read_bmap_names(), read_client_images(), read_face_data(), read_map_log(), read_smooth(), receive_party_password(), remove_directory(), replace(), reply_cmd(), resurrect_player(), ring_desc(), save_map(), save_player(), send_news(), send_rules(), set_dragon_name(), set_title(), show_matching_spells(), show_skills(), spellpath_msg(), ss_dump_statistics(), ss_dump_table(), START_TEST(), store_spell_expiry(), store_time(), strerror_local(), strtoktolin(), summon_golem(), tailor_god_spell(), tempnam_local(), tiled_map_need_pic(), unclean_path(), verify_player(), write_attribute_file(), write_book_archive(), write_equipment_index(), write_map_log(), write_map_page(), write_map_parameters_to_string(), write_maps_by_level(), write_note(), write_npc_list(), write_parameters_to_string(), write_quests_page(), write_race_index(), write_region_index(), write_regions_link(), write_rune(), write_slaying_info(), write_todclock(), write_type_file(), write_type_index(), write_world_info(), and write_world_map().
int strcasecmp | ( | const char * | s1, |
const char * | s2 | ||
) |
Case-insensitive comparaison of strings.
This seems to be lacking on some system.
s1 | |
s2 | strings to compare. |
Definition at line 434 of file porting.c.
References tolower.
Referenced by cast_create_missile(), command_kill_pets(), compare_map_info(), dump_monster_treasure(), find_ingred_cost(), find_treasure_by_name(), get_god_for_race(), get_region_from_string(), item_matched_string(), load_settings(), metaserver2_init(), name_cmp(), shop_sort(), sort_archetypes(), sort_equipment(), sort_mapname(), sort_race(), sort_slaying(), sort_struct_map_in_quest(), and sortbyname().
const char* strcasestr_local | ( | const char * | s, |
const char * | find | ||
) |
Finds a substring in a string, in a case-insensitive manner.
s | string we're searching into. |
find | string we're searching for. |
Definition at line 461 of file porting.c.
References strncasecmp(), and tolower.
Referenced by display_high_score(), write_mark(), and write_note().
char* strdup_local | ( | const char * | str | ) |
A replacement of strdup(), since it's not defined at some unix variants.
str | string to duplicate. |
Definition at line 310 of file porting.c.
Referenced by add_shop_item(), build_stringlist(), cast_spell(), cfapi_system_strdup_local(), check_login(), draw_ext_info(), fire_bow(), form_party(), generate_random_map(), init_attackmess(), init_connection(), init_emergency_mappath(), load_dir(), load_map_header(), load_settings(), metaserver2_init(), parse_regions(), parse_shop_string(), push(), read_bmap_names(), read_client_images(), and read_map_log().
char* strerror_local | ( | int | errnum, |
char * | buf, | ||
size_t | size | ||
) |
This takes an err number and returns a string with a description of the error.
errnum | error we want the description of. |
buf | buffer to contain the description. |
size | buf's length. |
Definition at line 525 of file porting.c.
References snprintf().
Referenced by add_score(), command_help(), compile_info(), dead_player(), display_high_score(), do_server(), i18n_init(), init_anim(), init_races(), init_server(), load_original_map(), load_temporary_map(), make_path_to_file(), read_bmap_names(), read_face_data(), read_smooth(), save_map(), SockList_ReadPacket(), write_socket_buffer(), and Write_To_Socket().
int strncasecmp | ( | const char * | s1, |
const char * | s2, | ||
int | n | ||
) |
Case-insensitive comparaison of strings.
This seems to be lacking on some system.
s1 | |
s2 | strings to compare. |
n | maximum number of chars to compare. |
Definition at line 402 of file porting.c.
References tolower.
Referenced by basic_emote(), examine(), find_player_partial_name(), find_skill_by_name(), init_experience(), item_matched_string(), learn_skill(), strcasestr_local(), and use_skill().
long strtol | ( | register char * | str, |
char ** | ptr, | ||
register int | base | ||
) |
Converts a string to long.
A replacement of strtol() since it's not defined at many unix systems.
str | string to convert. |
ptr | will point to first invalid character in str. |
base | base to consider to convert to long. |
Definition at line 339 of file porting.c.
Referenced by check_login(), find_multi_free_spot_within_radius(), and generate_monster().
char* tempnam_local | ( | const char * | dir, |
const char * | pfx | ||
) |
A replacement for the tempnam() function since it's not defined at some unix variants. Do not use this function for new code, use tempnam_secure() instead.
dir | directory where to create the file. Can be NULL, in which case NULL is returned. |
pfx | prefix to create unique name. Can be NULL. |
Definition at line 87 of file porting.c.
References curtmp, F_OK, getpid, MAXPATHLEN, and snprintf().
Referenced by save_map(), and tempnam_secure().
FILE* tempnam_secure | ( | const char * | dir, |
const char * | pfx, | ||
char ** | filename | ||
) |
A replacement for the tempnam_local() function since that one is not very secure. This one will open the file in an atomic way on platforms where it is possible.
dir | Directory where to create the file. Can be NULL, in which case NULL is returned. |
pfx | Prefix to create unique name. Can be NULL. |
filename | This should be a pointer to a char*, the function will overwrite the char* with the name of the resulting file. Must be freed by caller. Value is unchanged if the function returns NULL. |
Definition at line 143 of file porting.c.
References llevError, LOG(), MAXTMPRETRY, S_IRUSR, S_IWUSR, and tempnam_local().
Referenced by save_player().
|
static |
Used to generate temporary unique name.
Definition at line 69 of file porting.c.
Referenced by tempnam_local().
const char* uncomp[NROF_COMPRESS_METHODS][3] |
This is a list of the suffix, uncompress and compress functions. Thus, if you have some other compress program you want to use, the only thing that needs to be done is to extended this. The first entry must be NULL - this is what is used for non compressed files.
Definition at line 593 of file porting.c.
Referenced by check_path(), and save_map().