iPXE
Functions
string.c File Reference

String functions. More...

#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void * generic_memset (void *dest, int character, size_t len)
 Fill memory region. More...
 
void * generic_memcpy (void *dest, const void *src, size_t len)
 Copy memory region (forwards) More...
 
void * generic_memcpy_reverse (void *dest, const void *src, size_t len)
 Copy memory region (backwards) More...
 
void * generic_memmove (void *dest, const void *src, size_t len)
 Copy (possibly overlapping) memory region. More...
 
int memcmp (const void *first, const void *second, size_t len)
 Compare memory regions. More...
 
void * memchr (const void *src, int character, size_t len)
 Find character within a memory region. More...
 
void * memswap (void *first, void *second, size_t len)
 Swap memory regions. More...
 
int strcmp (const char *first, const char *second)
 Compare strings. More...
 
int strncmp (const char *first, const char *second, size_t max)
 Compare strings. More...
 
int strcasecmp (const char *first, const char *second)
 Compare case-insensitive strings. More...
 
int strncasecmp (const char *first, const char *second, size_t max)
 Compare case-insensitive strings. More...
 
size_t strlen (const char *src)
 Get length of string. More...
 
size_t strnlen (const char *src, size_t max)
 Get length of string. More...
 
char * strchr (const char *src, int character)
 Find character within a string. More...
 
char * strrchr (const char *src, int character)
 Find rightmost character within a string. More...
 
char * strstr (const char *haystack, const char *needle)
 Find substring. More...
 
char * strcpy (char *dest, const char *src)
 Copy string. More...
 
char * strncpy (char *dest, const char *src, size_t max)
 Copy string. More...
 
char * strcat (char *dest, const char *src)
 Concatenate string. More...
 
char * strdup (const char *src)
 Duplicate string. More...
 
char * strndup (const char *src, size_t max)
 Duplicate string. More...
 
unsigned int digit_value (unsigned int character)
 Calculate digit value. More...
 
static const char * strtoul_pre (const char *string, int *negate, int *base)
 Preprocess string for strtoul() or strtoull() More...
 
unsigned long strtoul (const char *string, char **endp, int base)
 Convert string to numeric value. More...
 
unsigned long long strtoull (const char *string, char **endp, int base)
 Convert string to numeric value. More...
 

Detailed Description

String functions.

Definition in file string.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ generic_memset()

void* generic_memset ( void *  dest,
int  character,
size_t  len 
)

Fill memory region.

Parameters
destDestination region
characterFill character
lenLength
Return values
destDestination region

Definition at line 47 of file string.c.

47  {
48  uint8_t *dest_bytes = dest;
49 
50  while ( len-- )
51  *(dest_bytes++) = character;
52  return dest;
53 }
static void * dest
Definition: strings.h:176
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14

References dest, and len.

◆ generic_memcpy()

void* generic_memcpy ( void *  dest,
const void *  src,
size_t  len 
)

Copy memory region (forwards)

Parameters
destDestination region
srcSource region
lenLength
Return values
destDestination region

Definition at line 63 of file string.c.

63  {
64  const uint8_t *src_bytes = src;
65  uint8_t *dest_bytes = dest;
66 
67  while ( len-- )
68  *(dest_bytes++) = *(src_bytes++);
69  return dest;
70 }
static void const void * src
Definition: crypto.h:244
static void * dest
Definition: strings.h:176
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14

References dest, len, and src.

Referenced by generic_memmove().

◆ generic_memcpy_reverse()

void* generic_memcpy_reverse ( void *  dest,
const void *  src,
size_t  len 
)

Copy memory region (backwards)

Parameters
destDestination region
srcSource region
lenLength
Return values
destDestination region

Definition at line 80 of file string.c.

80  {
81  const uint8_t *src_bytes = ( src + len );
82  uint8_t *dest_bytes = ( dest + len );
83 
84  while ( len-- )
85  *(--dest_bytes) = *(--src_bytes);
86  return dest;
87 }
static void const void * src
Definition: crypto.h:244
static void * dest
Definition: strings.h:176
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14

References dest, len, and src.

Referenced by generic_memmove().

◆ generic_memmove()

