stdlib.h File Reference

#include <stdint.h>
#include <assert.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
unsigned long strtoul (const char *p, char **endp, int base)
void *__malloc malloc (size_t size)
 Allocate memory.
void * realloc (void *old_ptr, size_t new_size)
 Reallocate memory.
void free (void *ptr)
 Free memory.
void *__malloc zalloc (size_t len)
 Allocate cleared memory.
static void *__malloc calloc (size_t nmemb, size_t size)
 Allocate cleared memory.
long int random (void)
 Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
void srandom (unsigned int seed)
 Seed the pseudo-random number generator.
static int rand (void)
static void srand (unsigned int seed)
int system (const char *command)
 Execute command line.
__asmcall int main (void)
 Main entry point.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

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

Definition at line 36 of file misc.c.

References isspace().

Referenced by aoe_parse_root_path(), bzimage_parse_cmdline(), ftp_parse_value(), http_rx_content_length(), http_rx_response(), ib_srp_parse_byte_string(), ib_srp_parse_integer(), inet_aton(), iscsi_handle_chap_c_value(), iscsi_handle_chap_i_value(), iscsi_handle_chap_r_value(), iscsi_handle_targetaddress_value(), iscsi_parse_root_path(), mac_address_from_string_specs(), parse_setting_tag(), pxebs_exec(), scsi_parse_lun(), slam_parse_multicast_address(), sleep_exec(), storef_hex(), storef_int(), tftp_process_blksize(), tftp_process_multicast(), tftp_process_tsize(), uri_decode(), and uri_port().

00036                                                                {
00037         unsigned long ret = 0;
00038         unsigned int charval;
00039 
00040         while ( isspace ( *p ) )
00041                 p++;
00042 
00043         if ( base == 0 ) {
00044                 base = 10;
00045                 if ( *p == '0' ) {
00046                         p++;
00047                         base = 8;
00048                         if ( ( *p | 0x20 ) == 'x' ) {
00049                                 p++;
00050                                 base = 16;
00051                         }
00052                 }
00053         }
00054 
00055         while ( 1 ) {
00056                 charval = *p;
00057                 if ( charval >= 'a' ) {
00058                         charval = ( charval - 'a' + 10 );
00059                 } else if ( charval >= 'A' ) {
00060                         charval = ( charval - 'A' + 10 );
00061                 } else if ( charval <= '9' ) {
00062                         charval = ( charval - '0' );
00063                 }
00064                 if ( charval >= ( unsigned int ) base )
00065                         break;
00066                 ret = ( ( ret * base ) + charval );
00067                 p++;
00068         }
00069 
00070         if ( endp )
00071                 *endp = ( char * ) p;
00072 
00073         return ( ret );
00074 }

void* __malloc malloc ( size_t  size  ) 

void* realloc ( void *  old_ptr,
size_t  new_size 
)

Reallocate memory.

Parameters:
old_ptr Memory previously allocated by malloc(), or NULL
new_size Requested size
Return values:
new_ptr Allocated memory, or NULL
Allocates memory with no particular alignment requirement. new_ptr will be aligned to at least a multiple of sizeof(void*). If old_ptr is non-NULL, then the contents of the newly allocated memory will be the same as the contents of the previously allocated memory, up to the minimum of the old and new sizes. The old memory will be freed.

If allocation fails the previously allocated block is left untouched and NULL is returned.

Calling realloc() with a new size of zero is a valid way to free a memory block.

Definition at line 253 of file malloc.c.

References alloc_memblock(), container_of, autosized_block::data, free_memblock(), memcpy, NOWHERE, NULL, offsetof, and autosized_block::size.

Referenced by bitmap_resize(), free(), line_buffer(), malloc(), more_comps(), and resize_dhcp_option().

