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 * stpcpy (char *dest, const char *src)
 Copy string. 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 }
unsigned char uint8_t
Definition: stdint.h:10
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150
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 const void * src
Definition: string.h:47
unsigned char uint8_t
Definition: stdint.h:10
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150
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 const void * src
Definition: string.h:47
unsigned char uint8_t
Definition: stdint.h:10
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150
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 const void * src
Definition: string.h:47
void * generic_memcpy(void *dest, const void *src, size_t len)
Copy memory region (forwards)
Definition: string.c:63
void * generic_memcpy_reverse(void *dest, const void *src, size_t len)
Copy memory region (backwards)
Definition: string.c:80
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150
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 }
uint32_t first
First block in range.
Definition: pccrr.h:14
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
static __always_inline int off_t userptr_t second
Definition: librm.h:166

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(), cms_decrypt(), 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_path_net_probe(), efi_pxe_ip_filter(), efi_pxe_udp_read(), efi_shim_is_sbatlevel(), efi_veto_dhcp6(), 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(), pubkey_okx(), pubkey_sign_okx(), 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 const void * src
Definition: string.h:47
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 }
uint32_t first
First block in range.
Definition: pccrr.h:14
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
static __always_inline int off_t userptr_t second
Definition: librm.h:166

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 }
uint32_t first
First block in range.
Definition: pccrr.h:14
int strncmp(const char *first, const char *second, size_t max)
Compare strings.
Definition: string.c:186
static __always_inline int off_t userptr_t second
Definition: librm.h:166

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(), editstring_okx(), efi_veto_hp_xhci(), efi_veto_ip4config(), efi_veto_vmware_uefipxebc(), execv(), fc_port_find(), fdt_child(), fdt_property(), find_child_settings(), find_dynui(), find_gdb_transport(), find_image(), 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
uint32_t first
First block in range.
Definition: pccrr.h:14
unsigned char uint8_t
Definition: stdint.h:10
static __always_inline int off_t userptr_t second
Definition: librm.h:166

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 }
uint32_t first
First block in range.
Definition: pccrr.h:14
int strncasecmp(const char *first, const char *second, size_t max)
Compare case-insensitive strings.
Definition: string.c:221
static __always_inline int off_t userptr_t second
Definition: librm.h:166

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
uint32_t first
First block in range.
Definition: pccrr.h:14
static int toupper(int character)
Convert character to upper case.
Definition: ctype.h:120
unsigned char uint8_t
Definition: stdint.h:10
static __always_inline int off_t userptr_t second
Definition: librm.h:166

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 const void * src
Definition: string.h:47
size_t strnlen(const char *src, size_t max)
Get length of string.
Definition: string.c:255

References src, and strnlen().

Referenced by __attribute__(), _print_label(), acpimac_extract(), add_dynui_item(), add_parameter(), alloc_form(), 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_dynui(), create_parameters(), cwuri_fetch_uri(), dns_decode_okx(), dns_list_okx(), draw_editbox(), draw_menu_item(), edit_string(), editstring_okx(), 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(), ipair_tag(), ipv6_sock_aton(), iscsi_handle_chap_c_value(), iscsi_handle_chap_i_value(), iscsi_handle_chap_r_value(), iwlist(), linebuf_accumulated_okx(), match_long_option(), mschapv2_challenge_hash(), net80211_marshal_request_info(), netdev_fetch_bustype(), netdev_fetch_chip(), netdev_fetch_ifname(), netdev_fetch_linktype(), 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(), 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 }
static const void * src
Definition: string.h:47
#define max(x, y)
Definition: ath.h:39
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 const void * src
Definition: string.h:47
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 const void * src
Definition: string.h:47
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_file_open(), efi_pecoff_debug_name(), image_strip_suffix(), 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
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
uint32_t len
Length.
Definition: ena.h:14
#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().

◆ stpcpy()

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

Copy string.

Parameters
destDestination string
srcSource string
Return values
dnulTerminating NUL of destination 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 ( ( char * ) dest_bytes );
337 }
static const void * src
Definition: string.h:47
unsigned char uint8_t
Definition: stdint.h:10
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150

References dest, and src.

Referenced by alloc_form(), strcpy(), and string_test_exec().

◆ strcpy()

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

Copy string.

Parameters
destDestination string
srcSource string
Return values
destDestination string

Definition at line 346 of file string.c.

346  {
347 
348  stpcpy ( dest, src );
349  return dest;
350 }
static const void * src
Definition: string.h:47
char * stpcpy(char *dest, const char *src)
Copy string.
Definition: string.c:326
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150

References dest, src, and stpcpy().