void* generic_memmove ( void *  dest,
const void *  src,
size_t  len 
)

Copy (possibly overlapping) memory region.

Parameters
destDestination region
srcSource region
lenLength
Return values
destDestination region

Definition at line 97 of file string.c.

97  {
98 
99  if ( dest < src ) {
100  return generic_memcpy ( dest, src, len );
101  } else {
102  return generic_memcpy_reverse ( dest, src, len );
103  }
104 }
static void const void * src
Definition: crypto.h:244
void * generic_memcpy(void *dest, const void *src, size_t len)
Copy memory region (forwards)
Definition: string.c:63
static void * dest
Definition: strings.h:176
void * generic_memcpy_reverse(void *dest, const void *src, size_t len)
Copy memory region (backwards)
Definition: string.c:80
uint32_t len
Length.
Definition: ena.h:14

References dest, generic_memcpy(), generic_memcpy_reverse(), len, and src.

◆ memcmp()

int memcmp ( const void *  first,
const void *  second,
size_t  len 
)

Compare memory regions.

Parameters
firstFirst region
secondSecond region
lenLength
Return values
diffDifference

Definition at line 114 of file string.c.

114  {
115  const uint8_t *first_bytes = first;
116  const uint8_t *second_bytes = second;
117  int diff;
118 
119  while ( len-- ) {
120  diff = ( *(first_bytes++) - *(second_bytes++) );
121  if ( diff )
122  return diff;
123  }
124  return 0;
125 }
static __always_inline int off_t userptr_t second
Definition: efi_uaccess.h:80
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References first, len, and second.

Referenced by acpimac_extract(), apply_syslog_settings(), asn1_compare(), asn1_okx(), base16_decode_okx(), base64_decode_okx(), bofm_en(), cachedhcp_apply(), cachedhcp_record(), ccmp_decrypt(), check_bios_interrupts(), cipher_decrypt_okx(), cipher_encrypt_okx(), com32_identify(), deflate_okx(), dhcp_deliver(), dhcpv6_check_duid(), dhe_key_okx(), digest_frag_okx(), dns_copy_okx(), dns_encode_okx(), eapol_key_rx(), efi_block_match(), efi_file_get_info(), efi_find_table(), efi_guid_ntoa(), efi_pxe_ip_filter(), efi_pxe_udp_read(), efi_shim_is_sbatlevel(), efi_veto_hp_xhci(), efi_veto_ip4config(), efi_veto_vmware_uefipxebc(), efivars_find(), elf_load(), elfboot_probe(), eoib_find(), eoib_find_peer(), eoib_rx_av(), eth_probe(), eth_slow_lacp_rx(), fc_els_logo_logout(), fc_peer_examine(), fc_peer_get_port_id(), fc_peer_get_wwn(), fc_peer_login(), fc_port_deliver(), fc_port_login(), fc_ulp_login(), fcels_exec(), fcoe_fip_rx(), fcoe_fip_rx_advertisement(), fcoe_rx(), find_ibdev(), hmac_okx(), hvm_cpuid_base(), ib_find_path_cache_entry(), ib_find_qp_mgid(), ib_mcast_detach(), ib_mi_handle(), ib_path_complete(), inet6_aton_okx(), int13_parse_eltorito(), int13con_find(), ipair_key(), ipoib_find_remac(), ipoib_map_remac(), ipv6_has_addr(), ipv6_is_fragment(), ipv6_route_okx(), ipv6_table_okx(), is_autoboot_ll_addr(), iscsi_handle_chap_r_value(), linda_verify_uc_ram(), lldp_fetch(), loopback_wait(), mac_address_from_string_specs(), memcpy_test_speed(), mlx_memory_cmp_priv(), mschapv2_okx(), ne_probe(), neighbour_find(), net80211_rx(), netfront_net_probe(), ntlm_authenticate_okx(), ntlm_data_okx(), ntlm_key_okx(), nvs_verify(), ocsp_compare_responder_key_hash(), pcnet32_setup_mac_addr(), peerblk_done(), peerblk_parse_block(), peerdist_discovery_reply(), peerdist_info_block_okx(), peerdist_info_passphrase_okx(), peerdist_info_segment_okx(), pem_marker(), png_probe(), rsa_verify(), rsdp_find_rsdt_range(), sandev_parse_iso9660(), script_probe(), slam_pull_header(), string_test_exec(), strstr(), tftp_rx(), tkip_decrypt(), tkip_mix_1(), tls_new_ciphertext(), tls_new_finished(), tls_new_server_hello(), trivial_memcmp_user(), typeof(), ucode_exec(), udp_demux(), uuid_aton_okx(), vlan_probe(), vmbus_find_driver(), wpa_derive_ptk(), wpa_handle_3_of_4(), x25519_invert_okx(), x25519_key_okx(), x25519_multiply_okx(), x509_chain_okx(), x509_check_ipaddress(), x509_check_root(), x509_fingerprint_okx(), xcm_find(), and xve_find().

