Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
COMMONS: macros, headers, defines, timers, allocators,...

Macros

#define __n_assert(__ptr, __ret)
 macro to assert things
#define _nstr(__PTR)
 N_STR or "NULL" string for logging purposes.
#define _nstrp(__PTR)
 N_STR or NULL pointer for testing purposes.
#define _str(__PTR)
 define true
#define _strp(__PTR)
 String or NULL pointer for testing purposes.
#define _strw(__PTR)
 String or " " string for config purposes.
#define Alloca(__ptr, __size)
 Malloca Handler to get errors and set to 0.
#define BYTEORDER_BIG_ENDIAN   1
 Big endian macro value.
#define BYTEORDER_LITTLE_ENDIAN   0
 Little endian macro value.
#define CALL_RETRY(__retvar, __expression, __max_tries)
 TEMP_FAILURE gnu macro portable version.
#define checkerror()
 check for errors
#define CONCAT(a, b)
 Concatenate two macro.
#define CONCAT_BUILDER(a, b)
 CONCAT macro helper.
#define DEFAULT   1000
 Default APP_STATUS Value.
#define endif
 close a ifwhatever block
#define equal_if(__a, __cond, __b)
 if( a , condition, b ) then a = b
#define FALL_THROUGH
 set windows if true
#define FORCE_INLINE   static inline __attribute__((always_inline))
 FORCE_INLINE portable macro.
#define Free(__ptr)
 Free Handler to get errors.
#define FreeNoLog(__ptr)
 Free Handler without log.
#define GET   4321
 Flag for GET something , passing as a function parameter.
#define get_error()
 pop up errors if any
#define iffalse   if( FALSE ==
 error checker type if( toto == FALSE )
#define ifnull   if( !
 error checker type if( !toto )
#define iftrue   if( TRUE ==
 error checker type if( toto == FALSE )
#define ifzero   if( 0 ==
 error checker type if( 0 != toto )
#define init_error_check()
 init error checking in a function
#define init_lock(__rwlock_mutex)
 Macro for initializing a rwlock.
#define Malloc(__ptr, __struct, __size)
 Malloc Handler to get errors and set to 0.
#define N_DAEMON_NO_CHDIR   64
 daemonize flag: do not call chdir("/")
#define N_DAEMON_NO_CLOSE   2
 daemonize flag: no descriptor close at all
#define N_DAEMON_NO_DOUBLE_FORK   8
 daemonize flag: do not double fork
#define N_DAEMON_NO_SETSID   16
 daemonize flag: do not call setsid
#define N_DAEMON_NO_SIGCHLD_HANDLER   256
 daemonize flag: do not use internal zombie SIGCHLD handler
#define N_DAEMON_NO_SIGCHLD_IGN   128
 daemonize flag: do not ignore SIGCHLD
#define N_DAEMON_NO_STD_REDIRECT   4
 daemonize flag: just do not redirect stdin/out/err to /dev/null
#define N_DAEMON_NO_UMASK   32
 daemonize flag: do not call umask( 0 )
#define next_even(__val)
 next even helper
#define next_odd(__val)
 next odd helper
#define PAUSED   1004
 Value of the state of an application who is paused.
#define randomize()
 Initialize the random sequence with time.
#define read_lock(__rwlock_mutex)
 Macro for acquiring a read lock on a rwlock mutex.
#define Realloc(__ptr, __struct, __size)
 Realloc Handler to get errors.
#define Reallocz(__ptr, __struct, __old_size, __size)
 Realloc + zero new memory zone Handler to get errors.
#define RUNNING   1001
 Value of the state of an application who is running.
#define rw_lock_destroy(__rwlock_mutex)
 Macro to destroy rwlock mutex.
#define RWLOCK_LOGLEVEL   LOG_NULL
 flag to tell the API to disable DEBUG log on locks
#define SET   1234
 Flag for SET something , passing as a function parameter.
#define STOPPED   1003
 Value of the state of an application who is stopped.
#define STOPWANTED   1002
 Value of the state of an application who want to stop his activity.
#define unlock(__rwlock_mutex)
 Macro for releasing read/write lock a rwlock mutex.
#define write_lock(__rwlock_mutex)
 Macro for acquiring a write lock on a rwlock mutex.

Functions

int file_exist (const char *filename)
 test file presence
int get_computer_name (char *computer_name, size_t len)
 get the computer name into the given buffer
char * get_prog_dir (void)
 get running program directory
char * get_prog_name (void)
 get running program name
void log_environment (int loglevel)
 log environment variables at the given log level
void n_abort (char const *format,...)
 htonl for 64 bits numbers
int n_daemonize (void)
 daemonize the current process
int n_daemonize_ex (int mode)
 daemonize the current process with the given mode flags
char * n_get_file_extension (char path[])
 get the file extension from a path
void N_HIDE_STR (char *buf,...)
 reconstruct hidden string from variadic char arguments
int n_open_with_default (const char *path)
 Open a file or a URL with whatever the desktop opens it with.
int n_popen (char *cmd, size_t read_buf_size, void **nstr_output, int *ret)
 shortcut for popen usage
int n_spawn_detached (const char *program, const char *const *args)
 Start a program and do not wait for it.
int n_spawn_pipe_close (N_SPAWN_PIPE **pipe, int stop, int *exit_code)
 End a program's input, or end the program, and wait for it.
N_SPAWN_PIPE * n_spawn_pipe_open (const char *program, const char *const *args, const char *log_path)
 Start a program whose standard input is fed by the caller.
int n_spawn_pipe_write (N_SPAWN_PIPE *pipe, const void *data, size_t len)
 Write to a program's standard input, all of it.
int n_spawn_wait (const char *program, const char *const *args, int *exit_code)
 Run a program with arguments and wait for it to finish.
int n_spawn_wait_cancel (const char *program, const char *const *args, int *exit_code, const volatile int *cancel)
 Run a program and wait for it, ending it early when asked.
void sigchld_handler (int sig)
 reap zombie processes
int sigchld_handler_installer (void)
 install signal SIGCHLD handler
pid_t system_nb (const char *command, int *infp, int *outfp)
 non-blocking system call

Detailed Description

Macro Definition Documentation

◆ __n_assert