00253                                                   {
00254         struct autosized_block *old_block;
00255         struct autosized_block *new_block;
00256         size_t old_total_size;
00257         size_t new_total_size;
00258         size_t old_size;
00259         void *new_ptr = NOWHERE;
00260 
00261         /* Allocate new memory if necessary.  If allocation fails,
00262          * return without touching the old block.
00263          */
00264         if ( new_size ) {
00265                 new_total_size = ( new_size +
00266                                    offsetof ( struct autosized_block, data ) );
00267                 new_block = alloc_memblock ( new_total_size, 1 );
00268                 if ( ! new_block )
00269                         return NULL;
00270                 new_block->size = new_total_size;
00271                 new_ptr = &new_block->data;
00272         }
00273         
00274         /* Copy across relevant part of the old data region (if any),
00275          * then free it.  Note that at this point either (a) new_ptr
00276          * is valid, or (b) new_size is 0; either way, the memcpy() is
00277          * valid.
00278          */
00279         if ( old_ptr && ( old_ptr != NOWHERE ) ) {
00280                 old_block = container_of ( old_ptr, struct autosized_block,
00281                                            data );
00282                 old_total_size = old_block->size;
00283                 old_size = ( old_total_size -
00284                              offsetof ( struct autosized_block, data ) );
00285                 memcpy ( new_ptr, old_ptr,
00286                          ( ( old_size < new_size ) ? old_size : new_size ) );
00287                 free_memblock ( old_block, old_total_size );
00288         }
00289 
00290         return new_ptr;
00291 }

void free ( void *  ptr  ) 

Free memory.

Parameters:
ptr Memory allocated by malloc(), or NULL
Memory allocated with malloc_dma() cannot be freed with free(); it must be freed with free_dma() instead.

If ptr is NULL, no action is taken.

Definition at line 316 of file malloc.c.

References realloc().

Referenced by aes_unwrap(), aes_wrap(), aoe_free(), aoeboot(), apply_iscsi_string_setting(), arbel_create_cq(), arbel_create_qp(), arbel_destroy_cq(), arbel_destroy_qp(), arbel_probe(), arbel_remove(), ath5k_desc_free(), ath5k_eeprom_free_pcal_info(), ath5k_hw_attach(), ath5k_hw_detach(), ath5k_probe(), ath5k_remove(), atl1e_free_ring_resources(), bi_mod_power(), bi_terminate(), bitmap_free(), chap_finish(), del_ipv4_miniroute(), del_ipv6_miniroute(), delwin(), dhcp_free(), dns_resolv(), downloader_free(), efi_snp_driver_start(), efi_snp_driver_stop(), eisabus_probe(), eisabus_remove(), empty_line_buffer(), expand_command(), free_fragbuf(), free_image(), free_netdev(), free_tls(), ftp_free(), generic_settings_clear(), generic_settings_store(), hermon_create_cq(), hermon_create_qp(), hermon_destroy_cq(), hermon_destroy_qp(), hermon_probe(), hermon_remove(), http_free(), ib_create_conn(), ib_create_cq(), ib_create_mi(), ib_create_path(), ib_create_qp(), ib_destroy_conn(), ib_destroy_cq(), ib_destroy_madx(), ib_destroy_mi(), ib_destroy_path(), ib_destroy_qp(), ib_mcast_attach(), ib_mcast_detach(), ib_srpboot(), image_set_cmdline(), isabus_probe(), isabus_remove(), isapnpbus_probe(), isapnpbus_remove(), iscsi_free(), iscsi_handle_targetaddress_value(), iscsi_rx_buffered_data_done(), iscsiboot(), linda_create_send_wq(), linda_destroy_send_wq(), mcabus_probe(), mcabus_remove(), mtnic_disable(), mtnic_probe(), net80211_autoassociate(), net80211_free(), net80211_free_wlan(), net80211_free_wlanlist(), net80211_mgmt_dequeue(), net80211_netdev_close(), net80211_prepare_assoc(), net80211_probe_finish_all(), net80211_probe_finish_best(), net80211_step_associate(), pcibus_probe(), pcibus_remove(), posix_file_free(), pxe_menu_boot(), rc80211_free(), ref_put(), register_nvo(), resolve_uri(), RSA_decrypt(), RSA_free(), rtl818x_probe(), rtl_close(), sec80211_install(), shell(), sis190_free_phy(), skge_free(), skge_probe(), skge_remove(), sky2_free_rings(), sky2_probe(), sky2_remove(), slam_free(), system(), t509bus_probe(), t509bus_remove(), tftp_free(), tls_clear_cipher(), tls_new_ciphertext(), tls_newdata_process_data(), tls_send_plaintext(), undipci_probe(), undipci_remove(), undirom_probe(), unregister_nvo(), vxge_hw_device_terminate(), wpa_stop(), and x509_free_rsa_public_key().