◆ memchr()

void* memchr ( const void *  src,
int  character,
size_t  len 
)

Find character within a memory region.

Parameters
srcSource region
characterCharacter to find
lenLength
Return values
foundFound character, or NULL if not found

Definition at line 135 of file string.c.

135  {
136  const uint8_t *src_bytes = src;
137 
138  for ( ; len-- ; src_bytes++ ) {
139  if ( *src_bytes == character )
140  return ( ( void * ) src_bytes );
141  }
142  return NULL;
143 }
static void const void * src
Definition: crypto.h:244
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References len, NULL, and src.

Referenced by line_buffer(), rsa_decrypt(), string_test_exec(), and trivial_memchr_user().

◆ memswap()

void* memswap ( void *  first,
void *  second,
size_t  len 
)

Swap memory regions.

Parameters
firstFirst region
secondSecond region
lenLength
Return values
firstFirst region

Definition at line 153 of file string.c.

153  {
154  uint8_t *first_bytes = first;
155  uint8_t *second_bytes = second;
156  uint8_t temp;
157 
158  for ( ; len-- ; first_bytes++, second_bytes++ ) {
159  temp = *first_bytes;
160  *first_bytes = *second_bytes;
161  *second_bytes = temp;
162  }
163  return first;
164 }
static __always_inline int off_t userptr_t second
Definition: efi_uaccess.h:80
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References first, len, and second.

Referenced by arp_rx(), gdbudp_recv(), string_test_exec(), and tls_change_cipher().

◆ strcmp()

int strcmp ( const char *  first,
const char *  second 
)

Compare strings.

Parameters
firstFirst string
secondSecond string
Return values
diffDifference

Definition at line 173 of file string.c.

173  {
174 
175  return strncmp ( first, second, ~( ( size_t ) 0 ) );
176 }
static __always_inline int off_t userptr_t second
Definition: efi_uaccess.h:80
int strncmp(const char *first, const char *second, size_t max)
Compare strings.
Definition: string.c:186
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References first, second, and strncmp().

Referenced by apply_syslogs_settings(), base16_encode_okx(), base64_encode_okx(), bzimage_parse_cmdline(), command_terminator(), dns_decode_okx(), dns_list_okx(), efi_veto_hp_xhci(), efi_veto_ip4config(), efi_veto_vmware_uefipxebc(), execv(), fc_port_find(), fdt_child(), fdt_property(), find_child_settings(), find_gdb_transport(), find_image(), find_menu(), find_netdev(), find_netdev_configurator(), find_parameters(), find_setting(), find_setting_type(), goto_find_label(), gzip_okx(), have_pxe_menu(), http_connect(), inet6_ntoa_okx(), inet_ntoa_okx(), ipair_rx_pair_error(), ipair_rx_session_error(), iscsi_handle_authmethod_value(), iscsi_handle_chap_a_value(), iscsi_handle_chap_n_value(), iscsi_handle_string(), iseq_exec(), keymap_find(), linebuf_accumulated_okx(), linebuf_consume_okx(), list_check_contents(), net80211_check_settings_update(), net80211_probe_step(), nfs_mount_deliver(), peerdisc_discovered(), peerdisc_find(), setting_cmp(), show_menu(), smsc95xx_vm3_fetch_mac(), snprintf_okx(), string_test_exec(), tls_session(), uri_churi_okx(), uri_format_okx(), uri_params_list_okx(), uri_pxe_okx(), uri_resolve_okx(), uri_resolve_path_okx(), uristrcmp(), usbblk_find(), uuid_ntoa_okx(), xenbus_find_driver(), and zlib_okx().