#define __n_assert ( __ptr,
__ret )
Value:
if (!(__ptr)) { \
n_log(LOG_DEBUG, "if( !(%s) ) assert at line %d of %s", #__ptr, __LINE__, __FILE__); \
__ret; \
}
#define LOG_DEBUG
debug-level messages
Definition n_log.h:108

macro to assert things

Examples
ex_accept_pool_client.c, ex_accept_pool_server.c, ex_common.c, ex_file.c, ex_fluid_config.c, ex_kafka.c, ex_list.c, ex_network.h, ex_network_ssl.c, ex_network_ssl_hardened.c, ex_threads.c, ex_trees.c, and ex_zlib.c.

Definition at line 279 of file n_common.h.

Referenced by __stack_pop(), __stack_push(), _destroy_ht(), _destroy_ht_trie(), _empty_ht(), _empty_ht_trie(), _find_window_node(), _form_decode_dup(), _free_nstr(), _ht_check_trie_divergence(), _ht_depth_first_search(), _ht_find_longest_prefix_trie(), _ht_get_double(), _ht_get_double_trie(), _ht_get_int(), _ht_get_int_trie(), _ht_get_node(), _ht_get_node_trie(), _ht_get_ptr(), _ht_get_ptr_trie(), _ht_get_string(), _ht_get_string_trie(), _ht_is_leaf_node_trie(), _ht_new_double_node(), _ht_new_int_node(), _ht_new_node(), _ht_new_node_trie(), _ht_new_ptr_node(), _ht_new_string_node(), _ht_new_string_ptr_node(), _ht_node_destroy(), _ht_print(), _ht_print_trie(), _ht_put_double(), _ht_put_double_trie(), _ht_put_int(), _ht_put_int_trie(), _ht_put_ptr(), _ht_put_ptr_trie(), _ht_put_string(), _ht_put_string_ptr(), _ht_put_string_ptr_trie(), _ht_put_string_trie(), _ht_remove(), _ht_remove_trie(), _ht_search(), _ht_search_trie(), _n_nodup_log(), _netw_crypto_setup_failed(), _netw_ssl_server_defaults(), _new_widget(), _register_widget(), _sse_read_byte(), _sse_write(), _ws_read(), _ws_write(), add_bmp_to_lib(), add_bytes_to_msg(), add_emitter(), add_int_to_msg(), add_nb_to_msg(), add_nstrdup_to_msg(), add_nstrptr_to_msg(), add_particle(), add_particle_at(), add_strdup_to_msg(), avro_decode_bytes_raw(), avro_decode_container(), avro_decode_datum(), avro_decode_long(), avro_encode_container(), avro_encode_datum(), avro_encode_long(), avro_file_to_json(), avro_json_to_file(), avro_nstr_avro_to_json(), avro_nstr_json_to_avro(), avro_schema_from_cjson(), avro_schema_parse(), avro_schema_parse_nstr(), avro_schema_to_json(), char_to_nstr(), char_to_nstr_ex(), char_to_nstr_nocopy(), check_n_log_dup(), check_n_log_dup_indexed(), client_worker_echo(), client_worker_fast(), close_nodup_log(), CompressData(), create_anim_library(), create_msg(), delete_bmp_from_lib(), delete_msg(), delete_stack(), destroy_anim_lib(), destroy_config_file(), destroy_ht(), destroy_n_fluid(), destroy_threaded_pool(), dispatch_to_pool(), dr_entity_check_threshold(), dr_entity_compute(), dr_entity_create(), dr_entity_destroy(), dr_entity_receive_state(), dr_entity_set_algo(), dr_entity_set_blend_mode(), dr_entity_set_blend_time(), dr_entity_set_position(), dr_entity_set_threshold(), draw_particle(), dump_nodup_log(), empty_ht(), empty_msg(), empty_nodup_table(), empty_nstr(), file_to_nstr(), free_emitters(), free_particle_system(), free_quadtree(), get_bytes_from_msg(), get_config_section_value(), get_int_from_msg(), get_keyboard(), get_msec(), get_nb_config_file_sections(), get_nb_config_file_sections_entries(), get_nb_from_msg(), get_net_datas(), get_nodup_indexed_key(), get_nodup_key(), get_nstr_from_msg(), get_sec(), get_str_from_msg(), get_usec(), handle_client(), handle_inline_and_count(), handle_request(), ht_duplicate(), ht_get_completion_list(), ht_get_double(), ht_get_int(), ht_get_node(), ht_get_node_ex(), ht_get_optimal_size(), ht_get_ptr(), ht_get_ptr_ex(), ht_get_string(), ht_get_table_collision_percentage(), ht_node_type(), ht_optimize(), ht_print(), ht_put_double(), ht_put_int(), ht_put_ptr(), ht_put_ptr_ex(), ht_put_string(), ht_put_string_ptr(), ht_remove(), ht_remove_ex(), ht_resize(), ht_search(), init_particle_system(), insert(), iso_corner_to_screen(), iso_generate_transition_masks(), iso_generate_transition_tiles(), iso_map_build_draw_order(), iso_map_calc_transitions(), iso_map_calc_transitions_full(), iso_map_corner_heights(), iso_map_draw(), iso_map_free(), iso_map_get_ability(), iso_map_get_height(), iso_map_get_terrain(), iso_map_interpolate_height(), iso_map_lerp_projection(), iso_map_load(), iso_map_new(), iso_map_randomize(), iso_map_save(), iso_map_set_ability(), iso_map_set_height(), iso_map_set_projection(), iso_map_set_projection_custom(), iso_map_set_projection_target(), iso_map_set_segments(), iso_map_set_terrain(), iso_map_should_transition(), iso_map_should_transition_smooth(), iso_map_smooth_corner_heights(), iso_map_to_screen(), iso_map_to_screen_f(), iso_mask_tile_to_diamond(), iso_screen_to_map(), iso_screen_to_map_height(), iso_screen_to_map_height_f(), join(), list_destroy(), list_empty(), list_empty_with_f(), list_node_pop(), list_node_push(), list_node_shift(), list_node_unshift(), list_pop_f(), list_push(), list_push_sorted(), list_search(), list_search_with_f(), list_shift_f(), list_unshift(), list_unshift_sorted(), load_app_state(), load_config_file(), main(), main(), main(), make_msg_from_str(), make_str_from_msg(), manage_particle(), manage_particle_ex(), move_particles(), n_atlas_destroy(), n_atlas_draw_cell(), n_atlas_page_ready(), n_atlas_set_page(), n_base64_decode(), n_base64_decode_len(), n_base64_encode(), n_base64_encode_len(), n_clock_sync_delete(), n_clock_sync_mark_sent(), n_clock_sync_new(), n_clock_sync_process_response(), n_clock_sync_seed(), n_clock_sync_server_time(), n_clock_sync_should_send(), n_diff_to_unified(), n_disk_cache_expire(), n_disk_cache_get(), n_disk_cache_open(), n_disk_cache_path(), n_disk_cache_prune(), n_disk_cache_prune_group(), n_disk_cache_put(), n_disk_cache_remove(), n_disk_cache_size(), n_file_copy_verified(), n_file_read_bounded(), n_file_same_content(), n_file_write_atomic(), n_fluid_advectSmoke(), n_fluid_advectVel(), n_fluid_avgU(), n_fluid_avgV(), n_fluid_draw(), n_fluid_extrapolate(), n_fluid_integrate(), n_fluid_resetObstacles(), n_fluid_sampleField(), n_fluid_setObstacle(), n_fluid_setObstacleFromBitmap(), n_fluid_simulate(), n_fluid_simulate_threaded(), n_fluid_solveIncompressibility(), n_free_file_info(), n_get_file_extension(), n_git_ahead_behind(), n_git_checkout_commit(), n_git_checkout_path(), n_git_close(), n_git_commit(), n_git_create_branch(), n_git_current_branch(), n_git_delete_branch(), n_git_diff_commits(), n_git_diff_workdir(), n_git_fetch(), n_git_init_ex(), n_git_list_branches(), n_git_log(), n_git_open(), n_git_pull(), n_git_push(), n_git_remote_set_url(), n_git_set_remote_auth(), n_git_stage(), n_git_stage_all(), n_git_status(), n_git_switch_branch(), n_git_unstage(), n_gui_add_button(), n_gui_add_checkbox(), n_gui_add_combobox(), n_gui_add_custom(), n_gui_add_datagrid(), n_gui_add_dropmenu(), n_gui_add_hexview(), n_gui_add_image(), n_gui_add_label(), n_gui_add_listbox(), n_gui_add_markdownview(), n_gui_add_progressbar(), n_gui_add_radiolist(), n_gui_add_scrollbar(), n_gui_add_slider(), n_gui_add_splitpane(), n_gui_add_syntaxview(), n_gui_add_textarea(), n_gui_add_window(), n_gui_apply_adaptive_resize(), n_gui_button_get_label(), n_gui_checkbox_get_label(), n_gui_checkbox_set_label(), n_gui_close_menus(), n_gui_color_picker_get(), n_gui_color_picker_new(), n_gui_color_picker_open(), n_gui_colorwheel_new(), n_gui_combobox_set_flags(), n_gui_count_detached(), n_gui_curve_new(), n_gui_custom_set_destroy(), n_gui_custom_set_mouse(), n_gui_destroy_ctx(), n_gui_detect_dpi_scale(), n_gui_double_clicked_widget(), n_gui_draw(), n_gui_draw_detached(), n_gui_dropmenu_set_open(), n_gui_focus_takes_key(), n_gui_focus_window(), n_gui_get_dpi_scale(), n_gui_get_event_queue(), n_gui_get_focus(), n_gui_get_resize_mode(), n_gui_get_topmost_open_window(), n_gui_get_widget(), n_gui_grid_index_at(), n_gui_grid_new(), n_gui_hovered_widget(), n_gui_label_fits(), n_gui_label_get_text(), n_gui_load_layout_json(), n_gui_load_theme_json(), n_gui_lower_window(), n_gui_maximize_window(), n_gui_menu_is_open(), n_gui_new_ctx(), n_gui_popup_new(), n_gui_process_event(), n_gui_raise_window(), n_gui_save_layout_json(), n_gui_save_theme_json(), n_gui_screen_to_virtual(), n_gui_set_cursor(), n_gui_set_default_font(), n_gui_set_display(), n_gui_set_display_size(), n_gui_set_double_click_radius(), n_gui_set_double_click_time(), n_gui_set_dpi_scale(), n_gui_set_event_queue(), n_gui_set_focus(), n_gui_set_resize_mode(), n_gui_set_shape_mode(), n_gui_set_virtual_size(), n_gui_splitpane_band(), n_gui_update_transform(), n_gui_wants_mouse(), n_gui_was_double_click(), n_gui_widget_is_visible(), n_gui_widget_screen_rect(), n_gui_widget_set_rect(), n_gui_window_apply_autofit(), n_gui_window_attach(), n_gui_window_button_rect(), n_gui_window_detach(), n_gui_window_find_button(), n_gui_window_from_display(), n_gui_window_get_display(), n_gui_window_get_resize_policy(), n_gui_window_get_zorder(), n_gui_window_get_zvalue(), n_gui_window_is_detached(), n_gui_window_is_maximised(), n_gui_window_native_is_hidden(), n_gui_window_set_autofit(), n_gui_window_set_caption(), n_gui_window_set_close_callback(), n_gui_window_set_content_draw_callback(), n_gui_window_set_maximize_callback(), n_gui_window_set_minimize_callback(), n_gui_window_set_native_icons(), n_gui_window_set_rect_axes(), n_gui_window_set_resize_policy(), n_gui_window_set_tb_btn_theme(), n_gui_window_set_tb_button_bitmaps(), n_gui_window_set_tb_close_theme(), n_gui_window_set_wheel_scrollbar(), n_gui_window_set_zorder(), n_gui_window_update_normalized(), n_hex_decode(), n_hex_decode_to(), n_hex_encode(), n_hex_encode_to(), n_html_escape(), n_http2_server_goaway(), n_http2_server_handshake(), n_http2_server_new(), n_http2_server_respond(), n_http2_server_rst_stream(), n_http2_server_run(), n_http_form_multipart_parse(), n_http_form_parse(), n_http_percent_decode(), n_http_response_new(), n_http_response_write(), n_http_server_config_defaults(), n_http_server_new(), n_http_server_read_body(), n_http_server_read_body_to_fd(), n_http_server_run(), n_http_server_stats(), n_http_set_cookie_build(), n_icc_from_buffer(), n_icc_from_file(), n_iso_camera_center_on(), n_iso_camera_follow(), n_iso_camera_free(), n_iso_camera_new(), n_iso_camera_screen_to_world(), n_iso_camera_scroll(), n_iso_camera_world_to_screen(), n_iso_camera_zoom(), n_kafka_add_header(), n_kafka_add_header_ex(), n_kafka_delete(), n_kafka_delivery_message_callback(), n_kafka_disable_event_consumption(), n_kafka_disable_event_production(), n_kafka_dump_unprocessed(), n_kafka_enable_event_consumption(), n_kafka_enable_event_production(), n_kafka_event_destroy(), n_kafka_event_destroy_ptr(), n_kafka_get_event(), n_kafka_get_schema_from_char(), n_kafka_get_schema_from_nstr(), n_kafka_get_status(), n_kafka_load_config(), n_kafka_load_unprocessed(), n_kafka_mkdir_p(), n_kafka_move_file_to_sended(), n_kafka_new(), n_kafka_new_event(), n_kafka_new_event_from_char(), n_kafka_new_event_from_file(), n_kafka_new_event_from_string(), n_kafka_new_headers(), n_kafka_poll(), n_kafka_produce(), n_kafka_put_schema_in_char(), n_kafka_put_schema_in_nstr(), n_kafka_set_error_timeout(), n_kafka_set_sended_dir(), n_kafka_start_polling_thread(), n_kafka_stop_polling_thread(), n_mock_server_free(), n_mock_server_run(), n_mock_server_start(), n_mock_server_stop(), n_module_open(), n_module_symbol(), n_open_with_default(), n_popen(), n_pretty_js(), n_pretty_json(), n_pretty_json_lenient(), n_pretty_xml(), n_random_hex_token(), n_router_add(), n_router_check(), n_scan_dir(), n_spawn_detached(), n_spawn_pipe_open(), n_spawn_pipe_write(), n_spawn_wait_cancel(), n_sse_conn_free(), n_sse_connect(), n_sse_stop(), n_tiff_find(), n_tiff_get_ascii(), n_tiff_get_doubles(), n_tiff_parse(), n_tiff_parse_ifd(), n_vigenere_cypher(), n_vigenere_cypher_thread(), n_vigenere_decode_file(), n_vigenere_decode_file_qa(), n_vigenere_decode_qa(), n_vigenere_encode_file(), n_vigenere_encode_file_qa(), n_vigenere_encode_qa(), n_vigenere_get_answer(), n_ws_close(), n_ws_conn_free(), n_ws_connect(), n_ws_recv(), n_ws_send(), n_x509_generate_ca(), n_x509_keypair_pem(), n_x509_mint_host_cert(), netmsg_make_ident(), netmsg_make_ping(), netmsg_make_position_msg(), netmsg_make_quit_msg(), netmsg_make_string_msg(), netw_accept_from_ex(), netw_accept_pool_create(), netw_accept_pool_destroy(), netw_accept_pool_get_stats(), netw_accept_pool_start(), netw_accept_pool_stop(), netw_accept_pool_thread_func(), netw_accept_pool_wait(), netw_accept_ssl_with_sni_cb(), netw_add_msg(), netw_add_msg_ex(), netw_adopt_client_fd(), netw_bind_udp(), netw_build_http_response(), netw_calculate_urlencoded_size(), netw_close(), netw_connect_check(), netw_connect_ex_to(), netw_connect_nonblock(), netw_connect_udp(), netw_destroy_pool(), netw_extract_http_info(), netw_extract_http_request_type(), netw_get_http_date(), netw_get_ident(), netw_get_msg(), netw_get_ping(), netw_get_position(), netw_get_queue_status(), netw_get_quit(), netw_get_string(), netw_get_url_from_http_request(), netw_guess_http_content_type(), netw_make_listening(), netw_msg_get_type(), netw_new(), netw_new_pool(), netw_parse_post_data(), netw_pool_add(), netw_pool_broadcast(), netw_pool_nbclients(), netw_pool_netw_close(), netw_pool_remove(), netw_recv_func(), netw_send_func(), netw_send_ident(), netw_send_ping(), netw_send_position(), netw_send_quit(), netw_send_string_to(), netw_send_string_to_all(), netw_set(), netw_set_blocking(), netw_set_compression_mode(), netw_set_crypto(), netw_set_crypto_chain(), netw_set_crypto_chain_pem(), netw_set_crypto_pem(), netw_set_crypto_pem_ctx(), netw_set_user_id(), netw_setsockopt(), netw_ssl_connect_client_to(), netw_ssl_do_handshake(), netw_ssl_get_alpn(), netw_ssl_get_sni(), netw_ssl_get_verify_result(), netw_ssl_handshake_once(), netw_ssl_server_ctx_new(), netw_ssl_server_handshake_ex(), netw_ssl_server_handshake_once(), netw_ssl_set_alpn(), netw_ssl_set_ca(), netw_ssl_set_ciphers(), netw_ssl_set_client_cert(), netw_ssl_set_verify(), netw_ssl_set_versions(), netw_ssl_start_client(), netw_start_thr_engine(), netw_stop_thr_engine(), netw_udp_recvfrom(), netw_udp_sendto(), netw_urldecode(), netw_urlencode(), netw_wait_msg(), new_generic_list(), new_ht(), new_ht_trie(), new_list_node(), new_n_atlas(), new_n_fluid(), new_nstr(), new_stack(), new_tree(), nfgets(), npcre_clean_match(), npcre_delete(), npcre_match(), npcre_match_capture(), npcre_new(), npcre_replace(), nstr_to_fd(), nstr_to_file(), nstrcat_bytes_ex(), nstrcat_ex(), nstrdup(), nstrprintf_cat_ex(), nstrprintf_ex(), occupy_thread(), on_accept_pooled(), open_sysjrnl(), print_list_info(), recv_data(), recv_data_once(), recv_ssl_data(), recv_ssl_data_once(), recv_udp_data(), refresh_thread_pool(), remove_emitter(), remove_list_node_f(), resize_nstr(), send_data(), send_data_once(), send_net_datas(), send_ssl_data(), send_ssl_data_once(), send_udp_data(), set_log_file(), set_log_file_fd(), set_thread_pool_discard(), skipu(), skipw(), split(), split_count(), ssl_harden_context(), ssl_network_thread(), stack_peek(), stack_pop_b(), stack_pop_c(), stack_pop_d(), stack_pop_f(), stack_pop_i32(), stack_pop_i8(), stack_pop_p(), stack_pop_ui32(), stack_pop_ui8(), start_HiTimer(), str_sanitize_ex(), str_to_int_ex(), str_to_int_nolog(), str_to_long_ex(), str_to_long_long_ex(), strcpy_u(), strlo(), strup(), system_nb(), trajectory_add_point(), trajectory_clear_points(), trajectory_compute(), trajectory_delete(), trajectory_distance(), trajectory_get_acceleration(), trajectory_get_orientation(), trajectory_get_position(), trajectory_get_speed(), trajectory_new(), trajectory_set_end(), trajectory_set_start(), trajectory_update(), tree_insert_child(), trim(), trim_nocopy(), UncompressData(), unzip4_nstr(), unzip_nstr(), update_anim(), update_physics_position(), update_physics_position_nb(), update_physics_position_reverse(), update_physics_position_reverse_nb(), userlist_add_msg_to_ex(), userlist_add_user(), userlist_del_user(), userlist_destroy(), userlist_new(), userlist_send_waiting_msgs(), userlist_set_position_behavior(), userlist_user_add_waiting_msg(), userlist_user_send_waiting_msgs(), wait_for_synced_threaded_pool(), wait_for_threaded_pool(), worker_handle_client(), write_config_file(), zip4_nstr(), and zip_nstr().

◆ _nstr

◆ _nstrp

#define _nstrp ( __PTR)
Value:
((__PTR && __PTR->data) ? (__PTR->data) : NULL)

N_STR or NULL pointer for testing purposes.

Examples
ex_common.c, and ex_file.c.

Definition at line 201 of file n_common.h.

Referenced by main(), and n_kafka_load_config().

◆ _str

◆ _strp

#define _strp ( __PTR)
Value:
((__PTR) ? (__PTR) : NULL)

String or NULL pointer for testing purposes.

Definition at line 195 of file n_common.h.

◆ _strw

#define _strw ( __PTR)
Value:
((__PTR) ? (__PTR) : " ")

String or " " string for config purposes.

Definition at line 197 of file n_common.h.

◆ Alloca

#define Alloca ( __ptr,
__size )
Value:
{ \
int __n_errno = 0; \
errno = 0; \
__ptr = alloca(__size); \
__n_errno = errno; \
if (!__ptr) { \
n_log(LOG_ERR, "%s=alloca( %zu ) %s at line %d of %s", #__ptr, (size_t)(__size), (__n_errno == 0) ? "alloca error" : strerror(__n_errno), __LINE__, __FILE__); \
} else { \
memset(__ptr, 0, __size); \
} \
}
#define LOG_ERR
error conditions
Definition n_log.h:100

Malloca Handler to get errors and set to 0.

Examples
ex_common.c, ex_file.c, and ex_network_ssl.c.

Definition at line 216 of file n_common.h.

Referenced by handle_request(), and main().

◆ BYTEORDER_BIG_ENDIAN

#define BYTEORDER_BIG_ENDIAN   1

Big endian macro value.

Definition at line 101 of file n_common.h.

◆ BYTEORDER_LITTLE_ENDIAN

#define BYTEORDER_LITTLE_ENDIAN   0

Little endian macro value.

Definition at line 99 of file n_common.h.

◆ CALL_RETRY

#define CALL_RETRY ( __retvar,
__expression,
__max_tries )
Value:
do { \
int __nb_retries = 0; \
do { \
__retvar = (__expression); \
__nb_retries++; \
} while (__retvar == -1 && errno == EINTR && __nb_retries < (__max_tries)); \
} while (0)