00316                         {
00317         realloc ( ptr, 0 );
00318 }

void* __malloc zalloc ( size_t  size  ) 

Allocate cleared memory.

Parameters:
size Requested size
Return values:
ptr Allocated memory
Allocate memory as per malloc(), and zero it.

This function name is non-standard, but pretty intuitive. zalloc(size) is always equivalent to calloc(1,size)

Definition at line 331 of file malloc.c.

References autosized_block::data, malloc(), and memset().

Referenced by alloc_ibdev(), alloc_image(), alloc_netdev(), aoe_attach(), aoeboot(), arbel_create_cq(), arbel_create_qp(), arbel_probe(), ath5k_hw_attach(), ath5k_probe(), atl1e_setup_ring_resources(), autovivify_child_settings(), calloc(), create_downloader(), dhcp_deliver_iob(), dns_resolv(), efi_snp_driver_start(), ftp_open(), generic_settings_store(), hermon_create_cq(), hermon_create_qp(), hermon_probe(), http_open_filter(), hw_open(), ib_cmrc_open(), ib_create_conn(), ib_create_cq(), ib_create_madx(), ib_create_mi(), ib_create_path(), ib_create_qp(), ib_mcast_attach(), ib_srpboot(), iscsi_attach(), iscsiboot(), linda_create_send_wq(), mtnic_probe(), net80211_handle_mgmt(), net80211_prepare_assoc(), net80211_probe_start(), net80211_probe_step(), net80211_step_associate(), numeric_resolv(), open(), parse_uri(), pxe_menu_parse(), rc80211_init(), resolv(), rtl818x_probe(), sec80211_install(), sis190_mii_probe(), skge_probe(), skge_ring_alloc(), sky2_probe(), sky2_up(), slam_open(), srp_attach(), start_dhcp(), start_pxebs(), store_cached_dhcpack(), tcp_open(), tftp_core_open(), udp_open_common(), undipci_probe(), undirom_probe(), vxge_hw_device_initialize(), and xfer_open_named_socket().

00331                               {
00332         void *data;
00333 
00334         data = malloc ( size );
00335         if ( data )
00336                 memset ( data, 0, size );
00337         return data;
00338 }

static void* __malloc calloc ( size_t  nmemb,
size_t  size 
) [inline, static]

Allocate cleared memory.

Parameters:
nmemb Number of members
size Size of each member
Return values:
ptr Allocated memory
Allocate memory as per malloc(), and zero it.

This is implemented as a static inline, with the body of the function in zalloc(), since in most cases nmemb will be 1 and doing the multiply is just wasteful.

Definition at line 43 of file stdlib.h.

References zalloc().

Referenced by ath5k_desc_alloc(), ath5k_eeprom_convert_pcal_info_2413(), ath5k_eeprom_convert_pcal_info_5111(), ath5k_eeprom_convert_pcal_info_5112(), bi_initialize(), RSA_pub_key_new(), and slk_init().

00043                                                                    {
00044         return zalloc ( nmemb * size );
00045 }

long int random ( void   ) 

Generate a pseudo-random number between 0 and 2147483647L or 2147483562?

Return values:
rand Pseudo-random number

Definition at line 28 of file random.c.

References currticks(), rnd_seed, and srandom().

Referenced by forcedeth_reset(), get_random_bytes(), hermon_alloc_qpn(), ib_create_conn(), ib_create_qp(), iscsi_handle_chap_c_value(), rand(), tcp_open(), tls_new_server_hello(), tls_send_client_hello(), and wep_encrypt().

00028                          {
00029         int32_t q;
00030 
00031         if ( ! rnd_seed ) /* Initialize linear congruential generator */
00032                 srandom ( currticks() );
00033 
00034         /* simplified version of the LCG given in Bruce Schneier's
00035            "Applied Cryptography" */
00036         q = ( rnd_seed / 53668 );
00037         rnd_seed = ( 40014 * ( rnd_seed - 53668 * q ) - 12211 * q );
00038         if ( rnd_seed < 0 )
00039                 rnd_seed += 2147483563L;
00040         return rnd_seed;
00041 }