◆ strncmp()

int strncmp ( const char *  first,
const char *  second,
size_t  max 
)

Compare strings.

Parameters
firstFirst string
secondSecond string
maxMaximum length to compare
Return values
diffDifference

Definition at line 186 of file string.c.

186  {
187  const uint8_t *first_bytes = ( ( const uint8_t * ) first );
188  const uint8_t *second_bytes = ( ( const uint8_t * ) second );
189  int diff;
190 
191  for ( ; max-- ; first_bytes++, second_bytes++ ) {
192  diff = ( *first_bytes - *second_bytes );
193  if ( diff )
194  return diff;
195  if ( ! *first_bytes )
196  return 0;
197  }
198  return 0;
199 }
#define max(x, y)
Definition: ath.h:39
static __always_inline int off_t userptr_t second
Definition: efi_uaccess.h:80
unsigned char uint8_t
Definition: stdint.h:10
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References first, max, and second.

Referenced by dhcp_discovery_rx(), http_parse_status(), iscsi_handle_string(), match_long_option(), nfs_uri_symlink(), parse_uri(), peerdist_discovery_reply_tag(), strcmp(), string_test_exec(), and undinet_probe().

◆ strcasecmp()

int strcasecmp ( const char *  first,
const char *  second 
)

Compare case-insensitive strings.

Parameters
firstFirst string
secondSecond string
Return values
diffDifference

Definition at line 208 of file string.c.

208  {
209 
210  return strncasecmp ( first, second, ~( ( size_t ) 0 ) );
211 }
static __always_inline int off_t userptr_t second
Definition: efi_uaccess.h:80
int strncasecmp(const char *first, const char *second, size_t max)
Compare case-insensitive strings.
Definition: string.c:221
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References first, second, and strncasecmp().

Referenced by com32_identify(), comboot_identify(), efi_block_label(), efi_file_find(), efi_file_open(), efi_local_check_volume_name(), efi_snp_hii_fetch(), efi_snp_hii_store(), http_authentication(), http_digest_authenticate(), http_format_metadata_flavor(), http_parse_connection(), http_parse_content_encoding(), http_parse_digest_auth(), http_parse_header(), http_parse_transfer_encoding(), http_scheme(), parse_fc_els_handler(), string_test_exec(), sundance_probe(), tftp_process_option(), and xfer_uri_opener().

◆ strncasecmp()

int strncasecmp ( const char *  first,
const char *  second,
size_t  max 
)

Compare case-insensitive strings.

Parameters
firstFirst string
secondSecond string
maxMaximum length to compare
Return values
diffDifference

Definition at line 221 of file string.c.

221  {
222  const uint8_t *first_bytes = ( ( const uint8_t * ) first );
223  const uint8_t *second_bytes = ( ( const uint8_t * ) second );
224  int diff;
225 
226  for ( ; max-- ; first_bytes++, second_bytes++ ) {
227  diff = ( toupper ( *first_bytes ) -
228  toupper ( *second_bytes ) );
229  if ( diff )
230  return diff;
231  if ( ! *first_bytes )
232  return 0;
233  }
234  return 0;
235 }
#define max(x, y)
Definition: ath.h:39
static __always_inline int off_t userptr_t second
Definition: efi_uaccess.h:80
static int toupper(int character)
Convert character to upper case.
Definition: ctype.h:120
unsigned char uint8_t
Definition: stdint.h:10
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References first, max, second, and toupper().

Referenced by efi_file_open(), strcasecmp(), string_test_exec(), and x509_check_dnsname().

◆ strlen()

size_t strlen ( const char *  src)

Get length of string.

Parameters
srcString
Return values
lenLength

Definition at line 243 of file string.c.

243  {
244 
245  return strnlen ( src, ~( ( size_t ) 0 ) );
246 }
static void const void * src
Definition: crypto.h:244
size_t strnlen(const char *src, size_t max)
Get length of string.
Definition: string.c:255