TEMP_FAILURE gnu macro portable version.

Definition at line 286 of file n_common.h.

◆ checkerror

#define checkerror ( )
Value:
if (___error__check_flag == TRUE) { \
n_log(LOG_ERR, "checkerror return false at line %d of %s", __LINE__, __FILE__); \
goto error; \
}

check for errors

Examples
ex_common.c, and ex_file.c.

Definition at line 318 of file n_common.h.

Referenced by main().

◆ CONCAT

#define CONCAT ( a,
b )
Value:
#define CONCAT_BUILDER(a, b)
CONCAT macro helper.
Definition n_common.h:454

Concatenate two macro.

Definition at line 456 of file n_common.h.

◆ CONCAT_BUILDER

#define CONCAT_BUILDER ( a,
b )
Value:
a##b

CONCAT macro helper.

Definition at line 454 of file n_common.h.

◆ DEFAULT

#define DEFAULT   1000

Default APP_STATUS Value.

Definition at line 427 of file n_common.h.

◆ endif

#define endif
Value:
){ \
___error__check_flag = TRUE; \
n_log(LOG_ERR, "First err was at line %d of %s", __LINE__, __FILE__); \
}

close a ifwhatever block

Examples
ex_common.c, and ex_file.c.

Definition at line 325 of file n_common.h.