void srandom ( unsigned int  seed  ) 

Seed the pseudo-random number generator.

Parameters:
seed Seed value

Definition at line 19 of file random.c.

References rnd_seed.

Referenced by random(), and srand().

00019                                    {
00020         rnd_seed = seed;
00021 }

static int rand ( void   )  [inline, static]

Definition at line 57 of file stdlib.h.

References random().

00057                                 {
00058         return random();
00059 }

static void srand ( unsigned int  seed  )  [inline, static]

Definition at line 61 of file stdlib.h.

References srandom().

00061                                                {
00062         srandom ( seed );
00063 }

int system ( const char *  command  ) 

Execute command line.

Parameters:
command Command line
Return values:
rc Command exit status
Execute the named command and arguments.

Definition at line 202 of file exec.c.

References ENOMEM, execv(), expand_command(), free(), NULL, and split_args().

Referenced by int22(), pxenv_file_exec(), script_exec(), and shell().

00202                                    {
00203         char *args;
00204         int argc;
00205         int rc = 0;
00206 
00207         /* Perform variable expansion */
00208         args = expand_command ( command );
00209         if ( ! args )
00210                 return -ENOMEM;
00211 
00212         /* Count arguments */
00213         argc = split_args ( args, NULL );
00214 
00215         /* Create argv array and execute command */
00216         if ( argc ) {
00217                 char * argv[argc + 1];
00218                 
00219                 split_args ( args, argv );
00220                 argv[argc] = NULL;
00221 
00222                 if ( argv[0][0] != '#' )
00223                         rc = execv ( argv[0], argv );
00224         }
00225 
00226         free ( args );
00227         return rc;
00228 }

__asmcall int main ( void   ) 

Main entry point.

Return values:
rc Return status code

Definition at line 35 of file main.c.

References autoboot(), BOLD, CYAN, FEATURES, for_each_image, for_each_table_entry, have_images(), image_exec(), initialise(), feature::name, NORMAL, printf(), PRODUCT_NAME, PRODUCT_SHORT_NAME, shell(), shell_banner(), shutdown(), SHUTDOWN_EXIT, shutdown_exit_flags, and startup().

Referenced by _start().

00035                             {
00036         struct feature *feature;
00037         struct image *image;
00038 
00039         /* Some devices take an unreasonably long time to initialise */
00040         printf ( PRODUCT_SHORT_NAME " initialising devices...\n" );
00041 
00042         initialise();
00043         startup();
00044 
00045         /*
00046          * Print welcome banner
00047          *
00048          *
00049          * If you wish to brand this build of gPXE, please do so by
00050          * defining the string PRODUCT_NAME in config/general.h.
00051          *
00052          * While nothing in the GPL prevents you from removing all
00053          * references to gPXE or http://etherboot.org, we prefer you
00054          * not to do so.
00055          *
00056          */
00057         printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "gPXE " VERSION
00058                  NORMAL " -- Open Source Boot Firmware -- "
00059                  CYAN "http://etherboot.org" NORMAL "\n"
00060                  "Features:" );
00061         for_each_table_entry ( feature, FEATURES )
00062                 printf ( " %s", feature->name );
00063         printf ( "\n" );
00064 
00065         /* Prompt for shell */
00066         if ( shell_banner() ) {
00067                 /* User wants shell; just give them a shell */
00068                 shell();
00069         } else {
00070                 /* User doesn't want shell; load and execute the first
00071                  * image, or autoboot() if we have no images.  If
00072                  * booting fails for any reason, offer a second chance
00073                  * to enter the shell for diagnostics.
00074                  */
00075                 if ( have_images() ) {
00076                         for_each_image ( image ) {
00077                                 image_exec ( image );
00078                                 break;
00079                         }
00080                 } else {
00081                         autoboot();
00082                 }
00083 
00084                 if ( shell_banner() )
00085                         shell();
00086         }
00087 
00088         shutdown ( SHUTDOWN_EXIT | shutdown_exit_flags );
00089 
00090         return 0;
00091 }


Generated on Tue Apr 6 20:01:53 2010 for gPXE by  doxygen 1.5.7.1