References src, and strnlen().

Referenced by _print_label(), acpimac_extract(), add_menu_item(), add_parameter(), autovivify_child_settings(), base16_decoded_max_len(), base16_encode_okx(), base64_decoded_max_len(), base64_encode_okx(), bzimage_set_cmdline(), cmdline_init(), comboot_copy_cmdline(), concat_args(), cpio_name_len(), create_menu(), create_parameters(), dns_decode_okx(), dns_list_okx(), draw_editbox(), draw_menu_item(), edit_string(), efi_block_exec(), efi_block_filename(), efi_cmdline_init(), efi_file_varlen(), efi_ifr_package(), efi_image_path(), efi_iscsi_path(), efi_local_open_resolved(), efi_snp_hii_append(), efi_snp_hii_store(), efivars_fetch(), generic_settings_store(), guestinfo_fetch_type(), guestrpc_command(), http_digest_update(), http_format_basic_auth(), http_parse_headers(), http_parse_ntlm_auth(), ib_srp_parse_byte_string(), ibft_set_string(), image_argument(), init_editbox(), insert_delete(), ipair_tag(), ipv6_sock_aton(), iscsi_handle_chap_c_value(), iscsi_handle_chap_i_value(), iscsi_handle_chap_r_value(), iwlist(), linebuf_accumulated_okx(), login_ui(), match_long_option(), mschapv2_challenge_hash(), net80211_marshal_request_info(), netdev_fetch_bustype(), netdev_fetch_chip(), netdev_fetch_ifname(), nfs_uri_symlink(), parse_net_args(), parse_string_setting(), parse_uri(), peerblk_retrieval_uri(), peerdisc_create(), peerdisc_discovered(), peerdisc_socket_rx(), peerdisc_socket_tx(), peerdist_discovery_reply(), peerdist_discovery_reply_tag(), peerdist_discovery_reply_values(), pem_marker(), prf_sha1(), pxenv_file_cmdline(), readline_history(), resolv(), resolv_setting(), resolve_path(), show_menu(), snprintf_okx(), strcat(), string_copy(), string_test_exec(), strstr(), sync_console(), tftp_send_error(), tftp_send_rrq(), tls_client_hello(), tls_session(), trivial_strlen_user(), uri_copy_fields(), uri_decode_inplace(), uri_encode_string(), uri_format_okx(), uri_pxe_okx(), validator_start_download(), version_fetch(), wpa_psk_start(), x509_check_dnsname(), xenbus_probe(), xenbus_probe_device(), xenbus_probe_type(), xenstore_dump(), xenstore_request(), xenstore_response(), and xenstore_send_string().

◆ strnlen()

size_t strnlen ( const char *  src,
size_t  max 
)

Get length of string.

Parameters
srcString
maxMaximum length
Return values
lenLength

Definition at line 255 of file string.c.

255  {
256  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
257  size_t len = 0;
258 
259  while ( max-- && *(src_bytes++) )
260  len++;
261  return len;
262 }
#define max(x, y)
Definition: ath.h:39
static void const void * src
Definition: crypto.h:244
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14

References len, max, and src.

Referenced by efi_pecoff_debug_name(), fdt_string(), fdt_traverse(), iscsi_handle_strings(), string_test_exec(), strlen(), strndup(), tftp_rx_oack(), and used_len_string().

◆ strchr()

char* strchr ( const char *  src,
int  character 
)

Find character within a string.

Parameters
srcString
characterCharacter to find
Return values
foundFound character, or NULL if not found

Definition at line 271 of file string.c.

271  {
272  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
273 
274  for ( ; ; src_bytes++ ) {
275  if ( *src_bytes == character )
276  return ( ( char * ) src_bytes );
277  if ( ! *src_bytes )
278  return NULL;
279  }
280 }
static void const void * src
Definition: crypto.h:244
unsigned char uint8_t
Definition: stdint.h:10
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References NULL, and src.