Referenced by main(), n_http_server_run(), netw_accept_from_ex(), netw_close(), recv_data(), recv_data_once(), recv_ssl_data(), recv_ssl_data_once(), send_data(), send_data_once(), send_ssl_data(), send_ssl_data_once(), and send_udp_data().

◆ equal_if

#define equal_if ( __a,
__cond,
__b )
Value:
if ((__a)__cond(__b)) { \
__a = __b; \
}

if( a , condition, b ) then a = b

Definition at line 335 of file n_common.h.

◆ FALL_THROUGH

#define FALL_THROUGH
Value:
/* fall through */ \
((void)0)

set windows if true

fall through macro for switch cases, avoid warning at compilation

Examples
ex_kafka.c.

Definition at line 72 of file n_common.h.

Referenced by main(), MurmurHash3_x64_128(), MurmurHash3_x86_128(), and MurmurHash3_x86_32().

◆ FORCE_INLINE

#define FORCE_INLINE   static inline __attribute__((always_inline))

FORCE_INLINE portable macro.

Examples
ex_common.c, and ex_file.c.

Definition at line 164 of file n_common.h.

Referenced by fmix32(), fmix64(), getblock32(), getblock64(), and inlined_func().

◆ Free

#define Free ( __ptr)
Value:
if (__ptr) { \
free(__ptr); \
__ptr = NULL; \
} else { \
n_log(LOG_DEBUG, "Free( %s ) already done or NULL at line %d of %s", #__ptr, __LINE__, __FILE__); \
}

Free Handler to get errors.

Examples
ex_accept_pool_server.c, ex_common.c, ex_file.c, ex_fluid.c, ex_gui_network.c, ex_gui_syntaxview.c, ex_hash.c, ex_hex.c, ex_list.c, ex_network_ssl.c, ex_network_ssl_hardened.c, ex_nstr.c, ex_trees.c, and ex_zlib.c.

Definition at line 263 of file n_common.h.

Referenced by _a4_wrap(), _destroy_ht(), _destroy_ht_trie(), _form_decode_dup(), _ht_new_node(), _ht_new_node_trie(), _ht_node_destroy(), _ht_put_string(), _ht_put_string_ptr(), _ht_put_string_trie(), _ht_remove_trie(), _n_form_field_free(), _n_html_attr_free(), _n_html_form_free(), _n_html_parse_tag(), _n_html_tag_free(), _n_nodup_log(), _n_nodup_log_indexed(), _ngui_publish_primary_selection(), _out_finish(), _serve(), _sort_windows_by_zorder(), _worker(), add_bmp_to_lib(), add_emitter(), add_int_to_msg(), add_nb_to_msg(), allegro_exit(), avro_decode_container(), avro_decode_datum(), avro_encode_container(), avro_encode_datum(), avro_schema_from_cjson(), avro_schema_to_json(), char_to_nstr_ex(), check_n_log_dup(), check_n_log_dup_indexed(), close_safe_logging(), create_anim_library(), create_msg(), create_quadtree(), delete_msg(), delete_stack(), destroy_anim_lib(), destroy_bitmap(), destroy_config_file(), destroy_config_file_section(), destroy_data(), destroy_font(), destroy_game_env(), destroy_midi(), destroy_sample(), destroy_threaded_pool(), dr_entity_destroy(), dump_nodup_log(), free_emitters(), free_particle_system(), free_split_result(), get_bytes_from_msg(), get_int_from_msg(), get_nb_from_msg(), get_nodup_indexed_key(), get_nodup_key(), get_str_from_msg(), handle_request(), ht_get_completion_list(), iso_map_free(), iso_map_new(), lexMenuDestroy(), list_destroy(), list_empty(), list_empty_with_f(), list_pop_f(), list_shift_f(), load_config_file(), main(), main(), main(), make_msg_from_str(), make_str_from_msg(), manage_particle_ex(), mp_part_free(), n_atlas_destroy(), n_clock_sync_delete(), n_cookiejar_free(), n_cookiejar_new(), n_disk_cache_close(), n_disk_cache_open(), n_file_copy_verified(), n_file_read_bounded(), n_file_streams_equal(), n_file_write_atomic(), n_get_current_dir_hd_serial(), n_gui_add_button(), n_gui_add_checkbox(), n_gui_add_combobox(), n_gui_add_custom(), n_gui_add_datagrid(), n_gui_add_dropmenu(), n_gui_add_hexview(), n_gui_add_image(), n_gui_add_label(), n_gui_add_listbox(), n_gui_add_markdownview(), n_gui_add_progressbar(), n_gui_add_radiolist(), n_gui_add_scrollbar(), n_gui_add_slider(), n_gui_add_splitpane(), n_gui_add_syntaxview(), n_gui_add_textarea(), n_gui_add_window(), n_gui_color_picker_free(), n_gui_color_picker_new(), n_gui_destroy_ctx(), n_gui_new_ctx(), n_gui_process_event(), n_html_to_text(), n_http_form_multipart_parse(), n_http_form_parse(), n_http_percent_decode(), n_http_response_write(), n_iso_camera_free(), n_kafka_delete(), n_kafka_new(), n_module_close(), n_pretty_js(), n_pretty_json_lenient(), n_pretty_xml(), n_random_hex_token(), n_router_add(), n_sitemap_extract_urls(), n_spawn_pipe_close(), n_spawn_pipe_open(), n_tiff_free(), n_tiff_parse_ifd(), n_vigenere_cypher(), n_vigenere_cypher_thread(), netw_accept_pool_create(), netw_accept_pool_destroy(), netw_close(), netw_destroy_pool(), netw_new(), netw_new_pool(), netw_send_func(), netw_urldecode(), new_ht(), new_ht_trie(), new_n_atlas(), new_nstr(), new_stack(), new_thread_pool(), nstrdup(), open_safe_logging(), poll_network_msgs(), pop_exception(), recv_php(), refresh_thread_pool(), remove_emitter(), remove_list_node_f(), resize_nstr(), ssl_network_thread(), str_to_int_ex(), str_to_int_nolog(), str_to_long_ex(), str_to_long_long_ex(), test_atomic_file(), test_decode_errors(), test_decode_roundtrip(), trajectory_delete(), tree_create_node(), tree_insert_child(), userlist_destroy(), userlist_new(), and worker_handle_client().

◆ FreeNoLog

#define FreeNoLog ( __ptr)
Value:
if (__ptr) { \
free(__ptr); \
__ptr = NULL; \
}

Free Handler without log.

Examples
ex_accept_pool_client.c, ex_accept_pool_server.c, ex_clock_sync.c, ex_common.c, ex_file.c, ex_gui_bench.c, ex_gui_dictionary.c, ex_gui_network.c, ex_network.c, ex_network_reactor.c, ex_network_ssl.c, ex_network_ssl_hardened.c, and ex_url.c.

Definition at line 272 of file n_common.h.

Referenced by _destroy_widget(), _destroy_window(), _dropmenu_entries_grow(), _emit(), _free_nstr(), _ht_node_destroy(), _ht_put_double_trie(), _ht_put_int_trie(), _ht_put_ptr_trie(), _ht_put_string_ptr_trie(), _ht_put_string_trie(), _items_grow(), _line_free(), _myers(), _n_form_field_free(), _n_git_commit_info_destroy(), _n_git_diff_print_cb(), _n_git_status_entry_destroy(), _n_git_string_destroy(), _n_gui_kv_content_free(), _n_html_attr_free(), _n_html_form_free(), _n_html_parse_tag(), _n_html_tag_free(), _n_log(), _out_finish(), _popup_append(), _popup_layout(), _text_free(), _text_load(), _textarea_copy_to_clipboard(), avro_schema_free(), build_syntaxview_window(), close_sysjrnl(), delete_bmp_from_lib(), destroy_anim_lib(), destroy_n_fluid(), free_entry(), free_entry_def(), free_nstr_nolog(), free_nstr_ptr(), free_nstr_ptr_nolog(), free_particle_system(), get_bytes_from_msg(), main(), main(), mp_part_free(), n_cookie_free(), n_diff_result_free(), n_diff_to_unified(), n_git_close(), n_git_init_ex(), n_git_open(), n_git_set_remote_auth(), n_gui_datagrid_add_column(), n_gui_datagrid_add_row(), n_gui_datagrid_clear_rows(), n_gui_datagrid_sort(), n_gui_destroy_ctx(), n_gui_hexview_set_data(), n_gui_kvtable_free(), n_gui_kvtable_set_placeholders(), n_gui_load_layout_json(), n_gui_load_theme_json(), n_gui_markdownview_set_text(), n_gui_popup_free(), n_gui_popup_set_title(), n_gui_sectionlist_free(), n_gui_set_widget_tooltip(), n_gui_syntaxview_set_text(), n_gui_tab_free(), n_gui_textarea_set_placeholder(), n_gui_textarea_set_suggest(), n_gui_tree_create(), n_gui_tree_free(), n_gui_tree_state_free(), n_http_form_free(), n_http_form_multipart_free(), n_http_form_parse(), n_http_response_add_header(), n_http_response_free(), n_http_response_remove_header(), n_http_response_set_header(), n_http_server_free(), n_kafka_delete(), n_kafka_event_destroy_ptr(), n_kafka_polling_thread(), n_kafka_set_sended_dir(), n_mock_server_free(), n_mock_server_start(), n_proxy_cfg_free(), n_proxy_cfg_parse(), n_router_add(), n_router_free(), n_sse_conn_free(), n_tiff_free(), n_url_free(), n_ws_conn_free(), n_ws_send(), netw_accept_from_ex(), netw_bind_udp(), netw_close(), netw_connect_check(), netw_connect_ex_to(), netw_connect_udp(), netw_info_destroy(), netw_make_listening(), netw_set_blocking(), netw_set_crypto(), netw_setsockopt(), netw_udp_recvfrom(), netw_udp_sendto(), new_n_fluid(), npcre_delete(), npcre_replace(), recv_data(), recv_data_once(), recv_php(), recv_ssl_data(), recv_ssl_data_once(), recv_udp_data(), send_data(), send_data_once(), send_php(), send_ssl_data(), send_ssl_data_once(), send_udp_data(), and write_config_file().

◆ GET

#define GET   4321

Flag for GET something , passing as a function parameter.

Definition at line 425 of file n_common.h.

◆ get_error

#define get_error ( )
Value:
(___error__check_flag == TRUE)

pop up errors if any

Examples
ex_common.c, and ex_file.c.

Definition at line 331 of file n_common.h.

Referenced by main().

◆ iffalse

#define iffalse   if( FALSE ==

error checker type if( toto == FALSE )

Examples
ex_common.c, and ex_file.c.

Definition at line 312 of file n_common.h.

Referenced by main().

◆ ifnull

#define ifnull   if( !

error checker type if( !toto )

Examples
ex_common.c, and ex_file.c.

Definition at line 306 of file n_common.h.

Referenced by main().

◆ iftrue

#define iftrue   if( TRUE ==

error checker type if( toto == FALSE )

Examples
ex_common.c, and ex_file.c.

Definition at line 315 of file n_common.h.

Referenced by main().

◆ ifzero

#define ifzero   if( 0 ==

error checker type if( 0 != toto )

Examples
ex_common.c, and ex_file.c.

Definition at line 309 of file n_common.h.

Referenced by main().

◆ init_error_check

#define init_error_check ( )
Value:
static int ___error__check_flag = FALSE;

init error checking in a function

Examples
ex_common.c, and ex_file.c.

Definition at line 302 of file n_common.h.

Referenced by main().

◆ init_lock

#define init_lock ( __rwlock_mutex)
Value:
({ \
pthread_rwlockattr_t __attr; \
pthread_rwlockattr_init(&__attr); \
int __ret = 0; \
do { \
n_log(RWLOCK_LOGLEVEL, "init_lock %s", #__rwlock_mutex); \
__rwlock_mutex = (pthread_rwlock_t)PTHREAD_RWLOCK_INITIALIZER; \
__ret = pthread_rwlock_init(&(__rwlock_mutex), &__attr); \
if (__ret != 0) { \
n_log(LOG_ERR, "Error %s while initializing %s at %s:%s:%d", strerror(__ret), #__rwlock_mutex, __FILE__, __func__, __LINE__); \
} \
pthread_rwlockattr_destroy(&__attr); \
} while (0); \
__ret; \
})
#define RWLOCK_LOGLEVEL
flag to tell the API to disable DEBUG log on locks
Definition n_common.h:346

Macro for initializing a rwlock.

Definition at line 350 of file n_common.h.

Referenced by n_cookiejar_new(), n_kafka_new(), netw_new_pool(), npcre_new(), and userlist_new().

◆ Malloc

#define Malloc ( __ptr,
__struct,
__size )
Value:
{ \
int __n_errno = 0; \
errno = 0; \
__ptr = (__struct*)calloc(__size, sizeof(__struct)); \
__n_errno = errno; \
if (!__ptr) { \
n_log(LOG_ERR, "( %s *)calloc( %zu , sizeof( %s ) ) %s at line %d of %s", #__ptr, (size_t)(__size), #__struct, (__n_errno == 0) ? "malloc error" : strerror(__n_errno), __LINE__, __FILE__); \
} \
}

Malloc Handler to get errors and set to 0.

Examples
ex_accept_pool_server.c, ex_common.c, ex_file.c, ex_fluid.c, ex_gui_bench.c, ex_gui_dictionary.c, ex_hash.c, ex_kafka.c, ex_network_ssl.c, ex_network_ssl_hardened.c, and ex_zlib.c.

Definition at line 204 of file n_common.h.

Referenced by _a4_wrap(), _datagrid_ensure_colors(), _datagrid_ensure_sel(), _dropmenu_entries_grow(), _emit(), _form_decode_dup(), _ht_find_longest_prefix_trie(), _ht_new_node(), _ht_new_node_trie(), _items_grow(), _myers(), _n_git_diff_print_cb(), _n_html_parse_tag(), _n_html_strdup_upper(), _n_html_strndup(), _n_html_strndup_lower(), _n_log(), _new_widget(), _ngui_publish_primary_selection(), _serve(), _sort_windows_by_zorder(), _suggest_refresh(), _text_load(), _textarea_copy_to_clipboard(), _worker(), add_bmp_to_lib(), add_emitter(), add_int_to_msg(), add_nb_to_msg(), add_particle(), add_particle_at(), add_threaded_process(), allegro_init(), avro_decode_bytes_raw(), avro_decode_datum(), avro_encode_datum(), avro_schema_from_cjson(), build_syntaxview_window(), create_anim_library(), create_msg(), dispatch_to_pool(), dr_entity_create(), handle_request(), ht_put_ptr_ex(), init_game_env(), init_particle_system(), iso_map_new(), iso_map_set_segments(), join(), lexLoadMenuFromFile(), load_config_file(), load_midi(), load_sample(), load_ttf_font(), main(), main(), main(), make_msg_from_str(), make_str_from_msg(), mp_strndup(), n_clock_sync_new(), n_cookiejar_add_from_header(), n_cookiejar_new(), n_diff_lines(), n_diff_to_unified(), n_disk_cache_open(), n_file_copy_verified(), n_file_read_bounded(), n_file_streams_equal(), n_file_write_atomic(), n_git_init_ex(), n_git_log(), n_git_open(), n_git_set_remote_auth(), n_git_status(), n_gui_add_button(), n_gui_add_checkbox(), n_gui_add_combobox(), n_gui_add_custom(), n_gui_add_datagrid(), n_gui_add_dropmenu(), n_gui_add_hexview(), n_gui_add_image(), n_gui_add_label(), n_gui_add_listbox(), n_gui_add_markdownview(), n_gui_add_progressbar(), n_gui_add_radiolist(), n_gui_add_scrollbar(), n_gui_add_slider(), n_gui_add_splitpane(), n_gui_add_syntaxview(), n_gui_add_textarea(), n_gui_add_window(), n_gui_color_picker_new(), n_gui_datagrid_add_column(), n_gui_datagrid_add_row(), n_gui_datagrid_sort(), n_gui_hexview_set_data(), n_gui_kvtable_create(), n_gui_load_layout_json(), n_gui_load_theme_json(), n_gui_new_ctx(), n_gui_sectionlist_create(), n_gui_syntaxview_get_selected_text(), n_gui_syntaxview_set_text(), n_gui_tab_create(), n_gui_tree_create(), n_hex_decode(), n_html_extract_forms(), n_html_to_text(), n_http_build_multipart(), n_http_form_multipart_parse(), n_http_form_parse(), n_http_parse_multipart(), n_http_response_add_header(), n_http_response_new(), n_http_response_write(), n_http_server_new(), n_iso_camera_new(), n_kafka_dump_unprocessed(), n_kafka_new(), n_kafka_new_event(), n_kafka_new_event_from_char(), n_mock_server_start(), n_module_open(), n_proxy_cfg_parse(), n_random_hex_token(), n_router_add(), n_router_new(), n_scan_dir(), n_spawn_pipe_open(), n_sse_connect(), n_tiff_parse_ifd(), n_url_parse(), n_vigenere_cypher(), n_ws_connect(), n_ws_send(), netw_accept_from_ex(), netw_accept_pool_create(), netw_add_msg_ex(), netw_bind_udp(), netw_connect_ex_to(), netw_connect_nonblock(), netw_connect_udp(), netw_make_listening(), netw_new(), netw_new_pool(), netw_recv_func(), netw_send_func(), new_generic_list(), new_ht(), new_ht_trie(), new_list_node(), new_n_atlas(), new_n_fluid(), new_nstr(), new_stack(), new_thread_pool(), new_tree(), npcre_new(), npcre_replace(), open_safe_logging(), recv_php(), resize_nstr(), split(), str_replace(), str_to_int_ex(), str_to_int_nolog(), str_to_long_ex(), str_to_long_long_ex(), trajectory_new(), userlist_new(), and vasprintf().

◆ N_DAEMON_NO_CHDIR

#define N_DAEMON_NO_CHDIR   64

daemonize flag: do not call chdir("/")

Definition at line 668 of file n_common.h.

Referenced by n_daemonize_ex().

◆ N_DAEMON_NO_CLOSE

#define N_DAEMON_NO_CLOSE   2

daemonize flag: no descriptor close at all

Definition at line 658 of file n_common.h.

Referenced by n_daemonize_ex().

◆ N_DAEMON_NO_DOUBLE_FORK

#define N_DAEMON_NO_DOUBLE_FORK   8

daemonize flag: do not double fork

Definition at line 662 of file n_common.h.

Referenced by n_daemonize_ex().

◆ N_DAEMON_NO_SETSID

#define N_DAEMON_NO_SETSID   16

daemonize flag: do not call setsid

Definition at line 664 of file n_common.h.

Referenced by n_daemonize_ex().

◆ N_DAEMON_NO_SIGCHLD_HANDLER

#define N_DAEMON_NO_SIGCHLD_HANDLER   256

daemonize flag: do not use internal zombie SIGCHLD handler

Definition at line 672 of file n_common.h.

Referenced by n_daemonize(), and n_daemonize_ex().

◆ N_DAEMON_NO_SIGCHLD_IGN

#define N_DAEMON_NO_SIGCHLD_IGN   128

daemonize flag: do not ignore SIGCHLD

Definition at line 670 of file n_common.h.

Referenced by n_daemonize(), and n_daemonize_ex().

◆ N_DAEMON_NO_STD_REDIRECT

#define N_DAEMON_NO_STD_REDIRECT   4

daemonize flag: just do not redirect stdin/out/err to /dev/null

Definition at line 660 of file n_common.h.

Referenced by n_daemonize_ex().

◆ N_DAEMON_NO_UMASK

#define N_DAEMON_NO_UMASK   32

daemonize flag: do not call umask( 0 )

Definition at line 666 of file n_common.h.

Referenced by n_daemonize_ex().

◆ next_even

#define next_even ( __val)
Value:
(((__val) % 2 == 0) ? (__val) : ((__val) + 1))

next even helper

Examples
ex_common.c, and ex_file.c.

Definition at line 299 of file n_common.h.

Referenced by main().

◆ next_odd

#define next_odd ( __val)
Value:
(((__val) % 2 == 0) ? ((__val) + 1) : (__val))

next odd helper

Examples
ex_common.c, and ex_file.c.

Definition at line 296 of file n_common.h.

Referenced by main().

◆ PAUSED

#define PAUSED   1004

Value of the state of an application who is paused.

Definition at line 435 of file n_common.h.

◆ randomize

#define randomize ( )
Value:
{ \
srand((unsigned)time(NULL)); \
rand(); \
}

Initialize the random sequence with time.

Definition at line 438 of file n_common.h.

◆ read_lock

#define read_lock ( __rwlock_mutex)
Value:
({ \
int __ret = 0; \
do { \
n_log(RWLOCK_LOGLEVEL, "read lock %s", #__rwlock_mutex); \
__ret = pthread_rwlock_rdlock(&(__rwlock_mutex)); \
if (__ret != 0) { \
n_log(LOG_ERR, "Error %s while read locking %s at %s:%s:%d", strerror(__ret), #__rwlock_mutex, __FILE__, __func__, __LINE__); \
} \
} while (0); \
__ret; \
})

Macro for acquiring a read lock on a rwlock mutex.

Definition at line 368 of file n_common.h.

Referenced by n_cookiejar_build_header(), n_cookiejar_count(), n_kafka_dump_unprocessed(), n_kafka_get_status(), n_kafka_poll(), n_kafka_polling_thread(), n_kafka_start_polling_thread(), n_kafka_stop_polling_thread(), netw_pool_broadcast(), netw_pool_nbclients(), userlist_add_msg_to_ex(), and userlist_set_position_behavior().

◆ Realloc

#define Realloc ( __ptr,
__struct,
__size )
Value:
({ \
int __n_errno = 0; \
errno = 0; \
void* __new_ptr = ((__size) && (sizeof(__struct)) && ((__size) > SIZE_MAX / sizeof(__struct))) ? NULL : (__struct*)realloc(__ptr, (__size) * sizeof(__struct)); \
__n_errno = errno; \
if (!__new_ptr) { \
n_log(LOG_ERR, "( %s *)realloc( %s * sizeof( %zu ) ) %s at line %d of %s", #__ptr, #__struct, (size_t)(__size), (__n_errno == 0) ? "realloc error" : strerror(__n_errno), __LINE__, __FILE__); \
} else { \
__ptr = __new_ptr; \
} \
(__new_ptr != NULL) ? TRUE : FALSE; \
})

Realloc Handler to get errors.

Returns TRUE on success, FALSE on failure. On failure the original pointer is preserved (not set to NULL).

Examples
ex_common.c, and ex_file.c.

Definition at line 231 of file n_common.h.

Referenced by _ht_find_longest_prefix_trie(), ht_resize(), main(), trajectory_add_point(), userlist_del_user(), and userlist_set_position_behavior().

◆ Reallocz

#define Reallocz ( __ptr,
__struct,
__old_size,
__size )
Value:
({ \
int __n_errno = 0; \
errno = 0; \
void* __new_ptr = ((__size) && (sizeof(__struct)) && ((__size) > SIZE_MAX / sizeof(__struct))) ? NULL : (__struct*)realloc(__ptr, __size); \
__n_errno = errno; \
if (!__new_ptr) { \
n_log(LOG_ERR, "( %s *)realloc( %s * sizeof( %zu ) ) %s at line %d of %s", #__ptr, #__struct, (size_t)(__size), (__n_errno == 0) ? "realloc error" : strerror(__n_errno), __LINE__, __FILE__); \
} else { \
__ptr = __new_ptr; \
if (__size > __old_size) memset(((char*)__ptr + __old_size), 0, __size - __old_size); \
} \
(__new_ptr != NULL) ? TRUE : FALSE; \
})

Realloc + zero new memory zone Handler to get errors.

Returns TRUE on success, FALSE on failure. On failure the original pointer is preserved (not set to NULL).

Examples
ex_common.c, and ex_file.c.

Definition at line 247 of file n_common.h.

Referenced by main(), nstrcat_ex(), resize_nstr(), and write_and_fit_ex().

◆ RUNNING

#define RUNNING   1001

Value of the state of an application who is running.

Definition at line 429 of file n_common.h.

◆ rw_lock_destroy

#define rw_lock_destroy ( __rwlock_mutex)
Value:
({ \
int __ret = 0; \
do { \
n_log(RWLOCK_LOGLEVEL, "destroy lock %s", #__rwlock_mutex); \
__ret = pthread_rwlock_destroy(&(__rwlock_mutex)); \
if (__ret != 0) { \
n_log(LOG_ERR, "Error %s while destroying %s at %s:%s:%d", strerror(__ret), #__rwlock_mutex, __FILE__, __func__, __LINE__); \
} \
} while (0); \
__ret; \
})

Macro to destroy rwlock mutex.

Definition at line 409 of file n_common.h.

Referenced by n_cookiejar_free(), n_kafka_delete(), netw_destroy_pool(), and npcre_delete().

◆ RWLOCK_LOGLEVEL

#define RWLOCK_LOGLEVEL   LOG_NULL

flag to tell the API to disable DEBUG log on locks

Definition at line 346 of file n_common.h.

◆ SET

#define SET   1234

Flag for SET something , passing as a function parameter.

Definition at line 423 of file n_common.h.

◆ STOPPED

#define STOPPED   1003

Value of the state of an application who is stopped.

Definition at line 433 of file n_common.h.

◆ STOPWANTED

#define STOPWANTED   1002

Value of the state of an application who want to stop his activity.

Definition at line 431 of file n_common.h.

◆ unlock

◆ write_lock

Function Documentation

◆ file_exist()

int file_exist ( const char * filename)

test file presence

test file presence

Parameters
filenamePath/name of the file
Returns
TRUE or FALSE

Definition at line 105 of file n_common.c.

Referenced by main(), and main().

Here is the caller graph for this function:

◆ get_computer_name()

int get_computer_name ( char * computer_name,
size_t len )

get the computer name into the given buffer

get the computer name into the given buffer

Parameters
computer_nameallocated buffer to hold the computer name
lensize of computer_name variable
Returns
TRUE or FALSE

Definition at line 75 of file n_common.c.

References LOG_ERR, and n_log.

Referenced by main(), and n_kafka_load_config().

Here is the caller graph for this function:

◆ get_prog_dir()

char * get_prog_dir ( void )

get running program directory

get running program directory

Returns
A copy of the current program running directory inside a string

Definition at line 118 of file n_common.c.

Referenced by main().

Here is the caller graph for this function:

◆ get_prog_name()

char * get_prog_name ( void )

get running program name

get running program name

Returns
A copy of the current program name inside a string

Definition at line 150 of file n_common.c.

Referenced by main().

Here is the caller graph for this function:

◆ log_environment()

void log_environment ( int loglevel)

log environment variables at the given log level

log environment variables at the given log level

Parameters
loglevelthe loglevel used to log the environment

Definition at line 821 of file n_common.c.

References n_log.

Referenced by main().

Here is the caller graph for this function:

◆ n_abort()

void n_abort ( char const * format,
... )

htonl for 64 bits numbers

ntonl for 64 bits numbers

exit and print log to stderr

htonl for 64 bits numbers

Parameters
formatprintf style format and args

Definition at line 58 of file n_common.c.

Referenced by main(), and main().

Here is the caller graph for this function:

◆ n_daemonize()

int n_daemonize ( void )

daemonize the current process

daemonize the current process

Returns
TRUE or FALSE

Definition at line 873 of file n_common.c.

References N_DAEMON_NO_SIGCHLD_HANDLER, N_DAEMON_NO_SIGCHLD_IGN, and n_daemonize_ex().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_daemonize_ex()

int n_daemonize_ex ( int mode)

daemonize the current process with the given mode flags

daemonize the current process with the given mode flags

Parameters
modeflag made of a combination of N_DAEMON_NO_CLOSE, N_DAEMON_NO_STD_REDIRECT, N_DAEMON_NO_DOUBLE_FORK , N_DAEMON_NO_SETSID, N_DAEMON_NO_UMASK, N_DAEMON_NO_CHDIR, N_DAEMON_NO_SETSID, N_DAEMON_NO_SIGCHLD_IGN, N_DAEMON_NO_SIGCHLD_HANDLER or 0 for defaults
Returns
TRUE or FALSE

Definition at line 882 of file n_common.c.

References LOG_ERR, LOG_NOTICE, mode, N_DAEMON_NO_CHDIR, N_DAEMON_NO_CLOSE, N_DAEMON_NO_DOUBLE_FORK, N_DAEMON_NO_SETSID, N_DAEMON_NO_SIGCHLD_HANDLER, N_DAEMON_NO_SIGCHLD_IGN, N_DAEMON_NO_STD_REDIRECT, N_DAEMON_NO_UMASK, n_log, and sigchld_handler_installer().

Referenced by n_daemonize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_get_file_extension()

char * n_get_file_extension ( char path[])

get the file extension from a path

get the file extension from a path

Parameters
paththe path + filename
Returns
a pointer to the first extension character or NULL

Definition at line 1069 of file n_common.c.

References __n_assert.

Referenced by main().

Here is the caller graph for this function:

◆ N_HIDE_STR()

void N_HIDE_STR ( char * buf,
... )

reconstruct hidden string from variadic char arguments

reconstruct hidden string from variadic char arguments

Parameters
bufthe variable which will receive the string. Must be large enough to hold all arguments.
Warning
No bounds checking is performed. The caller must ensure buf is large enough.

Definition at line 1048 of file n_common.c.

Referenced by main().

Here is the caller graph for this function:

◆ n_open_with_default()

int n_open_with_default ( const char * path)

Open a file or a URL with whatever the desktop opens it with.

xdg-open on Linux and the BSDs, open on macOS, ShellExecute on Windows. Detached, as n_spawn_detached().

Parameters
pathFile path or URL.
Returns
TRUE when the opener was started, FALSE otherwise.

Definition at line 792 of file n_common.c.

References __n_assert, done, LOG_ERR, n_log, and n_spawn_detached().

Here is the call graph for this function:

◆ n_popen()

int n_popen ( char * cmd,
size_t read_buf_size,
void ** nstr_output,
int * ret )

shortcut for popen usage

shortcut for popen usage

Parameters
cmdThe command to launch
read_buf_sizepopen read buf. Also serves as a minimum size for the dynamically allocated returned output if not already allocated
nstr_outputPointer to a valid N_STR or NULL (see read_buf_size)
retCommand output if any. Should be initialized to -1 and tested against to check if it's valid.
Returns
TRUE or FALSE

Definition at line 185 of file n_common.c.

References __n_assert, free_nstr, LOG_ERR, n_log, new_nstr(), and nstrprintf_cat.

Referenced by addr2line(), main(), and n_get_current_dir_hd_serial().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_spawn_detached()

int n_spawn_detached ( const char * program,
const char *const * args )

Start a program and do not wait for it.

For handing a file to another application - an image editor, a viewer - that must outlive the caller's interest in it. No shell is involved: the arguments are passed as they are, so a file name with spaces, quotes or a semicolon in it is one argument and nothing else. On POSIX the program is found on the PATH and started through a double fork in a session of its own, so it leaves no zombie and a terminal closing does not take it with it; on Windows it is CreateProcess with each argument quoted.

Parameters
programProgram to run: a name on the PATH or a path.
argsIts arguments after the program itself, NULL terminated. May be NULL for none.
Returns
TRUE when the program was started, FALSE when it could not be (on POSIX a program that is not found is reported by the child and still counts as started; the caller learns of it from the log).

Definition at line 293 of file n_common.c.

References __n_assert, line(), LOG_ERR, and n_log.

Referenced by main(), and n_open_with_default().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_spawn_pipe_close()

int n_spawn_pipe_close ( N_SPAWN_PIPE ** pipe,
int stop,
int * exit_code )

End a program's input, or end the program, and wait for it.

With stop at zero the input is closed, which is the end of the stream, and the program is waited for as long as it takes to finish with it. With stop set it is ended first - SIGTERM then SIGKILL two seconds later on POSIX, TerminateProcess on Windows - for a caller abandoning the work. Either way it is reaped, and *pipe is freed and set to NULL.

Parameters
pipeAddress of the running program. NULL or *NULL is a no-op that returns FALSE.
stopNon-zero to end the program rather than let it finish.
exit_codeReceives its exit code, 127 when it could not be found or started on POSIX, -1 when it was ended by a signal or stopped. May be NULL.
Returns
TRUE when it finished by itself with exit code 0, FALSE otherwise.

Definition at line 716 of file n_common.c.

References N_SPAWN_PIPE::child, Free, N_SPAWN_PIPE::input, LOG_ERR, LOG_NOTICE, n_log, N_SPAWN_PIPE::program, and stop().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_spawn_pipe_open()

N_SPAWN_PIPE * n_spawn_pipe_open ( const char * program,
const char *const * args,
const char * log_path )

Start a program whose standard input is fed by the caller.

For a tool that takes a stream rather than a file: an encoder fed raw frames, a compressor fed a buffer. No shell is involved, as with n_spawn_wait(). The program reads what n_spawn_pipe_write() sends and sees the end of its input at n_spawn_pipe_close(). Its standard output and error go to log_path when given, so what it said can be read after it failed, and are left as the caller's otherwise.

The write end is never inherited by another program the caller starts, which would otherwise hold the pipe open and keep this one waiting for an end of input that never comes.

Parameters
programProgram to run: a name on the PATH or a path.
argsIts arguments after the program itself, NULL terminated. May be NULL for none.
log_pathFile that receives the program's standard output and error, created or truncated. NULL leaves them as they are.
Returns
The running program, owned by the caller and released by n_spawn_pipe_close(), or NULL when it could not be started. On POSIX a program that is not found is only learnt of at the first write or at the close, as exit code 127.

Definition at line 525 of file n_common.c.

References __n_assert, N_SPAWN_PIPE::child, Free, N_SPAWN_PIPE::input, line(), LOG_ERR, Malloc, n_log, and N_SPAWN_PIPE::program.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_spawn_pipe_write()

int n_spawn_pipe_write ( N_SPAWN_PIPE * pipe,
const void * data,
size_t len )

Write to a program's standard input, all of it.

Blocks while the program is not reading, which is how a fast producer is held to a slow consumer's pace. A program that has ended, or closed its input, makes this return FALSE rather than raise SIGPIPE: the signal is held back for the calling thread during the write and discarded.

Parameters
pipeThe running program. NULL fails.
dataWhat to write. May be NULL when len is 0.
lenHow many bytes.
Returns
TRUE when every byte was written, FALSE when the program is gone or the write failed.

Definition at line 655 of file n_common.c.

References __n_assert, N_SPAWN_PIPE::input, LOG_ERR, n_log, and N_SPAWN_PIPE::program.

Referenced by main().

Here is the caller graph for this function:

◆ n_spawn_wait()

int n_spawn_wait ( const char * program,
const char *const * args,
int * exit_code )

Run a program with arguments and wait for it to finish.

The waiting counterpart of n_spawn_detached(), for a tool whose result the caller needs before going on: a converter, a compressor. No shell is involved, so every argument arrives whole whatever it contains. On POSIX the program is found on the PATH, started with fork and execvp and reaped with waitpid; on Windows it is CreateProcess with each argument quoted and a wait on its handle. The caller's thread blocks for as long as the program runs: call it from a worker, not from an interface thread.

Parameters
programProgram to run: a name on the PATH or a path.
argsIts arguments after the program itself, NULL terminated. May be NULL for none.
exit_codeReceives the program's exit code when it ran to the end, 127 when it could not be found or started on POSIX, -1 when it was ended by a signal. May be NULL.
Returns
TRUE when the program ran and exited with 0, FALSE otherwise; the reason is in exit_code and the log.

Definition at line 370 of file n_common.c.

References n_spawn_wait_cancel().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_spawn_wait_cancel()

int n_spawn_wait_cancel ( const char * program,
const char *const * args,
int * exit_code,
const volatile int * cancel )

Run a program and wait for it, ending it early when asked.

n_spawn_wait() for a program that can run for minutes, a download say, whose caller must be able to stop it. While the program runs the flag is looked at every tenth of a second; once it is non-zero the program is ended - SIGTERM, then SIGKILL two seconds later on POSIX, TerminateProcess on Windows - and reaped, and the call returns FALSE. What the program had written by then is the caller's to remove.

Parameters
programProgram to run: a name on the PATH or a path.
argsIts arguments after the program itself, NULL terminated. May be NULL for none.
exit_codeAs n_spawn_wait(); -1 when the program was stopped. May be NULL.
cancelFlag another thread raises to stop the program. Read, never written. NULL waits as n_spawn_wait() does.
Returns
TRUE when the program ran and exited with 0, FALSE when it failed or was stopped.

Definition at line 374 of file n_common.c.

References __n_assert, line(), LOG_ERR, LOG_NOTICE, and n_log.

Referenced by main(), and n_spawn_wait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigchld_handler()

void sigchld_handler ( int sig)

reap zombie processes

reap zombie processes

Parameters
sigsignal type handle

Definition at line 842 of file n_common.c.

References LOG_DEBUG, and n_log.

Referenced by sigchld_handler_installer().

Here is the caller graph for this function:

◆ sigchld_handler_installer()

int sigchld_handler_installer ( void )

install signal SIGCHLD handler

install signal SIGCHLD handler

Returns
TRUE or FALSE

Definition at line 856 of file n_common.c.

References LOG_ERR, n_log, and sigchld_handler().

Referenced by main(), and n_daemonize_ex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ system_nb()

pid_t system_nb ( const char * command,
int * infp,
int * outfp )

non-blocking system call

non-blocking system call

Parameters
commandto call
infpstdin file descriptor holder or NULL
outfpstdout file descriptor holder or NULL
Returns
The system command pid or -1

Definition at line 979 of file n_common.c.

References __n_assert, LOG_ERR, and n_log.

Referenced by main().

Here is the caller graph for this function: