Tor 0.4.9.1-alpha-dev
Functions
printf.c File Reference

Compatibility wrappers around snprintf and its friends. More...

#include "lib/cc/torint.h"
#include "lib/string/printf.h"
#include "lib/err/torerr.h"
#include "lib/malloc/malloc.h"
#include <stdlib.h>
#include <stdio.h>

Go to the source code of this file.

Functions

int tor_snprintf (char *str, size_t size, const char *format,...)
 
int tor_vsnprintf (char *str, size_t size, const char *format, va_list args)
 
int tor_asprintf (char **strp, const char *fmt,...)
 
int tor_vasprintf (char **strp, const char *fmt, va_list args)
 

Detailed Description

Compatibility wrappers around snprintf and its friends.

Definition in file printf.c.

Function Documentation

◆ tor_asprintf()

int tor_asprintf ( char **  strp,
const char *  fmt,
  ... 
)

Portable asprintf implementation. Does a printf() into a newly malloc'd string. Sets *strp to this string, and returns its length (not including the terminating NUL character).

You can treat this function as if its implementation were something like

  char buf[_INFINITY_];
  tor_snprintf(buf, sizeof(buf), fmt, args);
  *strp = tor_strdup(buf);
  return strlen(*strp):

Where INFINITY is an imaginary constant so big that any string can fit into it.

Definition at line 75 of file printf.c.

Referenced by bridge_resolve_conflicts(), bytes_to_usage(), clear_trackexithost_mappings(), client_dns_set_addressmap_impl(), clock_skew_warning(), config_load_geoip_file_(), congestion_control_get_control_port_fields(), control_event_address_mapped(), disk_state_put_commit_line(), disk_state_put_srv_line(), encode_onion_key(), esc_router_info(), format_client_stats_heartbeat(), get_client_auth_creds_filename(), get_first_listener_addrport_string(), get_pt_proxy_uri(), get_srv_element_from_commit(), get_transport_bindaddr(), get_vote_line_from_commit(), getinfo_helper_geoip(), hs_lookup_last_hid_serv_request(), hs_path_from_filename(), kvline_check_keyword_args(), learned_router_identity(), networkstatus_check_required_protocols(), parse_http_url(), reachability_warnings_callback(), rep_hist_get_padding_count_lines(), secs_to_uptime(), srv_to_control_string(), srv_to_ns_string(), storage_dir_clean_tmpfiles(), storage_dir_get_usage(), storage_dir_map(), storage_dir_read(), storage_dir_remove_file(), storage_dir_save_chunks_to_file(), tor_listdir(), tor_sockaddr_to_str(), validate_ports_csv(), and write_address_to_file().

◆ tor_snprintf()

int tor_snprintf ( char *  str,
size_t  size,
const char *  format,
  ... 
)

Replacement for snprintf. Differs from platform snprintf in two ways: First, always NUL-terminates its output. Second, always returns -1 if the result is truncated. (Note that this return behavior does not conform to C99; it just happens to be easier to emulate "return -1" with conformant implementations than it is to emulate "return number that would be written" with non-conformant implementations.)

Definition at line 27 of file printf.c.

Referenced by bwhist_fill_bandwidth_history(), connection_describe(), connection_or_get_state_description(), copy_ipv6_address(), describe_portnum(), domain_to_string(), entry_guard_describe(), fmt_addrport(), format_iso_time_nospace_usec(), format_time_interval(), get_default_conf_file(), get_platform_str(), hs_service_upload_desc_to_dir(), log_prefix_(), log_tor_version(), metrics_format_label(), namemap_fmt_name(), orconn_target_get_name(), pem_encode(), port_to_str(), router_load_single_router(), router_parse_addr_policy_item_from_string(), smartlist_contains_int_as_string(), storage_dir_save_labeled_to_file(), tls_log_errors(), token_check_object(), tor_addr_to_PTR_name(), tor_addr_to_str(), tor_inet_ntoa(), tor_inet_ntop(), tor_init(), and write_stream_target_to_buf().

◆ tor_vasprintf()

int tor_vasprintf ( char **  strp,
const char *  fmt,
va_list  args 
)

Portable vasprintf implementation. Does a printf() into a newly malloc'd string. Differs from regular vasprintf in the same ways that tor_asprintf() differs from regular asprintf.

Definition at line 96 of file printf.c.

Referenced by buf_add_vprintf(), connection_printf_to_buf(), control_reply_add_printf(), control_vprintf_reply(), process_vprintf(), send_control_event_impl(), smartlist_add_vasprintf(), tor_asprintf(), and tor_assertion_failed_().

◆ tor_vsnprintf()

int tor_vsnprintf ( char *  str,
size_t  size,
const char *  format,
va_list  args 
)

Replacement for vsnprintf; behavior differs as tor_snprintf differs from snprintf.

Definition at line 41 of file printf.c.

Referenced by tor_snprintf().