Referenced by base64_decode(), bzimage_parse_cmdline(), cmdline_strip(), comboot_fetch_kernel(), cpio_name_len(), dns_resolv(), efi_pecoff_debug_name(), fdt_path(), http_parse_header(), ipv6_sock_aton(), iscsi_handle_string(), iscsi_handle_targetaddress_value(), netbios_domain(), nfs_uri_init(), parse_setting_name(), parse_settings_name(), parse_uri(), slam_parse_multicast_address(), string_test_exec(), tftp_process_multicast(), uri_character_escaped(), and x509_check_dnsname().

◆ strrchr()

char* strrchr ( const char *  src,
int  character 
)

Find rightmost character within a string.

Parameters
srcString
characterCharacter to find
Return values
foundFound character, or NULL if not found

Definition at line 289 of file string.c.

289  {
290  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
291  const uint8_t *start = src_bytes;
292 
293  while ( *src_bytes )
294  src_bytes++;
295  for ( src_bytes-- ; src_bytes >= start ; src_bytes-- ) {
296  if ( *src_bytes == character )
297  return ( ( char * ) src_bytes );
298  }
299  return NULL;
300 }
static void const void * src
Definition: crypto.h:244
uint32_t start
Starting offset.
Definition: netvsc.h:12
unsigned char uint8_t
Definition: stdint.h:10
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References NULL, src, and start.

Referenced by basename(), com32_identify(), comboot_identify(), dirname(), efi_autoexec_tftp(), efi_file_open(), efi_pecoff_debug_name(), image_extract(), nfs_uri_next_mountpoint(), parse_uri(), and string_test_exec().

◆ strstr()

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

Find substring.

Parameters
haystackString
needleSubstring
Return values
foundFound substring, or NULL if not found

Definition at line 309 of file string.c.

309  {
310  size_t len = strlen ( needle );
311 
312  for ( ; *haystack ; haystack++ ) {
313  if ( memcmp ( haystack, needle, len ) == 0 )
314  return ( ( char * ) haystack );
315  }
316  return NULL;
317 }
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
uint32_t len
Length.
Definition: ena.h:14
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References len, memcmp(), NULL, and strlen().

Referenced by cmdline_strip(), comboot_fetch_kernel(), image_argument(), ipair_tag(), parse_uri(), string_test_exec(), and ucode_exec().

◆ strcpy()

char* strcpy ( char *  dest,
const char *  src 
)

Copy string.

Parameters
destDestination string
srcSource string
Return values
destDestination string

Definition at line 326 of file string.c.

326  {
327  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
328  uint8_t *dest_bytes = ( ( uint8_t * ) dest );
329 
330  /* We cannot use strncpy(), since that would pad the destination */
331  for ( ; ; src_bytes++, dest_bytes++ ) {
332  *dest_bytes = *src_bytes;
333  if ( ! *dest_bytes )
334  break;
335  }
336  return dest;
337 }
static void const void * src
Definition: crypto.h:244
static void * dest
Definition: strings.h:176
unsigned char uint8_t
Definition: stdint.h:10

References dest, and src.

Referenced by add_menu_item(), add_parameter(), cmdline_strip(), create_menu(), create_parameters(), efi_autoexec_tftp(), efi_ifr_package(), ibft_set_string(), icert_encode(), inet6_ntoa(), net80211_prepare_assoc(), net80211_probe_start(), net80211_probe_step(), nfs_uri_symlink(), parse_uri(), peerdisc_discovered(), peerdist_discovery_reply(), resolv_setting(), strcat(), string_test_exec(), tftp_send_error(), and tls_session().

◆ strncpy()

char* strncpy ( char *  dest,
const char *  src,
size_t  max 
)

Copy string.

Parameters
destDestination string
srcSource string
maxMaximum length
Return values
destDestination string

Definition at line 347 of file string.c.

347  {
348  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
349  uint8_t *dest_bytes = ( ( uint8_t * ) dest );
350 
351  for ( ; max ; max--, src_bytes++, dest_bytes++ ) {
352  *dest_bytes = *src_bytes;
353  if ( ! *dest_bytes )
354  break;
355  }
356  while ( max-- )
357  *(dest_bytes++) = '\0';
358  return dest;
359 }
#define max(x, y)
Definition: ath.h:39
static void const void * src
Definition: crypto.h:244
static void * dest
Definition: strings.h:176
unsigned char uint8_t
Definition: stdint.h:10

