iPXE
Functions
string.c File Reference

String functions. More...

#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.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. 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...
 
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 46 of file string.c.

46  {
47  uint8_t *dest_bytes = dest;
48 
49  while ( len-- )
50  *(dest_bytes++) = character;
51  return dest;
52 }
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.

Parameters
destDestination region
srcSource region
lenLength
Return values
destDestination region

Definition at line 62 of file string.c.

62  {
63  const uint8_t *src_bytes = src;
64  uint8_t *dest_bytes = dest;
65 
66  while ( len-- )
67  *(dest_bytes++) = *(src_bytes++);
68  return dest;
69 }
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
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 79 of file string.c.

79  {
80  const uint8_t *src_bytes = ( src + len );
81  uint8_t *dest_bytes = ( dest + len );
82 
83  if ( dest < src )
84  return generic_memcpy ( dest, src, len );
85  while ( len-- )
86  *(--dest_bytes) = *(--src_bytes);
87  return dest;
88 }
void * generic_memcpy(void *dest, const void *src, size_t len)
Copy memory region.
Definition: string.c:62
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14

References dest, generic_memcpy(), 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 98 of file string.c.

98  {
99  const uint8_t *first_bytes = first;
100  const uint8_t *second_bytes = second;
101  int diff;
102 
103  while ( len-- ) {
104  diff = ( *(second_bytes++) - *(first_bytes++) );
105  if ( diff )
106  return diff;
107  }
108  return 0;
109 }
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 apply_syslog_settings(), asn1_compare(), asn1_okx(), base16_decode_okx(), base64_decode_okx(), bofm_en(), cachedhcp_probe(), ccmp_decrypt(), check_bios_interrupts(), cipher_decrypt_okx(), cipher_encrypt_okx(), com32_identify(), deflate_okx(), dhcp_deliver(), dhcpv6_check_duid(), digest_frag_okx(), dns_copy_okx(), dns_encode_okx(), eapol_key_rx(), efi_blacklist_dell_ip4config(), efi_block_boot_image(), efi_file_get_info(), efi_find_table(), efi_guid_ntoa(), efi_pxe_ip_filter(), efi_pxe_udp_read(), elf_load(), elfboot_probe(), eoib_find(), eoib_find_peer(), eoib_rx_av(), eth_probe(), 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(), find_netdev_by_ll_addr(), 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(), ipoib_find_remac(), ipoib_map_remac(), ipv6_has_addr(), ipv6_is_fragment(), ipv6_route_okx(), is_autoboot_ll_addr(), iscsi_handle_chap_r_value(), linda_verify_uc_ram(), loopback_wait(), mac_address_from_string_specs(), memcpy_test_speed(), mlx_memory_cmp_priv(), ne_probe(), neighbour_find(), net80211_rx(), 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(), udp_demux(), vmbus_find_driver(), wpa_derive_ptk(), wpa_handle_3_of_4(), x509_chain_okx(), x509_check_dnsname(), 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 119 of file string.c.

119  {
120  const uint8_t *src_bytes = src;
121 
122  for ( ; len-- ; src_bytes++ ) {
123  if ( *src_bytes == character )
124  return ( ( void * ) src_bytes );
125  }
126  return NULL;
127 }
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

137  {
138  uint8_t *first_bytes = first;
139  uint8_t *second_bytes = second;
140  uint8_t temp;
141 
142  for ( ; len-- ; first_bytes++, second_bytes++ ) {
143  temp = *first_bytes;
144  *first_bytes = *second_bytes;
145  *second_bytes = temp;
146  }
147  return first;
148 }
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 157 of file string.c.

157  {
158 
159  return strncmp ( first, second, ~( ( size_t ) 0 ) );
160 }
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:170
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_blacklist_dell_ip4config(), 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(), have_pxe_menu(), http_connect(), http_scheme(), inet6_ntoa_okx(), inet_ntoa_okx(), iscsi_handle_authmethod_value(), iscsi_handle_chap_a_value(), iscsi_handle_chap_n_value(), iscsi_handle_string(), iseq_exec(), 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(), xenbus_find_driver(), and xfer_uri_opener().

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

170  {
171  const uint8_t *first_bytes = ( ( const uint8_t * ) first );
172  const uint8_t *second_bytes = ( ( const uint8_t * ) second );
173  int diff;
174 
175  for ( ; max-- ; first_bytes++, second_bytes++ ) {
176  diff = ( *first_bytes - *second_bytes );
177  if ( diff )
178  return diff;
179  if ( ! *first_bytes )
180  return 0;
181  }
182  return 0;
183 }
#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 192 of file string.c.