Referenced by add_dynui_item(), add_parameter(), cmdline_strip(), create_dynui(), create_parameters(), 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 360 of file string.c.

360  {
361  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
362  uint8_t *dest_bytes = ( ( uint8_t * ) dest );
363 
364  for ( ; max ; max--, src_bytes++, dest_bytes++ ) {
365  *dest_bytes = *src_bytes;
366  if ( ! *dest_bytes )
367  break;
368  }
369  while ( max-- )
370  *(dest_bytes++) = '\0';
371  return dest;
372 }
static const void * src
Definition: string.h:47
#define max(x, y)
Definition: ath.h:39
unsigned char uint8_t
Definition: stdint.h:10
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150

References dest, max, and src.

Referenced by buildarch_fetch(), cwuri_fetch_uri(), efi_block_install(), int13_install(), netdev_fetch_bustype(), netdev_fetch_chip(), netdev_fetch_ifname(), netdev_fetch_linktype(), 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 381 of file string.c.

381  {
382 
383  strcpy ( ( dest + strlen ( dest ) ), src );
384  return dest;
385 }
static const void * src
Definition: string.h:47
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:346
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150

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 393 of file string.c.

393  {
394 
395  return strndup ( src, ~( ( size_t ) 0 ) );
396 }
static const void * src
Definition: string.h:47
char * strndup(const char *src, size_t max)
Duplicate string.
Definition: string.c:405

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 405 of file string.c.

405  {
406  size_t len = strnlen ( src, max );
407  char *dup;
408 
409  dup = malloc ( len + 1 /* NUL */ );
410  if ( dup ) {
411  memcpy ( dup, src, len );
412  dup[len] = '\0';
413  }
414  return dup;
415 }
static const void * src
Definition: string.h:47
#define max(x, y)
Definition: ath.h:39
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 426 of file string.c.

426  {
427 
428  if ( character >= 'a' )
429  return ( character - ( 'a' - 10 ) );
430  if ( character >= 'A' )
431  return ( character - ( 'A' - 10 ) );
432  if ( character <= '9' )
433  return ( character - '0' );
434  return character;
435 }

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 445 of file string.c.

445  {
446 
447  /* Skip any leading whitespace */
448  while ( isspace ( *string ) )
449  string++;
450 
451  /* Process arithmetic sign, if present */
452  *negate = 0;
453  if ( *string == '-' ) {
454  string++;
455  *negate = 1;
456  } else if ( *string == '+' ) {
457  string++;
458  }
459 
460  /* Process base, if present */
461  if ( *base == 0 ) {
462  *base = 10;
463  if ( *string == '0' ) {
464  string++;
465  *base = 8;
466  if ( ( *string & ~0x20 ) == 'X' ) {
467  string++;
468  *base = 16;
469  }
470  }
471  }
472 
473  return string;
474 }
uint32_t base
Base.
Definition: librm.h:252
uint32_t string
Definition: multiboot.h:14
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 484 of file string.c.

484  {
485  unsigned long value = 0;
486  unsigned int digit;
487  int negate;
488 
489  /* Preprocess string */
490  string = strtoul_pre ( string, &negate, &base );
491 
492  /* Process digits */
493  for ( ; ; string++ ) {
494  digit = digit_value ( *string );
495  if ( digit >= ( unsigned int ) base )
496  break;
497  value = ( ( value * base ) + digit );
498  }
499 
500  /* Negate value if, applicable */
501  if ( negate )
502  value = -value;
503 
504  /* Fill in end pointer, if applicable */
505  if ( endp )
506  *endp = ( ( char * ) string );
507 
508  return value;
509 }
uint32_t base
Base.
Definition: librm.h:252
unsigned int digit_value(unsigned int character)
Calculate digit value.
Definition: string.c:426
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:445

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 519 of file string.c.

519  {
520  unsigned long long value = 0;
521  unsigned int digit;
522  int negate;
523 
524  /* Preprocess string */
525  string = strtoul_pre ( string, &negate, &base );
526 
527  /* Process digits */
528  for ( ; ; string++ ) {
529  digit = digit_value ( *string );
530  if ( digit >= ( unsigned int ) base )
531  break;
532  value = ( ( value * base ) + digit );
533  }
534 
535  /* Negate value if, applicable */
536  if ( negate )
537  value = -value;
538 
539  /* Fill in end pointer, if applicable */
540  if ( endp )
541  *endp = ( ( char * ) string );
542 
543  return value;
544 }
uint32_t base
Base.
Definition: librm.h:252
unsigned int digit_value(unsigned int character)
Calculate digit value.
Definition: string.c:426
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:445

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