References dest, max, and src.

Referenced by buildarch_fetch(), efi_block_install(), int13_install(), netdev_fetch_bustype(), netdev_fetch_chip(), netdev_fetch_ifname(), platform_fetch(), slk_set(), string_test_exec(), and version_fetch().

◆ strcat()

char* strcat ( char *  dest,
const char *  src 
)

Concatenate string.

Parameters
destDestination string
srcSource string
Return values
destDestination string

Definition at line 368 of file string.c.

368  {
369 
370  strcpy ( ( dest + strlen ( dest ) ), src );
371  return dest;
372 }
static void const void * src
Definition: crypto.h:244
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:326
static void * dest
Definition: strings.h:176
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243

References dest, src, strcpy(), and strlen().

Referenced by _print_label(), and string_test_exec().

◆ strdup()

char* strdup ( const char *  src)

Duplicate string.

Parameters
srcSource string
Return values
dupDuplicated string, or NULL if allocation failed

Definition at line 380 of file string.c.

380  {
381 
382  return strndup ( src, ~( ( size_t ) 0 ) );
383 }
static void const void * src
Definition: crypto.h:244
char * strndup(const char *src, size_t max)
Duplicate string.
Definition: string.c:392

References src, and strndup().

Referenced by expand_settings(), history_append(), history_store(), http_parse_ntlm_auth(), ib_srp_parse_root_path(), image_set_cmdline(), image_set_name(), ipv6_sock_aton(), iscsi_handle_targetaddress_value(), iscsi_parse_root_path(), nfs_parse_uri(), nfs_uri_init(), nfs_uri_next_mountpoint(), oncrpc_init_cred_sys(), parse_settings_name(), peerdisc_discovered(), resolve_path(), resolve_uri(), slam_parse_multicast_address(), string_test_exec(), and system().

◆ strndup()

char* strndup ( const char *  src,
size_t  max 
)

Duplicate string.

Parameters
srcSource string
maxMaximum length
Return values
dupDuplicated string, or NULL if allocation failed

Definition at line 392 of file string.c.

392  {
393  size_t len = strnlen ( src, max );
394  char *dup;
395 
396  dup = malloc ( len + 1 /* NUL */ );
397  if ( dup ) {
398  memcpy ( dup, src, len );
399  dup[len] = '\0';
400  }
401  return dup;
402 }
#define max(x, y)
Definition: ath.h:39
static void const void * src
Definition: crypto.h:244
void * memcpy(void *dest, const void *src, size_t len) __nonnull
size_t strnlen(const char *src, size_t max)
Get length of string.
Definition: string.c:255
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
uint32_t len
Length.
Definition: ena.h:14

References len, malloc(), max, memcpy(), src, and strnlen().

Referenced by nfs_deliver(), strdup(), and string_test_exec().

◆ digit_value()

unsigned int digit_value ( unsigned int  character)

Calculate digit value.

Parameters
characterDigit character
Return values
digitDigit value

Invalid digits will be returned as a value greater than or equal to the numeric base.

Definition at line 413 of file string.c.

413  {
414 
415  if ( character >= 'a' )
416  return ( character - ( 'a' - 10 ) );
417  if ( character >= 'A' )
418  return ( character - ( 'A' - 10 ) );
419  if ( character <= '9' )
420  return ( character - '0' );
421  return character;
422 }

Referenced by hex_decode(), string_test_exec(), strtoul(), and strtoull().

◆ strtoul_pre()

static const char* strtoul_pre ( const char *  string,
int *  negate,
int *  base 
)
static

Preprocess string for strtoul() or strtoull()

Parameters
stringString
negateFinal value should be negated
baseNumeric base
Return values
stringRemaining string

Definition at line 432 of file string.c.