192  {
193  const uint8_t *first_bytes = ( ( const uint8_t * ) first );
194  const uint8_t *second_bytes = ( ( const uint8_t * ) second );
195  int diff;
196 
197  for ( ; ; first_bytes++, second_bytes++ ) {
198  diff = ( toupper ( *first_bytes ) -
199  toupper ( *second_bytes ) );
200  if ( diff )
201  return diff;
202  if ( ! *first_bytes )
203  return 0;
204  }
205 }
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:109
unsigned char uint8_t
Definition: stdint.h:10
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References first, second, and toupper().

Referenced by com32_identify(), comboot_identify(), efi_file_find(), 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(), parse_fc_els_handler(), string_test_exec(), sundance_probe(), and tftp_process_option().

◆ strlen()

size_t strlen ( const char *  src)

Get length of string.

Parameters
srcString
Return values
lenLength

Definition at line 213 of file string.c.

213  {
214 
215  return strnlen ( src, ~( ( size_t ) 0 ) );
216 }
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
size_t strnlen(const char *src, size_t max)
Get length of string.
Definition: string.c:225

References src, and strnlen().

Referenced by _print_label(), add_menu_item(), add_parameter(), autovivify_child_settings(), base16_decoded_max_len(), base16_encode_okx(), base64_decoded_max_len(), base64_encode_okx(), bzimage_load_initrd(), bzimage_set_cmdline(), cmdline_init(), comboot_copy_cmdline(), concat_args(), create_menu(), create_parameters(), dns_decode_okx(), dns_list_okx(), draw_editbox(), draw_menu_item(), edit_string(), efi_block_boot_image(), efi_file_varlen(), efi_ifr_package(), efi_image_cmdline(), efi_image_path(), efi_local_open_resolved(), efi_snp_hii_append(), efi_snp_hii_store(), 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(), init_editbox(), insert_delete(), 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(), 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(), 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_send_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 225 of file string.c.

225  {
226  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
227  size_t len = 0;
228 
229  while ( max-- && *(src_bytes++) )
230  len++;
231  return len;
232 }
#define max(x, y)
Definition: ath.h:39
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
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 241 of file string.c.

241  {
242  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
243 
244  for ( ; ; src_bytes++ ) {
245  if ( *src_bytes == character )
246  return ( ( char * ) src_bytes );
247  if ( ! *src_bytes )
248  return NULL;
249  }
250 }
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
unsigned char uint8_t
Definition: stdint.h:10
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References NULL, and src.

Referenced by base64_decode(), bzimage_load_initrd(), cmdline_strip(), comboot_fetch_kernel(), 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 259 of file string.c.

259  {
260  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
261  const uint8_t *start = src_bytes;
262 
263  while ( *src_bytes )
264  src_bytes++;
265  for ( src_bytes-- ; src_bytes >= start ; src_bytes-- ) {
266  if ( *src_bytes == character )
267  return ( ( char * ) src_bytes );
268  }
269  return NULL;
270 }
uint32_t start
Starting offset.
Definition: netvsc.h:12
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
unsigned char uint8_t
Definition: stdint.h:10
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References NULL, src, and start.

Referenced by basename(), com32_identify(), comboot_identify(), dirname(), efi_pecoff_debug_name(), 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 279 of file string.c.

279  {
280  size_t len = strlen ( needle );
281 
282  for ( ; *haystack ; haystack++ ) {
283  if ( memcmp ( haystack, needle, len ) == 0 )
284  return ( ( char * ) haystack );
285  }
286  return NULL;
287 }
size_t strlen(const char *src)
Get length of string.
Definition: string.c:213
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:98
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by bzimage_parse_cmdline(), bzimage_parse_cpio_cmdline(), cmdline_strip(), comboot_fetch_kernel(), parse_uri(), 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 296 of file string.c.

296  {
297  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
298  uint8_t *dest_bytes = ( ( uint8_t * ) dest );
299 
300  /* We cannot use strncpy(), since that would pad the destination */
301  for ( ; ; src_bytes++, dest_bytes++ ) {
302  *dest_bytes = *src_bytes;
303  if ( ! *dest_bytes )
304  break;
305  }
306  return dest;
307 }
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
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_ifr_package(), ibft_set_string(), inet6_ntoa(), net80211_prepare_assoc(), net80211_probe_start(), net80211_probe_step(), nfs_uri_symlink(), 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 317 of file string.c.