432  {
433 
434  /* Skip any leading whitespace */
435  while ( isspace ( *string ) )
436  string++;
437 
438  /* Process arithmetic sign, if present */
439  *negate = 0;
440  if ( *string == '-' ) {
441  string++;
442  *negate = 1;
443  } else if ( *string == '+' ) {
444  string++;
445  }
446 
447  /* Process base, if present */
448  if ( *base == 0 ) {
449  *base = 10;
450  if ( *string == '0' ) {
451  string++;
452  *base = 8;
453  if ( ( *string & ~0x20 ) == 'X' ) {
454  string++;
455  *base = 16;
456  }
457  }
458  }
459 
460  return string;
461 }
uint32_t string
Definition: multiboot.h:14
static const void * base
Base address.
Definition: crypto.h:335
int isspace(int character)
Check to see if character is a space.
Definition: ctype.c:41

References base, isspace(), and string.

Referenced by strtoul(), and strtoull().

◆ strtoul()

unsigned long strtoul ( const char *  string,
char **  endp,
int  base 
)

Convert string to numeric value.

Parameters
stringString
endpEnd pointer (or NULL)
baseNumeric base (or zero to autodetect)
Return values
valueNumeric value

Definition at line 471 of file string.c.

471  {
472  unsigned long value = 0;
473  unsigned int digit;
474  int negate;
475 
476  /* Preprocess string */
477  string = strtoul_pre ( string, &negate, &base );
478 
479  /* Process digits */
480  for ( ; ; string++ ) {
481  digit = digit_value ( *string );
482  if ( digit >= ( unsigned int ) base )
483  break;
484  value = ( ( value * base ) + digit );
485  }
486 
487  /* Negate value if, applicable */
488  if ( negate )
489  value = -value;
490 
491  /* Fill in end pointer, if applicable */
492  if ( endp )
493  *endp = ( ( char * ) string );
494 
495  return value;
496 }
unsigned int digit_value(unsigned int character)
Calculate digit value.
Definition: string.c:413
static const void * base
Base address.
Definition: crypto.h:335
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static const char * strtoul_pre(const char *string, int *negate, int *base)
Preprocess string for strtoul() or strtoull()
Definition: string.c:432

References base, digit_value(), strtoul_pre(), and value.

Referenced by aoe_parse_uri(), bzimage_parse_cmdline(), cpio_parse_cmdline(), efi_snp_hii_store(), fc_aton(), fc_id_aton(), ftp_parse_value(), ftp_reply(), gdbserial_init(), http_parse_content_length(), http_parse_retry_after(), http_parse_status(), http_rx_chunk_len(), ib_srp_parse_integer(), inet6_aton(), inet_aton(), iscsi_handle_chap_i_value(), iscsi_handle_maxburstlength_value(), iscsi_handle_targetaddress_value(), iscsi_parse_root_path(), mac_address_from_string_specs(), parse_int_setting(), parse_integer(), parse_setting_tag(), pnm_ascii(), scsi_parse_lun(), slam_parse_multicast_address(), string_test_exec(), tftp_process_blksize(), tftp_process_multicast(), tftp_process_tsize(), uri_decode(), uri_port(), and xenstore_read_num().

◆ strtoull()

unsigned long long strtoull ( const char *  string,
char **  endp,
int  base 
)

Convert string to numeric value.

Parameters
stringString
endpEnd pointer (or NULL)
baseNumeric base (or zero to autodetect)
Return values
valueNumeric value

Definition at line 506 of file string.c.

506  {
507  unsigned long long value = 0;
508  unsigned int digit;
509  int negate;
510 
511  /* Preprocess string */
512  string = strtoul_pre ( string, &negate, &base );
513 
514  /* Process digits */
515  for ( ; ; string++ ) {
516  digit = digit_value ( *string );
517  if ( digit >= ( unsigned int ) base )
518  break;
519  value = ( ( value * base ) + digit );
520  }
521 
522  /* Negate value if, applicable */
523  if ( negate )
524  value = -value;
525 
526  /* Fill in end pointer, if applicable */
527  if ( endp )
528  *endp = ( ( char * ) string );
529 
530  return value;
531 }
unsigned int digit_value(unsigned int character)
Calculate digit value.
Definition: string.c:413
static const void * base
Base address.
Definition: crypto.h:335
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static const char * strtoul_pre(const char *string, int *negate, int *base)
Preprocess string for strtoul() or strtoull()
Definition: string.c:432

References base, digit_value(), strtoul_pre(), and value.