317  {
318  const uint8_t *src_bytes = ( ( const uint8_t * ) src );
319  uint8_t *dest_bytes = ( ( uint8_t * ) dest );
320 
321  for ( ; max ; max--, src_bytes++, dest_bytes++ ) {
322  *dest_bytes = *src_bytes;
323  if ( ! *dest_bytes )
324  break;
325  }
326  while ( max-- )
327  *(dest_bytes++) = '\0';
328  return dest;
329 }
#define max(x, y)
Definition: ath.h:39
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
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 338 of file string.c.

338  {
339 
340  strcpy ( ( dest + strlen ( dest ) ), src );
341  return dest;
342 }
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:296
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
size_t strlen(const char *src)
Get length of string.
Definition: string.c:213

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

350  {
351 
352  return strndup ( src, ~( ( size_t ) 0 ) );
353 }
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
char * strndup(const char *src, size_t max)
Duplicate string.
Definition: string.c:362

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(), readline_history(), resolve_path(), 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 362 of file string.c.

362  {
363  size_t len = strnlen ( src, max );
364  char *dup;
365 
366  dup = malloc ( len + 1 /* NUL */ );
367  if ( dup ) {
368  memcpy ( dup, src, len );
369  dup[len] = '\0';
370  }
371  return dup;
372 }
#define max(x, y)
Definition: ath.h:39
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
size_t strnlen(const char *src, size_t max)
Get length of string.
Definition: string.c:225
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 383 of file string.c.

383  {
384 
385  if ( character >= 'a' )
386  return ( character - ( 'a' - 10 ) );
387  if ( character >= 'A' )
388  return ( character - ( 'A' - 10 ) );
389  if ( character <= '9' )
390  return ( character - '0' );
391  return character;
392 }

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

402  {
403 
404  /* Skip any leading whitespace */
405  while ( isspace ( *string ) )
406  string++;
407 
408  /* Process arithmetic sign, if present */
409  *negate = 0;
410  if ( *string == '-' ) {
411  string++;
412  *negate = 1;
413  } else if ( *string == '+' ) {
414  string++;
415  }
416 
417  /* Process base, if present */
418  if ( *base == 0 ) {
419  *base = 10;
420  if ( *string == '0' ) {
421  string++;
422  *base = 8;
423  if ( ( *string & ~0x20 ) == 'X' ) {
424  string++;
425  *base = 16;
426  }
427  }
428  }
429 
430  return string;
431 }
uint32_t string
Definition: multiboot.h:14
int isspace(int character)
Check to see if character is a space.
Definition: ctype.c:41
uint16_t base
Base address.
Definition: edd.h:14

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

441  {
442  unsigned long value = 0;
443  unsigned int digit;
444  int negate;
445 
446  /* Preprocess string */
447  string = strtoul_pre ( string, &negate, &base );
448 
449  /* Process digits */
450  for ( ; ; string++ ) {
451  digit = digit_value ( *string );
452  if ( digit >= ( unsigned int ) base )
453  break;
454  value = ( ( value * base ) + digit );
455  }
456 
457  /* Negate value if, applicable */
458  if ( negate )
459  value = -value;
460 
461  /* Fill in end pointer, if applicable */
462  if ( endp )
463  *endp = ( ( char * ) string );
464 
465  return value;
466 }
unsigned int digit_value(unsigned int character)
Calculate digit value.
Definition: string.c:383
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:402
uint16_t base
Base address.
Definition: edd.h:14

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

Referenced by aoe_parse_uri(), bzimage_parse_cmdline(), bzimage_parse_cpio_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_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 476 of file string.c.

476  {
477  unsigned long long value = 0;
478  unsigned int digit;
479  int negate;
480 
481  /* Preprocess string */
482  string = strtoul_pre ( string, &negate, &base );
483 
484  /* Process digits */
485  for ( ; ; string++ ) {
486  digit = digit_value ( *string );
487  if ( digit >= ( unsigned int ) base )
488  break;
489  value = ( ( value * base ) + digit );
490  }
491 
492  /* Negate value if, applicable */
493  if ( negate )
494  value = -value;
495 
496  /* Fill in end pointer, if applicable */
497  if ( endp )
498  *endp = ( ( char * ) string );
499 
500  return value;
501 }
unsigned int digit_value(unsigned int character)
Calculate digit value.
Definition: string.c:383
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:402
uint16_t base
Base address.
Definition: edd.h:14

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