os/ossrv/genericopenlibs/openenvcore/include/stdlib.dosc
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/** @file ../include/stdlib.h
sl@0
     2
@internalComponent
sl@0
     3
*/
sl@0
     4
sl@0
     5
/** @fn  abort(void)
sl@0
     6
sl@0
     7
@return   The abort function
sl@0
     8
never returns.
sl@0
     9
sl@0
    10
  The abort function causes abnormal program termination to occur, unless the
sl@0
    11
signal SIGABRT is being caught and the signal handler does not return.
sl@0
    12
sl@0
    13
 Any open streams are flushed and closed.
sl@0
    14
sl@0
    15
Examples:
sl@0
    16
@code
sl@0
    17
#include  <stdio.h>
sl@0
    18
#include  <stdlib.h>
sl@0
    19
 
sl@0
    20
int main( void )
sl@0
    21
{
sl@0
    22
   FILE *stream;
sl@0
    23
 
sl@0
    24
   if( (stream = fopen( "notexist.file", "r" )) == NULL )
sl@0
    25
   {
sl@0
    26
      perror( "Error occurred while opening file" );
sl@0
    27
      abort();
sl@0
    28
   }
sl@0
    29
   else
sl@0
    30
      fclose( stream );
sl@0
    31
   return 0;
sl@0
    32
}
sl@0
    33
sl@0
    34
@endcode
sl@0
    35
sl@0
    36
 Output
sl@0
    37
@code
sl@0
    38
Error occurred while opening file: No such file or directory
sl@0
    39
sl@0
    40
@endcode
sl@0
    41
  
sl@0
    42
Implementation notes: 
sl@0
    43
  
sl@0
    44
  The abort function is thread-safe. It is unknown whether it is async-cancel-safe.
sl@0
    45
sl@0
    46
Limitations:
sl@0
    47
sl@0
    48
The signal related functionalities are not applicable to the Symbian OS implementation
sl@0
    49
as there is no support for signals from Symbian OS.
sl@0
    50
sl@0
    51
@see exit()
sl@0
    52
 
sl@0
    53
sl@0
    54
@publishedAll
sl@0
    55
@externallyDefinedApi
sl@0
    56
*/
sl@0
    57
sl@0
    58
/** @fn  abs(int j)
sl@0
    59
@param j
sl@0
    60
@return   The abs function
sl@0
    61
returns
sl@0
    62
the absolute value.
sl@0
    63
sl@0
    64
  The abs function computes the absolute value of an integer j. The absolute value is always postive, it has size but not direction.
sl@0
    65
sl@0
    66
sl@0
    67
sl@0
    68
Examples:
sl@0
    69
@code
sl@0
    70
#include  <stdio.h>
sl@0
    71
#include  <stdlib.h>
sl@0
    72
 
sl@0
    73
int main( void )
sl@0
    74
{
sl@0
    75
   int    ix = -4, iy;
sl@0
    76
   long   lx = -41567L, ly;
sl@0
    77
   long long llx = -5343546758, lly;
sl@0
    78
 
sl@0
    79
   iy = abs( ix );
sl@0
    80
   printf( "The absolute value of %d is %d
sl@0
    81
", ix, iy);
sl@0
    82
 
sl@0
    83
   ly = labs( lx );
sl@0
    84
   printf( "The absolute value of %ld is %ld
sl@0
    85
", lx, ly);
sl@0
    86
 
sl@0
    87
   lly = llabs( llx );
sl@0
    88
   printf( "The absolute value of %lld is %lld
sl@0
    89
", llx, lly );
sl@0
    90
 
sl@0
    91
   return 0;
sl@0
    92
}
sl@0
    93
sl@0
    94
@endcode
sl@0
    95
 
sl@0
    96
@code
sl@0
    97
Output
sl@0
    98
sl@0
    99
The absolute value of -4 is 4
sl@0
   100
The absolute value of -41567 is 41567
sl@0
   101
The absolute value of -5343546758 is 5343546758
sl@0
   102
sl@0
   103
@endcode
sl@0
   104
@see fabs()
sl@0
   105
@see floor()
sl@0
   106
@see hypot()
sl@0
   107
@see labs()
sl@0
   108
@see llabs()
sl@0
   109
@see math()
sl@0
   110
 
sl@0
   111
sl@0
   112
@publishedAll
sl@0
   113
@externallyDefinedApi
sl@0
   114
*/
sl@0
   115
sl@0
   116
/** @fn  atexit(void(*)(void) func)
sl@0
   117
@param func
sl@0
   118
@return   The atexit function returns the value 0 if successful; otherwise it returns 
sl@0
   119
the value -1 and sets the global variable errno to indicate the error.
sl@0
   120
sl@0
   121
  The atexit function
sl@0
   122
registers the given function to be called at program exit, whether via exit or via return from the program's main. Functions so registered are called in reverse order;
sl@0
   123
no arguments are passed.
sl@0
   124
sl@0
   125
 These functions must not call exit . If it is necessary to terminate the process while in such a 
sl@0
   126
  function, the _exit function should be used. Alternatively, 
sl@0
   127
  the function may cause abnormal process termination, for example by calling abort
sl@0
   128
sl@0
   129
 At least 32 functions can always be registered and more are allowed as long 
sl@0
   130
  as sufficient memory can be allocated.
sl@0
   131
sl@0
   132
In Symbian app with an entry point E32Main, the registered functions will not be called unless exit() is specified explicitly.
sl@0
   133
sl@0
   134
Limitation:
sl@0
   135
atexit() is not supported on emulator.
sl@0
   136
sl@0
   137
Examples:
sl@0
   138
@code
sl@0
   139
#include <stdlib.h>
sl@0
   140
#include <stdio.h>
sl@0
   141
 
sl@0
   142
void fun1( void ), fun2( void ), fun3( void ), fun4( void );
sl@0
   143
 
sl@0
   144
int main( void )
sl@0
   145
{
sl@0
   146
   atexit( fun1 );
sl@0
   147
   atexit( fun2 );
sl@0
   148
   atexit( fun3 );
sl@0
   149
   atexit( fun4 );
sl@0
   150
   printf( "Before exiting...." );
sl@0
   151
}
sl@0
   152
 
sl@0
   153
void fun1()
sl@0
   154
{
sl@0
   155
   printf( " fun1 " );
sl@0
   156
}
sl@0
   157
 
sl@0
   158
void fun2()
sl@0
   159
{
sl@0
   160
   printf( " fun2" );
sl@0
   161
}
sl@0
   162
 
sl@0
   163
void fun3()
sl@0
   164
{
sl@0
   165
   printf( " fun3 " );
sl@0
   166
}
sl@0
   167
 
sl@0
   168
void fun4()
sl@0
   169
{
sl@0
   170
   printf( " fun4 " );
sl@0
   171
}
sl@0
   172
sl@0
   173
@endcode
sl@0
   174
@code
sl@0
   175
Output
sl@0
   176
sl@0
   177
Before exiting...
sl@0
   178
fun4
sl@0
   179
fun3
sl@0
   180
fun2
sl@0
   181
fun1
sl@0
   182
sl@0
   183
@endcode
sl@0
   184
sl@0
   185
@code
sl@0
   186
#include <stdlib.h>
sl@0
   187
#include <stdio.h>
sl@0
   188
#include <e32base.h>
sl@0
   189
sl@0
   190
void fun1(void),fun2(void),fun3(void);
sl@0
   191
sl@0
   192
LOCAL_C int MainL()
sl@0
   193
	{
sl@0
   194
	atexit( fun1 );
sl@0
   195
   	atexit( fun2 );
sl@0
   196
   	atexit( fun3 );
sl@0
   197
    	printf( "Before exiting....\n" );
sl@0
   198
  	getchar();
sl@0
   199
	exit();
sl@0
   200
	}
sl@0
   201
sl@0
   202
sl@0
   203
void fun1()
sl@0
   204
{
sl@0
   205
printf( " fun1\n " );
sl@0
   206
getchar();
sl@0
   207
}
sl@0
   208
 
sl@0
   209
void fun2()
sl@0
   210
{
sl@0
   211
printf( " fun2\n " );
sl@0
   212
getchar();
sl@0
   213
}
sl@0
   214
 
sl@0
   215
void fun3()
sl@0
   216
{
sl@0
   217
printf( " fun3\n " );
sl@0
   218
getchar();
sl@0
   219
}
sl@0
   220
sl@0
   221
sl@0
   222
GLDEF_C TInt E32Main()
sl@0
   223
	{
sl@0
   224
	__UHEAP_MARK;
sl@0
   225
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   226
	if(cleanup == NULL)
sl@0
   227
		{
sl@0
   228
		return KErrNoMemory;
sl@0
   229
		}
sl@0
   230
	TInt ret;
sl@0
   231
	TRAPD(err,ret = MainL());
sl@0
   232
sl@0
   233
	delete cleanup;
sl@0
   234
	__UHEAP_MARKEND;
sl@0
   235
	return KErrNone;
sl@0
   236
   	}
sl@0
   237
sl@0
   238
@encode
sl@0
   239
sl@0
   240
@code
sl@0
   241
Output
sl@0
   242
sl@0
   243
Before exiting...
sl@0
   244
sl@0
   245
fun3
sl@0
   246
fun2
sl@0
   247
fun1
sl@0
   248
sl@0
   249
@endcode
sl@0
   250
sl@0
   251
@see exit()
sl@0
   252
 
sl@0
   253
sl@0
   254
@publishedAll
sl@0
   255
@externallyDefinedApi
sl@0
   256
*/
sl@0
   257
sl@0
   258
/** @fn  atof(const char *nptr)
sl@0
   259
@param nptr
sl@0
   260
@return   The atof function
sl@0
   261
returns
sl@0
   262
the converted value if the value can be represented.
sl@0
   263
sl@0
   264
  The atof function converts the initial portion of the string pointed to by nptr to double
sl@0
   265
representation.
sl@0
   266
sl@0
   267
@code
sl@0
   268
 It is equivalent to: strtod(nptr, (char **)NULL);
sl@0
   269
sl@0
   270
The decimal point
sl@0
   271
character is defined in the program's locale (category LC_NUMERIC).
sl@0
   272
@endcode
sl@0
   273
sl@0
   274
sl@0
   275
Examples:
sl@0
   276
@code
sl@0
   277
#include <stdlib.h>
sl@0
   278
#include <stdio.h>
sl@0
   279
 
sl@0
   280
void main( void )
sl@0
   281
{
sl@0
   282
 /* Test of atof */
sl@0
   283
 double d = atof("  86778E-2");
sl@0
   284
 
sl@0
   285
 printf( "result of atof: %f
sl@0
   286
", d );
sl@0
   287
}
sl@0
   288
sl@0
   289
@endcode
sl@0
   290
sl@0
   291
@code
sl@0
   292
Output
sl@0
   293
result of atof: 867.78
sl@0
   294
sl@0
   295
@endcode
sl@0
   296
sl@0
   297
Implementation notes:
sl@0
   298
  
sl@0
   299
The atof function is not thread-safe and also not async-cancel-safe. The atof function has been deprecated. Use strtod instead.
sl@0
   300
sl@0
   301
@see atoi()
sl@0
   302
@see atol()
sl@0
   303
@see strtod()
sl@0
   304
@see strtol()
sl@0
   305
@see strtoul()
sl@0
   306
 
sl@0
   307
sl@0
   308
@publishedAll
sl@0
   309
@externallyDefinedApi
sl@0
   310
*/
sl@0
   311
sl@0
   312
/** @fn  atoi(const char *nptr)
sl@0
   313
@param nptr
sl@0
   314
@return   The atoi function
sl@0
   315
returns
sl@0
   316
the converted value if the value can be represented.
sl@0
   317
sl@0
   318
  The atoi function converts the initial portion of the string pointed to by nptr to int
sl@0
   319
representation.
sl@0
   320
sl@0
   321
@code
sl@0
   322
sl@0
   323
 It is equivalent to: (int)strtol(nptr, (char **)NULL, 10);
sl@0
   324
@endocde
sl@0
   325
sl@0
   326
sl@0
   327
Examples:
sl@0
   328
@code
sl@0
   329
#include <stdlib.h>
sl@0
   330
#include <stdio.h>
sl@0
   331
 
sl@0
   332
void main( void )
sl@0
   333
{
sl@0
   334
  /* call to atoi */
sl@0
   335
  char *str = "  -56957jdhfjk";    
sl@0
   336
  int i = atoi( str );
sl@0
   337
  printf( "result of atoi: %d
sl@0
   338
", i );
sl@0
   339
}
sl@0
   340
sl@0
   341
@endcode
sl@0
   342
sl@0
   343
@code
sl@0
   344
Output
sl@0
   345
result of atoi: -56957
sl@0
   346
sl@0
   347
@endcode
sl@0
   348
sl@0
   349
Implementation notes:
sl@0
   350
  
sl@0
   351
The atoi function is not thread-safe and also not async-cancel safe. The atoi function has been deprecated. Use strtol instead.
sl@0
   352
sl@0
   353
@see atof()
sl@0
   354
@see atol()
sl@0
   355
@see strtod()
sl@0
   356
@see strtol()
sl@0
   357
@see strtoul()
sl@0
   358
 
sl@0
   359
sl@0
   360
@publishedAll
sl@0
   361
@externallyDefinedApi
sl@0
   362
*/
sl@0
   363
sl@0
   364
/** @fn  atol(const char *nptr)
sl@0
   365
@param nptr
sl@0
   366
sl@0
   367
Note: 
sl@0
   368
sl@0
   369
This description also covers the following functions -
sl@0
   370
 atoll() 
sl@0
   371
sl@0
   372
@return   The atol and atoll functions
sl@0
   373
return
sl@0
   374
the converted value if the value can be represented.
sl@0
   375
sl@0
   376
  The atol function converts the initial portion of the string pointed to by nptr to long
sl@0
   377
integer
sl@0
   378
representation.
sl@0
   379
sl@0
   380
 It is equivalent to:
sl@0
   381
sl@0
   382
@code
sl@0
   383
sl@0
   384
    strtol(nptr, (char **)NULL, 10); 
sl@0
   385
@endcode
sl@0
   386
The atoll function converts the initial portion of the string pointed to by nptr to long long
sl@0
   387
integer representation. It is equivalent to:    
sl@0
   388
@code
sl@0
   389
    strtoll(nptr, (char **)NULL, 10);
sl@0
   390
@endcode
sl@0
   391
sl@0
   392
Examples:
sl@0
   393
@code
sl@0
   394
#include <stdlib.h>
sl@0
   395
#include <stdio.h>
sl@0
   396
 
sl@0
   397
void main( void )
sl@0
   398
{
sl@0
   399
 /* call to atol */
sl@0
   400
 long l = atol( "-000002344" );
sl@0
   401
 
sl@0
   402
 printf( "result of atol: %ld
sl@0
   403
", l );
sl@0
   404
}
sl@0
   405
@endcode
sl@0
   406
sl@0
   407
@code
sl@0
   408
Output
sl@0
   409
sl@0
   410
result of atol: -2344
sl@0
   411
sl@0
   412
@endcode
sl@0
   413
@code
sl@0
   414
#include <stdlib.h>
sl@0
   415
#include <stdio.h>
sl@0
   416
 
sl@0
   417
void main( void )
sl@0
   418
{
sl@0
   419
 /* call to atoll */
sl@0
   420
 long long l = atoll("454756356bs");
sl@0
   421
 
sl@0
   422
 printf( "result of atoll: %ld
sl@0
   423
", l );
sl@0
   424
}
sl@0
   425
sl@0
   426
@endcode
sl@0
   427
sl@0
   428
@code
sl@0
   429
Output
sl@0
   430
sl@0
   431
result of atoll: 454756356
sl@0
   432
sl@0
   433
@endcode
sl@0
   434
@see atof()
sl@0
   435
@see atoi()
sl@0
   436
@see strtod()
sl@0
   437
@see strtol()
sl@0
   438
@see strtoul()
sl@0
   439
 
sl@0
   440
sl@0
   441
@publishedAll
sl@0
   442
@externallyDefinedApi
sl@0
   443
*/
sl@0
   444
sl@0
   445
/** @fn  bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *))
sl@0
   446
@param key
sl@0
   447
@param base
sl@0
   448
@param nmemb
sl@0
   449
@param size
sl@0
   450
@param compar
sl@0
   451
@return   The bsearch function returns a pointer to a matching member of the array, 
sl@0
   452
or a null pointer if no match is found. If two or more matching members are found 
sl@0
   453
the result is unspecified.
sl@0
   454
sl@0
   455
  The bsearch function searches an array of nmemb objects, the initial member of which is
sl@0
   456
pointed to by base, for a member that matches the object pointed to by key. The size of each member of the array is specified by size.
sl@0
   457
sl@0
   458
 The contents of the array should be in ascending sorted order according to 
sl@0
   459
  the comparison function referenced by compar. The compar routine is expected to have two arguments which point to the key object and to an array member, in that order. It return an integer 
sl@0
   460
  less than, equal to, or greater than zero if the key object is found, respectively, to be less than, to match, or be 
sl@0
   461
  greater than the array member.
sl@0
   462
sl@0
   463
Examples:
sl@0
   464
@code
sl@0
   465
#include<stdlib.h>
sl@0
   466
#include<stdio.h>
sl@0
   467
 
sl@0
   468
int search_function(const void* a,const void* b)
sl@0
   469
{
sl@0
   470
    return(*(int *)a - *(int *)b);
sl@0
   471
}
sl@0
   472
 
sl@0
   473
int main()
sl@0
   474
{
sl@0
   475
int arr[] = {3,5,7,8,10};
sl@0
   476
int key = 7;
sl@0
   477
int i = 5;
sl@0
   478
 
sl@0
   479
int *ele;
sl@0
   480
 
sl@0
   481
ele  = ( int* ) bsearch(&key;, (void *)arr, i, sizeof(arr[0]), search_function);
sl@0
   482
 
sl@0
   483
if (ele != NULL)
sl@0
   484
        printf("
sl@0
   485
element found: %d", *ele);
sl@0
   486
else
sl@0
   487
        printf("
sl@0
   488
element not found");
sl@0
   489
return 0;
sl@0
   490
}
sl@0
   491
sl@0
   492
@endcode
sl@0
   493
@code
sl@0
   494
Output
sl@0
   495
sl@0
   496
element found: 7
sl@0
   497
sl@0
   498
@endcode
sl@0
   499
@see qsort()
sl@0
   500
 
sl@0
   501
sl@0
   502
@publishedAll
sl@0
   503
@externallyDefinedApi
sl@0
   504
*/
sl@0
   505
sl@0
   506
/** @fn  calloc(size_t number, size_t size)
sl@0
   507
@param number
sl@0
   508
@param size
sl@0
   509
sl@0
   510
Refer to  malloc() for the documentation
sl@0
   511
@see brk()
sl@0
   512
@see mmap()
sl@0
   513
@see getpagesize()
sl@0
   514
 
sl@0
   515
sl@0
   516
@publishedAll
sl@0
   517
@externallyDefinedApi
sl@0
   518
*/
sl@0
   519
sl@0
   520
/** @fn  div(int num, int denom)
sl@0
   521
@param num
sl@0
   522
@param denom
sl@0
   523
@return   The div function
sl@0
   524
returns a structure of type div_t that contains two int
sl@0
   525
members named quot (quotient)
sl@0
   526
and rem (remainder).
sl@0
   527
sl@0
   528
  The div function
sl@0
   529
computes the value num/denom and returns the quotient and remainder in a structure named div_t that contains two int
sl@0
   530
members named quot and rem.
sl@0
   531
sl@0
   532
Examples:
sl@0
   533
@code
sl@0
   534
#include <stdlib.h>
sl@0
   535
#include <stdio.h>
sl@0
   536
 
sl@0
   537
void main( void )
sl@0
   538
{
sl@0
   539
 int numer = -14;
sl@0
   540
 int denom = -3;
sl@0
   541
 int exp_numer = 0;
sl@0
   542
    
sl@0
   543
 /* call to div */
sl@0
   544
 div_t x = div(numer, denom);
sl@0
   545
 
sl@0
   546
 printf("Result->
sl@0
   547
 Quotient = %d
sl@0
   548
 Remainder = %d
sl@0
   549
", x.quot, x.rem);
sl@0
   550
                
sl@0
   551
 exp_numer = (denom * x.quot) + x.rem;
sl@0
   552
 
sl@0
   553
 if( exp_numer == (numer) )
sl@0
   554
    printf("Result is same as the expected output");  
sl@0
   555
 else
sl@0
   556
    printf("Unexpected output");
sl@0
   557
    
sl@0
   558
 return 0; 
sl@0
   559
}
sl@0
   560
sl@0
   561
@endcode
sl@0
   562
@code
sl@0
   563
Output
sl@0
   564
sl@0
   565
Result->
sl@0
   566
Quotient = 4
sl@0
   567
Remainder = -2
sl@0
   568
Result is same as the expected output
sl@0
   569
sl@0
   570
@endcode
sl@0
   571
@see ldiv()
sl@0
   572
@see lldiv()
sl@0
   573
 
sl@0
   574
sl@0
   575
@publishedAll
sl@0
   576
@externallyDefinedApi
sl@0
   577
*/
sl@0
   578
sl@0
   579
/** @fn  exit(int status)
sl@0
   580
@param status
sl@0
   581
sl@0
   582
Note: 
sl@0
   583
sl@0
   584
This description also covers the following functions -
sl@0
   585
 _Exit() 
sl@0
   586
sl@0
   587
@return   The exit and _Exit functions
sl@0
   588
never return.
sl@0
   589
sl@0
   590
 The  exit and  _Exit functions terminate a process.
sl@0
   591
sl@0
   592
Before termination, exit performs the following functions in the order listed:
sl@0
   593
sl@0
   594
@code
sl@0
   595
sl@0
   596
   1. Call the functions registered with the atexit function, in the reverse order of their registration.
sl@0
   597
   2. Flush all open output streams.
sl@0
   598
   3. Close all open streams.
sl@0
   599
   4. Unlink all files created with the tmpfile function. 
sl@0
   600
@endcode
sl@0
   601
sl@0
   602
The _Exit function terminates without calling the functions registered with the atexit function, and may or may not perform the other actions listed. 
sl@0
   603
Both functions make the low-order eight bits of the status argument available to a parent process which has called a wait function.
sl@0
   604
sl@0
   605
The C Standard (-isoC-99) defines the values 0, EXIT_SUCCESS, and EXIT_FAILURE as possible values of status. 
sl@0
   606
Cooperating processes may use other values.
sl@0
   607
sl@0
   608
Note that exit does nothing to prevent bottomless recursion should a function registered using atexit itself call exit. 
sl@0
   609
Such functions must call _Exit instead (although this has other effects as well which may not be desired).
sl@0
   610
sl@0
   611
Examples:
sl@0
   612
@code
sl@0
   613
/* Detailed description : Sample usage of exit system call. */
sl@0
   614
#include <stdlib.h>
sl@0
   615
 
sl@0
   616
void main()
sl@0
   617
{
sl@0
   618
  exit(0) ; //Here 0 is exit status of the process
sl@0
   619
}
sl@0
   620
sl@0
   621
@endcode
sl@0
   622
@see _exit()
sl@0
   623
@see wait()
sl@0
   624
@see atexit()
sl@0
   625
@see tmpfile()
sl@0
   626
 
sl@0
   627
sl@0
   628
@publishedAll
sl@0
   629
@externallyDefinedApi
sl@0
   630
*/
sl@0
   631
sl@0
   632
/** @fn  free(void *p)
sl@0
   633
@param p
sl@0
   634
sl@0
   635
Refer to  malloc() for the documentation
sl@0
   636
@see brk()
sl@0
   637
@see mmap()
sl@0
   638
@see getpagesize()
sl@0
   639
 
sl@0
   640
sl@0
   641
@publishedAll
sl@0
   642
@externallyDefinedApi
sl@0
   643
*/
sl@0
   644
sl@0
   645
/** @fn  getenv(const char *name)
sl@0
   646
@param name
sl@0
   647
sl@0
   648
Note: 
sl@0
   649
sl@0
   650
This description also covers the following functions -
sl@0
   651
 setenv()  putenv()  unsetenv() 
sl@0
   652
sl@0
   653
@return   The getenv function returns the value of the environment variable as a NULL -terminated string. If the variable name is not in the current environment, NULL is returned. The setenv and putenv functions return the value 0 if successful; otherwise they 
sl@0
   654
  return the value -1 and set the global variable errno is set to indicate the error. The unsetenv function never returns.
sl@0
   655
sl@0
   656
These functions set, unset and fetch environment variables from the
sl@0
   657
host environment list.
sl@0
   658
For compatibility with differing environment conventions,
sl@0
   659
the given arguments name and value may be appended and prepended,
sl@0
   660
respectively,
sl@0
   661
with an equal sign "="
sl@0
   662
sl@0
   663
 The getenv function obtains the current value of the environment variable name.
sl@0
   664
sl@0
   665
 The setenv function inserts or resets the environment variable name in the current environment list.
sl@0
   666
If the variable name does not exist in the list,
sl@0
   667
it is inserted with the given value. If the variable does exist, the argument overwrite is tested; if overwrite is
sl@0
   668
zero, the
sl@0
   669
variable is not reset, otherwise it is reset
sl@0
   670
to the given value.
sl@0
   671
sl@0
   672
 The putenv function takes an argument of the form "name=value" and is
sl@0
   673
equivalent to: setenv(name, value, 1);
sl@0
   674
sl@0
   675
 The unsetenv function
sl@0
   676
deletes all instances of the variable name pointed to by name from the list.
sl@0
   677
sl@0
   678
Examples:
sl@0
   679
@code
sl@0
   680
#include <stdlib.h> //getenv
sl@0
   681
#include <stdio.h> //printf
sl@0
   682
 
sl@0
   683
int main( void )
sl@0
   684
{
sl@0
   685
  int iret = putenv("PATH=c:\sys\bin;");
sl@0
   686
 
sl@0
   687
  if( iret == -1)
sl@0
   688
     printf( "putenv() failed!!
sl@0
   689
" );
sl@0
   690
 
sl@0
   691
   /* fetch new value. */
sl@0
   692
  char *psc = getenv("PATH");
sl@0
   693
 
sl@0
   694
  if( psc != NULL )
sl@0
   695
      printf( "new PATH variable is: %s
sl@0
   696
", psc );
sl@0
   697
 
sl@0
   698
  return 0;
sl@0
   699
}
sl@0
   700
sl@0
   701
@endcode
sl@0
   702
@code
sl@0
   703
Output
sl@0
   704
sl@0
   705
new PATH variable is: c:\sys\bin;
sl@0
   706
sl@0
   707
@endcode
sl@0
   708
@code
sl@0
   709
#include <stdlib.h> //setenv, getenv
sl@0
   710
#include <stdio.h> //printf
sl@0
   711
 
sl@0
   712
int main( void )
sl@0
   713
{
sl@0
   714
   char *var;
sl@0
   715
 
sl@0
   716
   /* Unset the value of the HOME environment variable
sl@0
   717
    * to make sure that it is non-existing.
sl@0
   718
    */
sl@0
   719
   unsetenv( "HOME" );
sl@0
   720
 
sl@0
   721
   /* Set the value of HOME environment with no overwrite option */
sl@0
   722
   int iret = setenv("HOME", "/home", 0);
sl@0
   723
    
sl@0
   724
   if(iret == -1)
sl@0
   725
      printf( "Setenv failed!!" );
sl@0
   726
    
sl@0
   727
   /* Get new value. */
sl@0
   728
   var = getenv( "HOME" );
sl@0
   729
 
sl@0
   730
   if( var != NULL )
sl@0
   731
      printf( "new HOME variable is: %s
sl@0
   732
", var );
sl@0
   733
    
sl@0
   734
   /* Set the value of HOME environment with the overwrite option */
sl@0
   735
   iret = setenv("HOME", "/check", 1);
sl@0
   736
    
sl@0
   737
   /* Get new value. */
sl@0
   738
   var = getenv( "HOME" );
sl@0
   739
 
sl@0
   740
   if( var != NULL )
sl@0
   741
      printf( "new HOME variable is: %s
sl@0
   742
", var );
sl@0
   743
     
sl@0
   744
   return 0;
sl@0
   745
}
sl@0
   746
sl@0
   747
@endcode
sl@0
   748
@code
sl@0
   749
Output
sl@0
   750
sl@0
   751
new HOME variable is: \home
sl@0
   752
new HOME variable is: \check
sl@0
   753
sl@0
   754
@endcode
sl@0
   755
 
sl@0
   756
sl@0
   757
@publishedAll
sl@0
   758
@externallyDefinedApi
sl@0
   759
*/
sl@0
   760
sl@0
   761
/** @fn  labs(long j)
sl@0
   762
@param j
sl@0
   763
@return   The labs() function shall return the absolute value of the long integer operand.
sl@0
   764
sl@0
   765
 The labs function
sl@0
   766
returns the absolute value of the long integer j.
sl@0
   767
sl@0
   768
sl@0
   769
sl@0
   770
Examples:
sl@0
   771
@code
sl@0
   772
#include  <stdio.h>
sl@0
   773
#include  <stdlib.h>
sl@0
   774
 
sl@0
   775
int main( void )
sl@0
   776
{
sl@0
   777
   int    ix = -4, iy;
sl@0
   778
   long   lx = -41567L, ly;
sl@0
   779
   long long llx = -5343546758, lly;
sl@0
   780
 
sl@0
   781
   iy = abs( ix );
sl@0
   782
   printf( "The abs value of %d is %d
sl@0
   783
", ix, iy);
sl@0
   784
 
sl@0
   785
   ly = labs( lx );
sl@0
   786
   printf( "The abs value of %ld is %ld
sl@0
   787
", lx, ly);
sl@0
   788
 
sl@0
   789
   lly = llabs( llx );
sl@0
   790
   printf( "The abs value of %lld is %lld
sl@0
   791
", llx, lly );
sl@0
   792
 
sl@0
   793
   return 0;
sl@0
   794
}
sl@0
   795
sl@0
   796
@endcode
sl@0
   797
@code
sl@0
   798
Output
sl@0
   799
sl@0
   800
The absolute value of -4 is 4
sl@0
   801
The absolute value of -41567 is 41567
sl@0
   802
The absolute value of -5343546758 is 5343546758
sl@0
   803
sl@0
   804
@endcode
sl@0
   805
@see abs()
sl@0
   806
@see floor()
sl@0
   807
@see llabs()
sl@0
   808
@see math()
sl@0
   809
 
sl@0
   810
sl@0
   811
@publishedAll
sl@0
   812
@externallyDefinedApi
sl@0
   813
*/
sl@0
   814
sl@0
   815
/** @fn  ldiv(long num, long denom)
sl@0
   816
@param num
sl@0
   817
@param denom
sl@0
   818
@return   The ldiv function
sl@0
   819
returns a structure of type ldiv_t that contains two long
sl@0
   820
members named quot (quotient)
sl@0
   821
and rem (remainder).
sl@0
   822
sl@0
   823
  The ldiv function
sl@0
   824
computes the value num / denom and returns the quotient and remainder in a structure named ldiv_t
sl@0
   825
that contains two long
sl@0
   826
members named quot and rem.
sl@0
   827
sl@0
   828
Examples:
sl@0
   829
@code
sl@0
   830
#include <stdlib.h>
sl@0
   831
#include <stdio.h>
sl@0
   832
 
sl@0
   833
int main( void )
sl@0
   834
{
sl@0
   835
 long numer = 13;
sl@0
   836
 long denom = -3;
sl@0
   837
 
sl@0
   838
 /* call to ldiv */
sl@0
   839
 ldiv_t x = ldiv(numer, denom);
sl@0
   840
 
sl@0
   841
 printf("Result-> 
sl@0
   842
Quotient = %ld 
sl@0
   843
Remainder = %ld", x.quot, x.rem);
sl@0
   844
                 
sl@0
   845
 long exp_numer = (denom * x.quot) + x.rem;
sl@0
   846
  
sl@0
   847
 if( exp_numer == (numer) )
sl@0
   848
    printf("
sl@0
   849
Result is same as the expected output");  
sl@0
   850
 else
sl@0
   851
    printf("
sl@0
   852
Unexpected output");
sl@0
   853
 
sl@0
   854
 return 0;
sl@0
   855
}
sl@0
   856
sl@0
   857
@endcode
sl@0
   858
@code
sl@0
   859
Output
sl@0
   860
sl@0
   861
Result->
sl@0
   862
Quotient = 4
sl@0
   863
Remainder = -1
sl@0
   864
Result is same as the expected output
sl@0
   865
sl@0
   866
@endcode
sl@0
   867
@see div()
sl@0
   868
@see lldiv()
sl@0
   869
 
sl@0
   870
sl@0
   871
@publishedAll
sl@0
   872
@externallyDefinedApi
sl@0
   873
*/
sl@0
   874
sl@0
   875
/** @fn  malloc(size_t nbytes)
sl@0
   876
@param nbytes
sl@0
   877
sl@0
   878
Note: 
sl@0
   879
sl@0
   880
This description also covers the following functions -
sl@0
   881
 calloc()  realloc()  reallocf()  free() 
sl@0
   882
sl@0
   883
@return   The malloc and calloc functions return a pointer to the allocated memory if successful; otherwise
sl@0
   884
a NULL pointer is returned and errno is set to ENOMEM. The realloc and reallocf functions return a pointer, possibly identical to ptr, to the allocated memory if successful; otherwise a NULL pointer is returned and errno is set to ENOMEM if the error was the result of an allocation failure. The realloc function always leaves the original buffer intact when an 
sl@0
   885
  error occurs, whereas reallocf deallocates it in this case. The free function returns no value.
sl@0
   886
sl@0
   887
  The malloc function allocates nbytes of memory. The allocated space is suitably aligned (after possible 
sl@0
   888
pointer coercion) for storage of any type of object. If the space is at least pagesize bytes in length (see getpagesize ) the returned memory will be 
sl@0
   889
page boundary aligned as well. If malloc fails a NULL pointer is returned.
sl@0
   890
sl@0
   891
 Note that malloc does NOT normally initialize the returned memory to zero bytes.
sl@0
   892
sl@0
   893
 The calloc function allocates space for number of objects, each nbytes in length. The result is identical to calling malloc with an argument of "number * nbytes", with the exception that the allocated memory is explicitly 
sl@0
   894
  initialized to zero bytes.
sl@0
   895
sl@0
   896
 The realloc function changes the size of the previously allocated memory 
sl@0
   897
  referenced by ptr to nbytes. The contents of the memory are unchanged up to the lesser 
sl@0
   898
  of the new and old sizes. If the new size is larger, the value of the newly 
sl@0
   899
  allocated portion of the memory is undefined. If the requested memory cannot 
sl@0
   900
  be allocated, NULL is returned and the memory referenced by ptr is valid and unchanged. If memory can be allocated, the memory referenced 
sl@0
   901
  by ptr is freed and a pointer to the newly allocated memory is returned. 
sl@0
   902
  Note that realloc and reallocf may move the memory allocation resulting in a different return 
sl@0
   903
  value from ptr. If ptr is NULL, the realloc function behaves identically to malloc for the specified nbytes.
sl@0
   904
sl@0
   905
 The reallocf function is identical to the realloc function, except that it
sl@0
   906
will free the passed pointer when the requested memory cannot be allocated.
sl@0
   907
This is a specific API designed to ease the problems with traditional coding styles
sl@0
   908
for realloc causing memory leaks in libraries.
sl@0
   909
sl@0
   910
 The free function causes the allocated memory referenced by ptr to be made available for future allocations.
sl@0
   911
If ptr is NULL, no action occurs.
sl@0
   912
sl@0
   913
Examples:
sl@0
   914
@code
sl@0
   915
#include <stdlib.h>    //malloc
sl@0
   916
#include <stdio.h>    //printf
sl@0
   917
  
sl@0
   918
int main( void )
sl@0
   919
{
sl@0
   920
   /* allocate memory */
sl@0
   921
   char  *pc = (char *)malloc( sizeof(char) * 3);
sl@0
   922
   
sl@0
   923
   if( pc == NULL )
sl@0
   924
      printf( "memory insufficient
sl@0
   925
" );
sl@0
   926
   else
sl@0
   927
   {
sl@0
   928
      printf( "memory allocated
sl@0
   929
" );
sl@0
   930
      free( pc );
sl@0
   931
      printf( "memory freed
sl@0
   932
" );
sl@0
   933
   }
sl@0
   934
  
sl@0
   935
   return 0;
sl@0
   936
}
sl@0
   937
sl@0
   938
@endcode
sl@0
   939
@code
sl@0
   940
Output
sl@0
   941
sl@0
   942
memory allocated
sl@0
   943
memory freed
sl@0
   944
sl@0
   945
@endcode
sl@0
   946
@code
sl@0
   947
#include <stdio.h> //printf
sl@0
   948
#include <stdlib.h> //calloc
sl@0
   949
   
sl@0
   950
int main( void )
sl@0
   951
{
sl@0
   952
   int  *pint = (int *)calloc(2, sizeof (int) * 2);
sl@0
   953
   if( pint != NULL )
sl@0
   954
      printf( "allocated 2 blocks of memory, each of size -
sl@0
   955
               twice the size of an integer
sl@0
   956
" );
sl@0
   957
   else
sl@0
   958
      printf( "can't allocate memory
sl@0
   959
" );
sl@0
   960
   free( pint );
sl@0
   961
  
sl@0
   962
   return 0;
sl@0
   963
}
sl@0
   964
sl@0
   965
@endcode
sl@0
   966
@code
sl@0
   967
Output
sl@0
   968
sl@0
   969
allocated 2 blocks of memory, each of size - 2 integers
sl@0
   970
sl@0
   971
@endcode
sl@0
   972
@code
sl@0
   973
#include <stdio.h> //printf
sl@0
   974
#include <stdlib.h> //realloc
sl@0
   975
 
sl@0
   976
int main( void )
sl@0
   977
{
sl@0
   978
 int  *pint = (int *)calloc(2, sizeof (int) * 2);
sl@0
   979
 if (pint == NULL)
sl@0
   980
  {
sl@0
   981
  printf("calloc failed to allocate memory
sl@0
   982
");
sl@0
   983
  return -1;
sl@0
   984
  }
sl@0
   985
 else
sl@0
   986
  {
sl@0
   987
  printf("calloc allocated memory: 128 bytes
sl@0
   988
");
sl@0
   989
  }
sl@0
   990
 
sl@0
   991
 pint = (int *)realloc(pint, (sizeof (int) * 6) );
sl@0
   992
 if (pint == NULL)
sl@0
   993
  {
sl@0
   994
  printf("realloc failed to allocate memory
sl@0
   995
");
sl@0
   996
  return -1;
sl@0
   997
  }
sl@0
   998
 else
sl@0
   999
  {
sl@0
  1000
  printf("realloc allocated memory: 192 bytes
sl@0
  1001
");
sl@0
  1002
  }
sl@0
  1003
  
sl@0
  1004
  free( pint );
sl@0
  1005
  return 0;
sl@0
  1006
}
sl@0
  1007
sl@0
  1008
@endcode
sl@0
  1009
@code
sl@0
  1010
Output
sl@0
  1011
sl@0
  1012
calloc allocated memory: 128 bytes
sl@0
  1013
realloc allocated memory: 192 bytes
sl@0
  1014
sl@0
  1015
@endcode
sl@0
  1016
@see brk()
sl@0
  1017
@see mmap()
sl@0
  1018
@see getpagesize()
sl@0
  1019
 
sl@0
  1020
sl@0
  1021
@publishedAll
sl@0
  1022
@externallyDefinedApi
sl@0
  1023
*/
sl@0
  1024
sl@0
  1025
/** @fn  mblen(const char *s, size_t n)
sl@0
  1026
@param s
sl@0
  1027
@param n
sl@0
  1028
@return   If s is a null pointer, mblen returns non-zero 0 value depending upon the current locale (see 
sl@0
  1029
  below). If s is not a null pointer, mblen returns : 0 (if mbchar points to the null byte), the number of bytes that constitute the character (if the next n or fewer bytes form a valid character), or -1 (if they do not form a valid character) and may set errno to indicate the error. In no case is the value returned greater than n or the value of the {MB_CUR_MAX} macro.
sl@0
  1030
sl@0
  1031
  The mblen function computes the length in bytes
sl@0
  1032
of a multibyte character s according to the current conversion state.
sl@0
  1033
Up to n bytes are examined.
sl@0
  1034
sl@0
  1035
 A call with a null s pointer returns nonzero if the current locale requires shift states,
sl@0
  1036
zero otherwise;
sl@0
  1037
if shift states are required, the shift state is reset to the initial state.
sl@0
  1038
sl@0
  1039
 The behavior of the mblen is affected by LC_CTYPE category of the current locale.
sl@0
  1040
sl@0
  1041
Examples:
sl@0
  1042
@code
sl@0
  1043
#include <stdlib.h>
sl@0
  1044
#include <wchar.h>
sl@0
  1045
/* Illustrates how to use mblen API */
sl@0
  1046
int example_mblen(wchar_t wc)
sl@0
  1047
{
sl@0
  1048
 int len;
sl@0
  1049
 
sl@0
  1050
 /* determine the number bytes in the multibyte char */
sl@0
  1051
 len = mblen(wc, MB_CUR_MAX);
sl@0
  1052
 if(len == -1)
sl@0
  1053
 {
sl@0
  1054
        wprintf(L"mblen returned error!!
sl@0
  1055
");
sl@0
  1056
 }
sl@0
  1057
 /* return the no of bytes */
sl@0
  1058
 return(len);
sl@0
  1059
}
sl@0
  1060
sl@0
  1061
@endcode
sl@0
  1062
sl@0
  1063
Limitations:   
sl@0
  1064
sl@0
  1065
The current implementation of mblen is not affected by the LC_CTYPE category of the current locale.
sl@0
  1066
It works only for UTF8 character set.
sl@0
  1067
sl@0
  1068
@see mbrlen()
sl@0
  1069
@see mbtowc()
sl@0
  1070
 
sl@0
  1071
sl@0
  1072
@publishedAll
sl@0
  1073
@externallyDefinedApi
sl@0
  1074
*/
sl@0
  1075
sl@0
  1076
/** @fn  mbstowcs(wchar_t *  pwcs, const char *  s, size_t n)
sl@0
  1077
@param pwcs
sl@0
  1078
@param s
sl@0
  1079
@param n
sl@0
  1080
@return   The mbstowcs function returns the number of wide characters converted,
sl@0
  1081
not counting any terminating null wide character, or -1
sl@0
  1082
if an invalid multibyte character was encountered.
sl@0
  1083
sl@0
  1084
  The mbstowcs function converts a multibyte character string mbstring beginning in the initial conversion state
sl@0
  1085
into a wide character string wcstring. No more than n wide characters are stored.
sl@0
  1086
A terminating null wide character is appended if there is room.
sl@0
  1087
sl@0
  1088
 The behavior of the mbstowcs is affected by LC_CTYPE category of the current locale.
sl@0
  1089
sl@0
  1090
sl@0
  1091
sl@0
  1092
Examples:
sl@0
  1093
@code
sl@0
  1094
#include <stdio.h>
sl@0
  1095
#include <stdlib.h>
sl@0
  1096
#include <wchar.h>
sl@0
  1097
/* Illustrates how to use mbstowcs API */
sl@0
  1098
size_t example_mbstowcs(wchar_t *wc, char *s, size_t n)
sl@0
  1099
{
sl@0
  1100
 size_t len;
sl@0
  1101
 /* converting multibyte string to a wide-char string */
sl@0
  1102
 len = mbstowcs(wc, s, n);
sl@0
  1103
 /* checking for error */
sl@0
  1104
 if(len < 0)
sl@0
  1105
 {
sl@0
  1106
        wprintf(L"mbstowcs returned error!!
sl@0
  1107
");
sl@0
  1108
 }
sl@0
  1109
 /* returning no of bytes consumed */
sl@0
  1110
 return (len);
sl@0
  1111
}
sl@0
  1112
sl@0
  1113
@endcode
sl@0
  1114
sl@0
  1115
Limitations:   
sl@0
  1116
sl@0
  1117
The current implementation of mbstowcs is not affected by the LC_CTYPE category of the current locale.
sl@0
  1118
It works only for UTF8 character set.
sl@0
  1119
sl@0
  1120
@see mbsrtowcs()
sl@0
  1121
@see mbtowc()
sl@0
  1122
 
sl@0
  1123
sl@0
  1124
@publishedAll
sl@0
  1125
@externallyDefinedApi
sl@0
  1126
*/
sl@0
  1127
sl@0
  1128
/** @fn  mbtowc(wchar_t * pwc, const char *  s, size_t n)
sl@0
  1129
@param pwc
sl@0
  1130
@param s
sl@0
  1131
@param n
sl@0
  1132
@return   If mbchar is NULL, the mbtowc function returns nonzero if shift states are supported,
sl@0
  1133
zero otherwise. Otherwise, if mbchar is not a null pointer, mbtowc either returns 0 if mbchar represents the null wide character, or returns
sl@0
  1134
the number of bytes processed in mbchar, or returns -1 if no multibyte character
sl@0
  1135
could be recognized or converted.
sl@0
  1136
In this case, mbtowc internal conversion state is undefined.
sl@0
  1137
sl@0
  1138
  The mbtowc function converts a multibyte character mbchar into a wide character according to the current conversion state,
sl@0
  1139
and stores the result in the object pointed to by wcharp. Up to n bytes are examined.
sl@0
  1140
sl@0
  1141
 A call with a null mbchar pointer returns nonzero if the current encoding requires shift 
sl@0
  1142
  states, zero otherwise. If shift states are required the shift state is reset 
sl@0
  1143
  to the initial state.
sl@0
  1144
sl@0
  1145
 The behavior of the mbtowc is affected by LC_CTYPE category of the current locale.
sl@0
  1146
sl@0
  1147
sl@0
  1148
sl@0
  1149
Examples:
sl@0
  1150
@code
sl@0
  1151
#include <stdlib.h>
sl@0
  1152
#include <wchar.h>
sl@0
  1153
/* Illustrates how to use mbtowc API */
sl@0
  1154
int example_mbtowc(wchar_t *wc, char *s)
sl@0
  1155
{
sl@0
  1156
 int len;
sl@0
  1157
 /* converting multibyte sequence to a wide-character */
sl@0
  1158
 len = mbtowc(wc, s, MB_CUR_MAX);
sl@0
  1159
 /* checking for error */
sl@0
  1160
 if(len < 0)
sl@0
  1161
 {
sl@0
  1162
        wprintf(L"mbtowc returned error!!
sl@0
  1163
");
sl@0
  1164
 }
sl@0
  1165
 /* returning no of bytes consumed */
sl@0
  1166
 return (len;);
sl@0
  1167
}
sl@0
  1168
sl@0
  1169
@endcode
sl@0
  1170
sl@0
  1171
Limitations:
sl@0
  1172
sl@0
  1173
The current implementation of mbtowc is not affected by the LC_CTYPE category of the current locale.
sl@0
  1174
It works only for UTF8 character set.
sl@0
  1175
sl@0
  1176
@see btowc()
sl@0
  1177
@see mblen()
sl@0
  1178
@see mbrtowc()
sl@0
  1179
@see mbstowcs()
sl@0
  1180
@see wctomb()
sl@0
  1181
 
sl@0
  1182
sl@0
  1183
@publishedAll
sl@0
  1184
@externallyDefinedApi
sl@0
  1185
*/
sl@0
  1186
sl@0
  1187
/** @fn  qsort(void *, size_t, size_t, int(*)(const void *, const void *))
sl@0
  1188
sl@0
  1189
@return   The qsort function
sl@0
  1190
returns no value.
sl@0
  1191
sl@0
  1192
  The qsort function is a modified partition-exchange sort, or quicksort.
sl@0
  1193
sl@0
  1194
 The qsort function sorts an array of nmemb objects, the initial member of which is pointed to by base. The size of each object is specified by size.
sl@0
  1195
sl@0
  1196
 The contents of the array base are sorted in ascending order according to
sl@0
  1197
a comparison function pointed to by compar, which requires two arguments pointing to the objects being
sl@0
  1198
compared.
sl@0
  1199
sl@0
  1200
 The comparison function must return an integer less than, equal to, or
sl@0
  1201
greater than zero if the first argument is considered to be respectively
sl@0
  1202
less than, equal to, or greater than the second.
sl@0
  1203
sl@0
  1204
 The algorithm implemented by qsort is not stable, that is, if two members compare as equal, their order in
sl@0
  1205
the sorted array is undefined.
sl@0
  1206
sl@0
  1207
 The qsort function is an implementation of C.A.R.
sl@0
  1208
Hoare's "quicksort"
sl@0
  1209
algorithm,
sl@0
  1210
a variant of partition-exchange sorting; in particular, see D.E. Knuth Ns's Algorithm Q . Quicksort takes O N lg N average time.
sl@0
  1211
sl@0
  1212
@code
sl@0
  1213
sl@0
  1214
This implementation uses median selection to avoid its O N**2 worst-case behavior.
sl@0
  1215
@endcode
sl@0
  1216
sl@0
  1217
Examples:
sl@0
  1218
@code
sl@0
  1219
#include <stdio.h>
sl@0
  1220
#include <stdlib.h>
sl@0
  1221
int sort_function( const void *a, const void *b);
sl@0
  1222
 
sl@0
  1223
int main(void)
sl@0
  1224
{
sl@0
  1225
   int  x;
sl@0
  1226
   int list[5] = {4,2,3,5,1};
sl@0
  1227
   qsort((void *)list, 5, sizeof(list[0]), sort_function);
sl@0
  1228
   for (x = 0; x < 5; x++)
sl@0
  1229
   printf("%d
sl@0
  1230
", list[x]);
sl@0
  1231
  
sl@0
  1232
   return 0;
sl@0
  1233
}
sl@0
  1234
int sort_function( const void *a, const void *b)
sl@0
  1235
{
sl@0
  1236
 int *p1 = (int *)a;
sl@0
  1237
 int val1 = *p1;
sl@0
  1238
 int *p2 = (int *)b;
sl@0
  1239
 int val2 = *p2;
sl@0
  1240
 int x = -1;
sl@0
  1241
 if(val1  > val2 )
sl@0
  1242
   x=1;
sl@0
  1243
 if(val1  == val2 )
sl@0
  1244
   x=0; 
sl@0
  1245
 
sl@0
  1246
 return x;
sl@0
  1247
}
sl@0
  1248
sl@0
  1249
@endcode
sl@0
  1250
@code
sl@0
  1251
Output
sl@0
  1252
sl@0
  1253
1
sl@0
  1254
2
sl@0
  1255
3
sl@0
  1256
4
sl@0
  1257
5
sl@0
  1258
sl@0
  1259
@endcode
sl@0
  1260
 
sl@0
  1261
sl@0
  1262
@publishedAll
sl@0
  1263
@externallyDefinedApi
sl@0
  1264
*/
sl@0
  1265
sl@0
  1266
/** @fn  rand(void)
sl@0
  1267
sl@0
  1268
sl@0
  1269
Refer to  srand() for the documentation
sl@0
  1270
sl@0
  1271
sl@0
  1272
 
sl@0
  1273
sl@0
  1274
@publishedAll
sl@0
  1275
@externallyDefinedApi
sl@0
  1276
*/
sl@0
  1277
sl@0
  1278
/** @fn  realloc(void *p, size_t nbytes)
sl@0
  1279
@param p
sl@0
  1280
@param nbytes
sl@0
  1281
sl@0
  1282
Refer to  malloc() for the documentation
sl@0
  1283
@see brk()
sl@0
  1284
@see mmap()
sl@0
  1285
@see getpagesize()
sl@0
  1286
 
sl@0
  1287
sl@0
  1288
@publishedAll
sl@0
  1289
@externallyDefinedApi
sl@0
  1290
*/
sl@0
  1291
sl@0
  1292
/** @fn  srand(unsigned seed)
sl@0
  1293
@param seed
sl@0
  1294
sl@0
  1295
Note: 
sl@0
  1296
sl@0
  1297
This description also covers the following functions -
sl@0
  1298
 rand() 
sl@0
  1299
sl@0
  1300
@return   The rand function
sl@0
  1301
never returns return the next pseudo-random number in the sequence. The srand function never returns.
sl@0
  1302
sl@0
  1303
  The rand function computes a sequence of pseudo-random integers in the range
sl@0
  1304
of 0 to RAND_MAX (as defined by the header file \#include \<stdlib.h\> ).
sl@0
  1305
sl@0
  1306
 The srand function sets its argument seed as the seed for a new sequence of
sl@0
  1307
pseudo-random numbers to be returned by rand. These sequences are repeatable by calling srand with the same seed value.
sl@0
  1308
sl@0
  1309
 If no seed value is provided, the functions are automatically
sl@0
  1310
seeded with a value of 1.
sl@0
  1311
sl@0
  1312
sl@0
  1313
sl@0
  1314
Examples:
sl@0
  1315
@code
sl@0
  1316
#include <stdlib.h>
sl@0
  1317
#include <stdio.h>
sl@0
  1318
 
sl@0
  1319
int main( void )
sl@0
  1320
{
sl@0
  1321
  int randArray[20];
sl@0
  1322
  int i=0;
sl@0
  1323
    
sl@0
  1324
  while(i<20)
sl@0
  1325
  {
sl@0
  1326
        randArray[i]=rand();
sl@0
  1327
        printf("
sl@0
  1328
%d", randArray[i]);
sl@0
  1329
        i++;
sl@0
  1330
  }
sl@0
  1331
 
sl@0
  1332
  return 0;
sl@0
  1333
}
sl@0
  1334
sl@0
  1335
@endcode
sl@0
  1336
@code
sl@0
  1337
Output
sl@0
  1338
sl@0
  1339
16807
sl@0
  1340
282475249
sl@0
  1341
1622650073
sl@0
  1342
984943658
sl@0
  1343
1144108930
sl@0
  1344
470211272
sl@0
  1345
101027544
sl@0
  1346
1457850878
sl@0
  1347
1458777923
sl@0
  1348
2007237709
sl@0
  1349
823564440
sl@0
  1350
1115438165
sl@0
  1351
1784484492
sl@0
  1352
74243042
sl@0
  1353
114807987
sl@0
  1354
1137522503
sl@0
  1355
1441282327
sl@0
  1356
16531729
sl@0
  1357
823378840
sl@0
  1358
143542612
sl@0
  1359
sl@0
  1360
@endcode
sl@0
  1361
@code
sl@0
  1362
#include <stdlib.h>
sl@0
  1363
#include <stdio.h>
sl@0
  1364
int main( void )
sl@0
  1365
{
sl@0
  1366
 int seedVal = 45454652;
sl@0
  1367
 int randVal;
sl@0
  1368
 srand(seedVal);
sl@0
  1369
 randVal=rand();
sl@0
  1370
 printf("Random Value returned is %d"), randVal);
sl@0
  1371
}
sl@0
  1372
sl@0
  1373
@endcode
sl@0
  1374
@code
sl@0
  1375
Output
sl@0
  1376
sl@0
  1377
Random Value returned is 1599641479
sl@0
  1378
sl@0
  1379
@endcode
sl@0
  1380
 
sl@0
  1381
sl@0
  1382
@publishedAll
sl@0
  1383
@externallyDefinedApi
sl@0
  1384
*/
sl@0
  1385
sl@0
  1386
/** @fn  strtod(const char *  s, char **  tail)
sl@0
  1387
@param s
sl@0
  1388
@param tail
sl@0
  1389
sl@0
  1390
Note: 
sl@0
  1391
sl@0
  1392
This description also covers the following functions -
sl@0
  1393
 strtof()  strtold() 
sl@0
  1394
sl@0
  1395
@return   The strtod , strtof ,
sl@0
  1396
and strtold functions return the converted value, if any. If endptr is not NULL ,
sl@0
  1397
a pointer to the character after the last character used
sl@0
  1398
in the conversion is stored in the location referenced by endptr . If no conversion is performed, zero is returned and the value of nptr is stored in the location referenced by endptr . If the correct value would cause overflow, plus or minus HUGE_VAL , HUGE_VALF , or HUGE_VALL is returned (according to the sign and type of the return 
sl@0
  1399
  value), and ERANGE is stored in errno . If the correct value would cause underflow a value, of the appropriate 
sl@0
  1400
  type, with magnitude is no greater than the smallest normalized positive number 
sl@0
  1401
  (KMinTReal in case of Symbian OS) is returned and ERANGE is stored in errno .
sl@0
  1402
sl@0
  1403
  These conversion functions convert the initial portion of the string pointed to by  nptr to double , float , and long double representation, respectively.
sl@0
  1404
sl@0
  1405
The expected form of the string is an optional plus ("+") or minus sign ("-") followed by either:
sl@0
  1406
sl@0
  1407
@code
sl@0
  1408
sl@0
  1409
    * a decimal significand consisting of a sequence of decimal digits optionally containing a decimal-point character, or
sl@0
  1410
    * a hexadecimal significand consisting of a "0X" or "0x" followed by a sequence of hexadecimal digits optionally containing a decimal-point character. 
sl@0
  1411
@endcode
sl@0
  1412
sl@0
  1413
In both cases, the significand may be optionally followed by an exponent. An exponent consists of an "E" or "e" (for decimal constants) or a "P" or 
sl@0
  1414
"p" (for hexadecimal constants), followed by an optional plus or minus sign, followed by a sequence of decimal digits. 
sl@0
  1415
For decimal constants, the exponent indicates the power of 10 by which the significand should be scaled. For hexadecimal constants, the scaling is instead done by powers of 2.
sl@0
  1416
sl@0
  1417
Alternatively, if the portion of the string following the optional plus or minus sign begins with "INFINITY" or "NAN", ignoring case, it is interpreted as an infinity or a quiet NaN, respectively.
sl@0
  1418
sl@0
  1419
In any of the above cases, leading white-space characters in the string (as defined by the isspace function) are skipped. The decimal point character is defined in the program's locale (category LC_NUMERIC).
sl@0
  1420
sl@0
  1421
Examples:
sl@0
  1422
@code
sl@0
  1423
#include <stdlib.h>
sl@0
  1424
#include <stdio.h>
sl@0
  1425
 
sl@0
  1426
int main( void )
sl@0
  1427
{
sl@0
  1428
 char *endpt = NULL;
sl@0
  1429
 double d = 0.0;
sl@0
  1430
  
sl@0
  1431
 d = strtod("0x00e123bhduitri", &endpt;);
sl@0
  1432
  
sl@0
  1433
 printf("{Expected: 922171.0} %f
sl@0
  1434
", d);
sl@0
  1435
 printf("{Expected: \"hduitri\"} %s
sl@0
  1436
", endpt);
sl@0
  1437
  
sl@0
  1438
 return 0;
sl@0
  1439
}
sl@0
  1440
sl@0
  1441
@endcode
sl@0
  1442
 Output
sl@0
  1443
@code
sl@0
  1444
{Expected: 922171.0} 922171.0
sl@0
  1445
{Expected: "hduitri"} hduitri
sl@0
  1446
sl@0
  1447
@endcode
sl@0
  1448
sl@0
  1449
Limitations:
sl@0
  1450
sl@0
  1451
All these functions don't support the long double length modifiers.
sl@0
  1452
sl@0
  1453
@see atof()
sl@0
  1454
@see atoi()
sl@0
  1455
@see atol()
sl@0
  1456
@see strtol()
sl@0
  1457
@see strtoul()
sl@0
  1458
@see wcstod()
sl@0
  1459
 
sl@0
  1460
sl@0
  1461
@publishedAll
sl@0
  1462
@externallyDefinedApi
sl@0
  1463
*/
sl@0
  1464
sl@0
  1465
/** @fn  strtof(const char *  s, char **  tail)
sl@0
  1466
@param s
sl@0
  1467
@param tail
sl@0
  1468
sl@0
  1469
Refer to  strtod() for the documentation
sl@0
  1470
@see atof()
sl@0
  1471
@see atoi()
sl@0
  1472
@see atol()
sl@0
  1473
@see strtol()
sl@0
  1474
@see strtoul()
sl@0
  1475
@see wcstod()
sl@0
  1476
 
sl@0
  1477
sl@0
  1478
@publishedAll
sl@0
  1479
@externallyDefinedApi
sl@0
  1480
*/
sl@0
  1481
sl@0
  1482
/** @fn  strtol(const char *  nptr, char **  endptr, int base)
sl@0
  1483
@param nptr
sl@0
  1484
@param endptr
sl@0
  1485
@param base
sl@0
  1486
sl@0
  1487
Note: 
sl@0
  1488
sl@0
  1489
This description also covers the following functions -
sl@0
  1490
 strtoll()  strtoimax()  strtoq() 
sl@0
  1491
sl@0
  1492
@return   The strtol , strtoll , strtoimax and strtoq functions return the result of the conversion, unless the value 
sl@0
  1493
  would underflow or overflow. If no conversion could be performed, 0 is returned 
sl@0
  1494
  and the global variable errno is set to EINVAL (the last feature is not portable across all platforms). If 
sl@0
  1495
  an overflow or underflow occurs, errno is set to ERANGE and the function return value is clamped according to the following 
sl@0
  1496
  table:
sl@0
  1497
sl@0
  1498
 @code
sl@0
  1499
sl@0
  1500
  Function	underflow	overflow 
sl@0
  1501
sl@0
  1502
  strtol        LONG_MIN	LONG_MAX 
sl@0
  1503
  strtoll	LLONG_MIN	LLONG_MAX 
sl@0
  1504
  strtoimax	INTMAX_MIN	INTMAX_MAX 
sl@0
  1505
  strtoq	LLONG_MIN	LLONG_MAX
sl@0
  1506
@endcode
sl@0
  1507
sl@0
  1508
  The strtol function
sl@0
  1509
converts the string in nptr to a long
sl@0
  1510
value.
sl@0
  1511
The strtoll function
sl@0
  1512
converts the string in nptr to a long long
sl@0
  1513
value.
sl@0
  1514
The strtoimax function
sl@0
  1515
converts the string in nptr to an intmax_t
sl@0
  1516
value.
sl@0
  1517
The strtoq function
sl@0
  1518
converts the string in nptr to a quad_t
sl@0
  1519
value.
sl@0
  1520
The conversion is done according to the given base ,
sl@0
  1521
which must be between 2 and 36 inclusive,
sl@0
  1522
or be the special value 0.
sl@0
  1523
sl@0
  1524
 The string may begin with an arbitrary amount of white space
sl@0
  1525
(as determined by isspace )
sl@0
  1526
followed by a single optional "+"
sl@0
  1527
or "-"
sl@0
  1528
sign.
sl@0
  1529
If base is zero or 16,
sl@0
  1530
the string may then include a "0x"
sl@0
  1531
prefix,
sl@0
  1532
and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is "0",
sl@0
  1533
in which case it is taken as 8 (octal).
sl@0
  1534
sl@0
  1535
 The remainder of the string is converted to a long , long long , intmax_t
sl@0
  1536
or quad_t
sl@0
  1537
value in the obvious manner,
sl@0
  1538
stopping at the first character which is not a valid digit
sl@0
  1539
in the given base.
sl@0
  1540
(In bases above 10, the letter "A"
sl@0
  1541
in either upper or lower case
sl@0
  1542
represents 10, "B"
sl@0
  1543
represents 11, and so forth, with "Z"
sl@0
  1544
representing 35.)
sl@0
  1545
sl@0
  1546
 If endptr is not NULL , strtol stores the address of the first invalid character in *endptr .
sl@0
  1547
If there were no digits at all, however, strtol stores the original value of nptr in *endptr .
sl@0
  1548
(Thus, if *nptr is not "\\0"
sl@0
  1549
but **endptr is "\\0"
sl@0
  1550
on return, the entire string was valid.)
sl@0
  1551
sl@0
  1552
Examples:
sl@0
  1553
@code
sl@0
  1554
#include <stdlib.h>
sl@0
  1555
#include <stdio.h>
sl@0
  1556
  
sl@0
  1557
int main( void )
sl@0
  1558
{
sl@0
  1559
 char *endpt = NULL;
sl@0
  1560
 long l = 0;
sl@0
  1561
  
sl@0
  1562
 l = strtol("0x1236nvbi", &endpt;, 0);
sl@0
  1563
  
sl@0
  1564
 printf("{Expected: 4662} %ld
sl@0
  1565
", l);
sl@0
  1566
 printf("{Expected: \"nvbi\"} %s
sl@0
  1567
", endpt);
sl@0
  1568
  
sl@0
  1569
 return 0;
sl@0
  1570
}
sl@0
  1571
sl@0
  1572
@endcode
sl@0
  1573
@code
sl@0
  1574
Output
sl@0
  1575
sl@0
  1576
{Expected: 4662} 4662
sl@0
  1577
{Expected: "nvbi"} nvbi
sl@0
  1578
sl@0
  1579
@endcode
sl@0
  1580
@see atof()
sl@0
  1581
@see atoi()
sl@0
  1582
@see atol()
sl@0
  1583
@see strtod()
sl@0
  1584
@see strtoul()
sl@0
  1585
@see wcstol()
sl@0
  1586
 
sl@0
  1587
sl@0
  1588
@publishedAll
sl@0
  1589
@externallyDefinedApi
sl@0
  1590
*/
sl@0
  1591
sl@0
  1592
/** @fn  strtold(const char *s, char **sp)
sl@0
  1593
@param s
sl@0
  1594
@param sp
sl@0
  1595
sl@0
  1596
Refer to  strtod() for the documentation
sl@0
  1597
@see atof()
sl@0
  1598
@see atoi()
sl@0
  1599
@see atol()
sl@0
  1600
@see strtol()
sl@0
  1601
@see strtoul()
sl@0
  1602
@see wcstod()
sl@0
  1603
 
sl@0
  1604
sl@0
  1605
@publishedAll
sl@0
  1606
@externallyDefinedApi
sl@0
  1607
*/
sl@0
  1608
sl@0
  1609
/** @fn  strtoul(const char *  nptr, char **  endptr, int base)
sl@0
  1610
@param nptr
sl@0
  1611
@param endptr
sl@0
  1612
@param base
sl@0
  1613
sl@0
  1614
Note: 
sl@0
  1615
sl@0
  1616
This description also covers the following functions -
sl@0
  1617
 strtoull()  strtoumax()  strtouq() 
sl@0
  1618
sl@0
  1619
@return   The strtoul , strtoull , strtoumax and strtouq functions
sl@0
  1620
return either the result of the conversion
sl@0
  1621
or, if there was a leading minus sign,
sl@0
  1622
the negation of the result of the conversion,
sl@0
  1623
unless the original (non-negated) value would overflow;
sl@0
  1624
in the latter case, strtoul returns ULONG_MAX , strtoull returns ULLONG_MAX , strtoumax returns UINTMAX_MAX ,
sl@0
  1625
and strtouq returns ULLONG_MAX .
sl@0
  1626
In all cases, errno is set to ERANGE .
sl@0
  1627
If no conversion could be performed, 0 is returned and
sl@0
  1628
the global variable errno is set to EINVAL (the last feature is not portable across all platforms).
sl@0
  1629
sl@0
  1630
  The strtoul function
sl@0
  1631
converts the string in nptr to an unsigned long
sl@0
  1632
value.
sl@0
  1633
The strtoull function
sl@0
  1634
converts the string in nptr to an unsigned long long
sl@0
  1635
value.
sl@0
  1636
The strtoumax function
sl@0
  1637
converts the string in nptr to an uintmax_t
sl@0
  1638
value.
sl@0
  1639
The strtouq function
sl@0
  1640
converts the string in nptr to a u_quad_t
sl@0
  1641
value.
sl@0
  1642
The conversion is done according to the given base ,
sl@0
  1643
which must be between 2 and 36 inclusive,
sl@0
  1644
or be the special value 0.
sl@0
  1645
sl@0
  1646
 The string may begin with an arbitrary amount of white space
sl@0
  1647
(as determined by isspace )
sl@0
  1648
followed by a single optional "+"
sl@0
  1649
or "-"
sl@0
  1650
sign.
sl@0
  1651
If base is zero or 16,
sl@0
  1652
the string may then include a "0x"
sl@0
  1653
prefix,
sl@0
  1654
and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is 'o',
sl@0
  1655
in which case it is taken as 8 (octal).
sl@0
  1656
sl@0
  1657
 The remainder of the string is converted to an unsigned long
sl@0
  1658
value in the obvious manner,
sl@0
  1659
stopping at the end of the string
sl@0
  1660
or at the first character that does not produce a valid digit
sl@0
  1661
in the given base.
sl@0
  1662
(In bases above 10, the letter "A"
sl@0
  1663
in either upper or lower case
sl@0
  1664
represents 10, "B"
sl@0
  1665
represents 11, and so forth, with "Z"
sl@0
  1666
representing 35.)
sl@0
  1667
sl@0
  1668
 If endptr is not NULL , strtoul stores the address of the first invalid character in *endptr .
sl@0
  1669
If there were no digits at all, however, strtoul stores the original value of nptr in *endptr .
sl@0
  1670
(Thus, if *nptr is not "\\0"
sl@0
  1671
but **endptr is "\\0"
sl@0
  1672
on return, the entire string was valid.)
sl@0
  1673
sl@0
  1674
Examples:
sl@0
  1675
@code
sl@0
  1676
#include <stdlib.h>
sl@0
  1677
#include <stdio.h>
sl@0
  1678
 
sl@0
  1679
int main( void )
sl@0
  1680
{
sl@0
  1681
 char *endpt = NULL;
sl@0
  1682
 unsigned long ul = 0;
sl@0
  1683
  
sl@0
  1684
 ul = strtoul("435435hmnb", &endpt;, 12);
sl@0
  1685
  
sl@0
  1686
 printf("{Expected: 1066793} %ld
sl@0
  1687
", ul);
sl@0
  1688
 printf("{Expected: \"hmnb\"} %s
sl@0
  1689
", endpt);
sl@0
  1690
  
sl@0
  1691
 return 0;
sl@0
  1692
}
sl@0
  1693
sl@0
  1694
@endcode
sl@0
  1695
@code
sl@0
  1696
Output
sl@0
  1697
sl@0
  1698
{Expected: 1066793} 1066793
sl@0
  1699
{Expected: "hmnb"} hmnb
sl@0
  1700
sl@0
  1701
@endcode
sl@0
  1702
@see strtol()
sl@0
  1703
@see wcstoul()
sl@0
  1704
 
sl@0
  1705
sl@0
  1706
@publishedAll
sl@0
  1707
@externallyDefinedApi
sl@0
  1708
*/
sl@0
  1709
sl@0
  1710
/** @fn  system(const char *cmd)
sl@0
  1711
@param cmd
sl@0
  1712
@return   The system function returns the exit status of the child process as returned by process exit reason or -1 if an error occurred when spawning a new process. It returns a non-zero value when NULL is passed as its argument.
sl@0
  1713
sl@0
  1714
  The system function
sl@0
  1715
spawns another process with the argument cmd. The calling process waits for the child process
sl@0
  1716
to finish executing.
sl@0
  1717
sl@0
  1718
 If cmd is a NULL pointer, system will return non-zero to indicate that system is suporrted
sl@0
  1719
and zero if it is not supported.
sl@0
  1720
sl@0
  1721
 The system function
sl@0
  1722
returns the exit status of the child process as returned by
sl@0
  1723
process' exit reason
sl@0
  1724
or -1 if an error occurred when spawning a new process.
sl@0
  1725
sl@0
  1726
Examples:
sl@0
  1727
@code
sl@0
  1728
#include <stdlib.h> //system
sl@0
  1729
#include <stdio.h> //printf
sl@0
  1730
 
sl@0
  1731
int main( void )
sl@0
  1732
{
sl@0
  1733
   int retVal = -1;
sl@0
  1734
  
sl@0
  1735
   printf( "Calling system()...
sl@0
  1736
" );
sl@0
  1737
  
sl@0
  1738
   /* helloworld.exe is an executable that just prints
sl@0
  1739
    * "Hello world!" and it should be created before
sl@0
  1740
    * executing this example code.
sl@0
  1741
    */
sl@0
  1742
   retVal = system("c:\sys\bin\helloworld.exe");
sl@0
  1743
   
sl@0
  1744
   /* Print the return value of system() */
sl@0
  1745
   printf( "system() returned: %d", retVal );
sl@0
  1746
   
sl@0
  1747
   return 0;
sl@0
  1748
}
sl@0
  1749
sl@0
  1750
@endcode
sl@0
  1751
@code
sl@0
  1752
Output
sl@0
  1753
sl@0
  1754
Calling system()...
sl@0
  1755
system() returned: -1
sl@0
  1756
sl@0
  1757
@endcode
sl@0
  1758
@see popen()
sl@0
  1759
 
sl@0
  1760
sl@0
  1761
@publishedAll
sl@0
  1762
@externallyDefinedApi
sl@0
  1763
*/
sl@0
  1764
sl@0
  1765
/** @fn  wctomb(char *s, wchar_t wchar)
sl@0
  1766
@param s
sl@0
  1767
@param wchar
sl@0
  1768
@return   If s is a null pointer, wctomb returns a non-zero or 0 value according to the current locale. If s is not a null pointer, wctomb returns -1 if the value of src does not correspond to 
sl@0
  1769
  a valid character, or returns the number of bytes that constitute the character 
sl@0
  1770
  corresponding to the value of wchar . In no case is value returned greater than the value of the {MB_CUR_MAX} macro.
sl@0
  1771
sl@0
  1772
  The wctomb function converts a wide character wchar into a multibyte character and stores
sl@0
  1773
the result in mbchar .
sl@0
  1774
The object pointed to by mbchar must be large enough to accommodate the multibyte character, which
sl@0
  1775
may be up to MB_LEN_MAX bytes.
sl@0
  1776
sl@0
  1777
 A call with a null mbchar pointer returns nonzero if the current locale requires shift states,
sl@0
  1778
zero otherwise;
sl@0
  1779
if shift states are required, the shift state is reset to the initial state.
sl@0
  1780
sl@0
  1781
 The behavior of the wctomb is affected by LC_CTYPE category of the current locale.
sl@0
  1782
sl@0
  1783
Examples:
sl@0
  1784
@code
sl@0
  1785
#include <stdlib.h>
sl@0
  1786
#include <wchar.h>
sl@0
  1787
/* Illustrates how to use wctomb API */
sl@0
  1788
int example_wctomb(wchar_t wc)
sl@0
  1789
{
sl@0
  1790
 char s[MAX_CUR_MAX];
sl@0
  1791
  int len;
sl@0
  1792
  
sl@0
  1793
  /* represent a wide-char in a single byte*/
sl@0
  1794
  len = wctomb(s, wc);
sl@0
  1795
  /* return the number of bytes */
sl@0
  1796
  return(len);
sl@0
  1797
}
sl@0
  1798
sl@0
  1799
@endcode
sl@0
  1800
sl@0
  1801
Limitations:
sl@0
  1802
sl@0
  1803
The current implementation of wctomb is not affected by the LC_CTYPE category of the current locale.
sl@0
  1804
It works only for UTF8 character set.
sl@0
  1805
sl@0
  1806
@see mbtowc()
sl@0
  1807
@see wcrtomb()
sl@0
  1808
@see wcstombs()
sl@0
  1809
@see wctob()
sl@0
  1810
 
sl@0
  1811
sl@0
  1812
@publishedAll
sl@0
  1813
@externallyDefinedApi
sl@0
  1814
*/
sl@0
  1815
sl@0
  1816
/** @fn  wcstombs(char *  s, const wchar_t *  pwcs, size_t n)
sl@0
  1817
@param s
sl@0
  1818
@param pwcs
sl@0
  1819
@param n
sl@0
  1820
@return   The wcstombs function returns the number of bytes converted (not including 
sl@0
  1821
any terminating null), if successful, otherwise it returns ( size_t)(-1) .
sl@0
  1822
sl@0
  1823
  The wcstombs function converts a wide character string wcstring into a multibyte character string, mbstring ,
sl@0
  1824
beginning in the initial conversion state.
sl@0
  1825
Up to n bytes are stored in mbstring .
sl@0
  1826
Partial multibyte characters at the end of the string are not stored.
sl@0
  1827
The multibyte character string is null terminated if there is room.
sl@0
  1828
sl@0
  1829
 The behavior of the wcstombs is affected by LC_CTYPE category of the current locale.
sl@0
  1830
sl@0
  1831
Examples:
sl@0
  1832
@code
sl@0
  1833
#include <stdlib.h>
sl@0
  1834
#include <wchar.h>
sl@0
  1835
/* Illustrates how to use wcstombs API */
sl@0
  1836
size_t example_wcstombs(wchar_t *wcs, char *s, size_t n)
sl@0
  1837
{
sl@0
  1838
 size_t len;
sl@0
  1839
 /* converting multibyte string to a wide-char string */
sl@0
  1840
 len = wcstombs(s, (const wchar_t *)wcs, n);
sl@0
  1841
 /* returning no of bytes that make up the multibyte sequence */
sl@0
  1842
 return (len;);
sl@0
  1843
}
sl@0
  1844
sl@0
  1845
@endcode
sl@0
  1846
sl@0
  1847
Limitations:
sl@0
  1848
sl@0
  1849
The current implementation of wcstombs is not affected by the LC_CTYPE category of the current locale.
sl@0
  1850
It works only for UTF8 character set.
sl@0
  1851
sl@0
  1852
@see mbstowcs()
sl@0
  1853
@see wcsrtombs()
sl@0
  1854
@see wctomb()
sl@0
  1855
 
sl@0
  1856
sl@0
  1857
@publishedAll
sl@0
  1858
@externallyDefinedApi
sl@0
  1859
*/
sl@0
  1860
sl@0
  1861
/** @fn  atoll(str) const char *str
sl@0
  1862
@param str
sl@0
  1863
sl@0
  1864
Refer to  atol() for the documentation
sl@0
  1865
@see atof()
sl@0
  1866
@see atoi()
sl@0
  1867
@see strtod()
sl@0
  1868
@see strtol()
sl@0
  1869
@see strtoul()
sl@0
  1870
 
sl@0
  1871
sl@0
  1872
@publishedAll
sl@0
  1873
@externallyDefinedApi
sl@0
  1874
*/
sl@0
  1875
sl@0
  1876
/** @fn  llabs(long long j)
sl@0
  1877
@param j
sl@0
  1878
@return   The llabs function
sl@0
  1879
returns the absolue value.
sl@0
  1880
sl@0
  1881
  The llabs function returns the absolute value of j.
sl@0
  1882
sl@0
  1883
sl@0
  1884
sl@0
  1885
Examples:
sl@0
  1886
@code
sl@0
  1887
#include  <stdio.h>
sl@0
  1888
#include  <stdlib.h>
sl@0
  1889
 
sl@0
  1890
int main( void )
sl@0
  1891
{
sl@0
  1892
   int    ix = -4, iy;
sl@0
  1893
   long   lx = -41567L, ly;
sl@0
  1894
   long long llx = -5343546758, lly;
sl@0
  1895
 
sl@0
  1896
   iy = abs( ix );
sl@0
  1897
   printf( "The abs value of %d is %d
sl@0
  1898
", ix, iy);
sl@0
  1899
 
sl@0
  1900
   ly = labs( lx );
sl@0
  1901
   printf( "The abs value of %ld is %ld
sl@0
  1902
", lx, ly);
sl@0
  1903
 
sl@0
  1904
   lly = llabs( llx );
sl@0
  1905
   printf( "The abs value of %lld is %lld
sl@0
  1906
", llx, lly );
sl@0
  1907
 
sl@0
  1908
   return 0;
sl@0
  1909
}
sl@0
  1910
sl@0
  1911
@endcode
sl@0
  1912
@code
sl@0
  1913
Output
sl@0
  1914
sl@0
  1915
The absolute value of -4 is 4
sl@0
  1916
The absolute value of -41567 is 41567
sl@0
  1917
The absolute value of -5343546758 is 5343546758
sl@0
  1918
sl@0
  1919
@endcode
sl@0
  1920
@see abs()
sl@0
  1921
@see fabs()
sl@0
  1922
@see hypot()
sl@0
  1923
@see labs()
sl@0
  1924
@see math()
sl@0
  1925
 
sl@0
  1926
sl@0
  1927
@publishedAll
sl@0
  1928
@externallyDefinedApi
sl@0
  1929
*/
sl@0
  1930
sl@0
  1931
/** @fn  lldiv(long long numer, long long denom)
sl@0
  1932
@param numer
sl@0
  1933
@param denom
sl@0
  1934
sl@0
  1935
The  lldiv function computes the value of  numer divided by  denom and returns the stored result in the form of the lldiv_t type.
sl@0
  1936
sl@0
  1937
The lldiv_t type is defined as:
sl@0
  1938
@code
sl@0
  1939
typedef struct {
sl@0
  1940
        long long quot; /* Quotient. */
sl@0
  1941
        long long rem;  /* Remainder. */
sl@0
  1942
} lldiv_t;
sl@0
  1943
@endcode
sl@0
  1944
sl@0
  1945
Examples:
sl@0
  1946
@code
sl@0
  1947
#include <stdlib.h>
sl@0
  1948
#include <stdio.h>
sl@0
  1949
#include <math.h> /* link to the math lib -libm */
sl@0
  1950
 
sl@0
  1951
int main( void )
sl@0
  1952
{
sl@0
  1953
 long long numer = pow(2, 40);
sl@0
  1954
 long long denom = 3;
sl@0
  1955
 
sl@0
  1956
 /* call to lldiv */
sl@0
  1957
 lldiv_t x = lldiv(-numer, denom);
sl@0
  1958
 
sl@0
  1959
 printf("Result-> 
sl@0
  1960
Quotient = %ld 
sl@0
  1961
Remainder = %ld", x.quot, x.rem);
sl@0
  1962
                 
sl@0
  1963
 long long exp_numer = (denom * x.quot) + x.rem;
sl@0
  1964
  
sl@0
  1965
 if( exp_numer == (-numer) )
sl@0
  1966
    printf("
sl@0
  1967
Expected output");  
sl@0
  1968
 else
sl@0
  1969
    printf("Unexpected output");
sl@0
  1970
  
sl@0
  1971
 return 0;
sl@0
  1972
}
sl@0
  1973
sl@0
  1974
@endcode
sl@0
  1975
@code
sl@0
  1976
Output
sl@0
  1977
sl@0
  1978
Result->
sl@0
  1979
Quotient = -366503875925
sl@0
  1980
Remainder = -1
sl@0
  1981
Expected output
sl@0
  1982
sl@0
  1983
sl@0
  1984
@endcode
sl@0
  1985
@see div()
sl@0
  1986
@see ldiv()
sl@0
  1987
@see math()
sl@0
  1988
 
sl@0
  1989
sl@0
  1990
@publishedAll
sl@0
  1991
@externallyDefinedApi
sl@0
  1992
*/
sl@0
  1993
sl@0
  1994
/** @fn  strtoll(const char *  nptr, char **  endptr, int base)
sl@0
  1995
@param nptr
sl@0
  1996
@param endptr
sl@0
  1997
@param base
sl@0
  1998
sl@0
  1999
Refer to  strtol() for the documentation
sl@0
  2000
@see atof()
sl@0
  2001
@see atoi()
sl@0
  2002
@see atol()
sl@0
  2003
@see strtod()
sl@0
  2004
@see strtoul()
sl@0
  2005
@see wcstol()
sl@0
  2006
 
sl@0
  2007
sl@0
  2008
@publishedAll
sl@0
  2009
@externallyDefinedApi
sl@0
  2010
*/
sl@0
  2011
sl@0
  2012
/** @fn  strtoull(const char *  nptr, char **  endptr, int base)
sl@0
  2013
@param nptr
sl@0
  2014
@param endptr
sl@0
  2015
@param base
sl@0
  2016
sl@0
  2017
Refer to  strtoul() for the documentation
sl@0
  2018
@see strtol()
sl@0
  2019
@see wcstoul()
sl@0
  2020
 
sl@0
  2021
sl@0
  2022
@publishedAll
sl@0
  2023
@externallyDefinedApi
sl@0
  2024
*/
sl@0
  2025
sl@0
  2026
/** @fn _Exit(int code) 
sl@0
  2027
@param code
sl@0
  2028
sl@0
  2029
Refer to  _exit() for the documentation
sl@0
  2030
sl@0
  2031
@publishedAll
sl@0
  2032
@externallyDefinedApi
sl@0
  2033
*/
sl@0
  2034
sl@0
  2035
/** @fn  setenv(const char *name, const char *value, int overwrite)
sl@0
  2036
@param name
sl@0
  2037
@param value
sl@0
  2038
@param overwrite
sl@0
  2039
sl@0
  2040
Refer to  getenv() for the documentation
sl@0
  2041
sl@0
  2042
 
sl@0
  2043
sl@0
  2044
@publishedAll
sl@0
  2045
@externallyDefinedApi
sl@0
  2046
*/
sl@0
  2047
sl@0
  2048
/** @fn  unsetenv(const char *name)
sl@0
  2049
@param name
sl@0
  2050
sl@0
  2051
Refer to  getenv() for the documentation
sl@0
  2052
sl@0
  2053
 
sl@0
  2054
sl@0
  2055
@publishedAll
sl@0
  2056
@externallyDefinedApi
sl@0
  2057
*/
sl@0
  2058
sl@0
  2059
sl@0
  2060
/** @fn  mkstemp(char *template)
sl@0
  2061
@param template
sl@0
  2062
@return   The mkstemp function
sl@0
  2063
returns -1 if no suitable file could be created
sl@0
  2064
and an error code is placed in the global variable. errno.
sl@0
  2065
sl@0
  2066
The mkstemp function
sl@0
  2067
takes the given file name template and overwrites a portion of it
sl@0
  2068
to create a file with that name and returns a file descriptor
sl@0
  2069
opened for reading and writing.
sl@0
  2070
This file name is guaranteed not to exist at the time of function invocation
sl@0
  2071
and is suitable for use
sl@0
  2072
by the application.
sl@0
  2073
The template may be any file name with some number of "X s"
sl@0
  2074
appended
sl@0
  2075
to it, for example
sl@0
  2076
@code
sl@0
  2077
/tmp/temp.XXXXXX.
sl@0
  2078
@endcode
sl@0
  2079
 The trailing "X s" are replaced with a
sl@0
  2080
unique alphanumeric combination.
sl@0
  2081
The number of unique file names mkstemp can return depends on the number of "X s"
sl@0
  2082
provided; six "X s"
sl@0
  2083
will
sl@0
  2084
result in mkstemp selecting one of 56800235584 (62 ** 6) possible temporary file names.
sl@0
  2085
sl@0
  2086
sl@0
  2087
Examples:
sl@0
  2088
@code
sl@0
  2089
#include <stdlib.h>
sl@0
  2090
#include <stdio.h> //printf, SEEK_SET
sl@0
  2091
#include <unistd.h>
sl@0
  2092
 
sl@0
  2093
int main( void )
sl@0
  2094
{
sl@0
  2095
 char arr[] = "c:\someXXXXXXXX";
sl@0
  2096
 char buf[10];
sl@0
  2097
  
sl@0
  2098
 //create a temporary file using mkstemp()
sl@0
  2099
 int fd = mkstemp(arr);
sl@0
  2100
  
sl@0
  2101
 if(fd != -1)
sl@0
  2102
 {
sl@0
  2103
    //write to the file
sl@0
  2104
    write(fd, "hello", 5);
sl@0
  2105
    //seek to the beginning of the file
sl@0
  2106
    lseek(fd, 0, SEEK_SET); //beg of the file
sl@0
  2107
    //read from the file
sl@0
  2108
    read(fd, buf, 5);
sl@0
  2109
    buf[5] = '\0';
sl@0
  2110
    //close the file
sl@0
  2111
    close(fd);
sl@0
  2112
 }
sl@0
  2113
 
sl@0
  2114
 printf("buf read: %s", buf);
sl@0
  2115
 return 0;
sl@0
  2116
}
sl@0
  2117
sl@0
  2118
@endcode
sl@0
  2119
@code
sl@0
  2120
Output
sl@0
  2121
sl@0
  2122
buf read: hello
sl@0
  2123
sl@0
  2124
@endcode
sl@0
  2125
sl@0
  2126
Notes:
sl@0
  2127
sl@0
  2128
 A common problem that results in a core dump is that the programmer passes 
sl@0
  2129
in a read-only string to mkstemp. This is particulary so with programs that were developed before -isoC compilers were common. For example, calling mkstemp with an argument of "/tmp/tempfile.XXXXXX" will result in a core dump due to mkstemp attempting to modify the string constant that was given. If 
sl@0
  2130
the program in question makes heavy use of that type of function call, you do 
sl@0
  2131
have the option of compiling the program so that it will store string constants 
sl@0
  2132
in a writable segment of memory.
sl@0
  2133
@see chmod()
sl@0
  2134
@see getpid()
sl@0
  2135
@see mkdir()
sl@0
  2136
@see open()
sl@0
  2137
@see stat()
sl@0
  2138
 
sl@0
  2139
sl@0
  2140
@publishedAll
sl@0
  2141
@externallyDefinedApi
sl@0
  2142
*/
sl@0
  2143
sl@0
  2144
/** @fn  mkstemp64(char *template)
sl@0
  2145
@param template
sl@0
  2146
@return   The mkstemp64 function
sl@0
  2147
returns -1 if no suitable file could be created
sl@0
  2148
and an error code is placed in the global variable. errno.
sl@0
  2149
sl@0
  2150
The mkstemp64() function generates a unique temporary file name from template. The last six characters of template must be XXXXXX and these are replaced with a string that makes the filename unique.
sl@0
  2151
The mkstemp64() function is a 64-bit version of mkstemp.
sl@0
  2152
This function can be used to create tmp files which can grow more than 32 bit sizes
sl@0
  2153
sl@0
  2154
@see mkstemp()
sl@0
  2155
 
sl@0
  2156
@publishedAll
sl@0
  2157
@externallyDefinedApi
sl@0
  2158
*/
sl@0
  2159
sl@0
  2160
/** @fn  putenv(const char *string)
sl@0
  2161
@param string
sl@0
  2162
sl@0
  2163
Refer to  getenv() for the documentation
sl@0
  2164
sl@0
  2165
 
sl@0
  2166
sl@0
  2167
@publishedAll
sl@0
  2168
@externallyDefinedApi
sl@0
  2169
*/
sl@0
  2170
sl@0
  2171
/** @fn  random(void)
sl@0
  2172
sl@0
  2173
Note: 
sl@0
  2174
sl@0
  2175
This description also covers the following functions -
sl@0
  2176
 srandom()  srandomdev()  initstate()  setstate() 
sl@0
  2177
sl@0
  2178
The random function
sl@0
  2179
uses a non-linear additive feedback random number generator employing a
sl@0
  2180
default table of size 31 long integers to return successive pseudo-random
sl@0
  2181
numbers in the range from 0 to
sl@0
  2182
(2**(310) -1). The period of this random number generator is very large, approximately
sl@0
  2183
16*(2**(310) -1).
sl@0
  2184
sl@0
  2185
 The random and srandom functions have (almost) the same calling sequence and initialization properties as the rand and srand functions.
sl@0
  2186
The difference is that rand produces a much less random sequence  in fact, the low dozen bits
sl@0
  2187
generated by rand go through a cyclic pattern.
sl@0
  2188
All the bits generated by random are usable.
sl@0
  2189
For example, 'random()\&01'
sl@0
  2190
will produce a random binary
sl@0
  2191
value.
sl@0
  2192
sl@0
  2193
 Like rand random will by default produce a sequence of numbers that can be duplicated
sl@0
  2194
by calling srandom with "1"
sl@0
  2195
as the seed.
sl@0
  2196
sl@0
  2197
 The srandomdev routine initializes a state array using the random random number device which returns good random numbers,
sl@0
  2198
suitable for cryptographic use.
sl@0
  2199
Note that this particular seeding
sl@0
  2200
procedure can generate states which are impossible to reproduce by
sl@0
  2201
calling srandom with any value, since the succeeding terms in the
sl@0
  2202
state buffer are no longer derived from the LC algorithm applied to
sl@0
  2203
a fixed seed.
sl@0
  2204
sl@0
  2205
 The initstate routine allows a state array, passed in as an argument, to be initialized
sl@0
  2206
for future use.
sl@0
  2207
The size of the state array (in bytes) is used by initstate to decide how sophisticated a random number generator it should use  the
sl@0
  2208
more state, the better the random numbers will be.
sl@0
  2209
(Current "optimal" values for the amount of state information are
sl@0
  2210
8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to
sl@0
  2211
the nearest known amount.
sl@0
  2212
Using less than 8 bytes will cause an error.)
sl@0
  2213
The seed for the initialization (which specifies a starting point for
sl@0
  2214
the random number sequence, and provides for restarting at the same
sl@0
  2215
point) is also an argument.
sl@0
  2216
The initstate function
sl@0
  2217
returns a pointer to the previous state information array.
sl@0
  2218
sl@0
  2219
 Once a state has been initialized, the setstate routine provides for rapid switching between states.
sl@0
  2220
The setstate function
sl@0
  2221
returns a pointer to the previous state array; its
sl@0
  2222
argument state array is used for further random number generation
sl@0
  2223
until the next call to initstate or setstate.
sl@0
  2224
sl@0
  2225
 Once a state array has been initialized, it may be restarted at a different 
sl@0
  2226
  point either by calling initstate (with the desired seed, the state array, and its size) or 
sl@0
  2227
  by calling both setstate (with the state array) and srandom (with the desired seed). The advantage of calling both setstate and srandom is that the size of the state array does not have to be remembered 
sl@0
  2228
  after it is initialized.
sl@0
  2229
sl@0
  2230
 With 256 bytes of state information, the period of the random number generator 
sl@0
  2231
  is greater than 2**(690) , which should be sufficient for most purposes.
sl@0
  2232
sl@0
  2233
Examples:
sl@0
  2234
@code
sl@0
  2235
//Illustrates how to use srandom API.
sl@0
  2236
#include <stdlib.h>
sl@0
  2237
void  srandomTest()
sl@0
  2238
{
sl@0
  2239
       long randNum;
sl@0
  2240
       // srandom function call sets its argument as the seed for the new sequence of random integers //generated by  random
sl@0
  2241
       srandom(2);
sl@0
  2242
// Function call to generate the random number, which will generate the random based on the //argument passed to the srandom function.
sl@0
  2243
       randNum = random();
sl@0
  2244
       //print the random number generated.
sl@0
  2245
       printf("random number is %d",randNum);
sl@0
  2246
}
sl@0
  2247
sl@0
  2248
@endcode
sl@0
  2249
@code
sl@0
  2250
Output
sl@0
  2251
sl@0
  2252
random number is 1505335290.
sl@0
  2253
sl@0
  2254
@endcode
sl@0
  2255
Diagnostics:
sl@0
  2256
sl@0
  2257
 If initstate is called with less than 8 bytes of state information, or if setstate detects that the state information has been garbled, error
sl@0
  2258
messages are printed on the standard error output.
sl@0
  2259
@see arc4random()
sl@0
  2260
@see rand()
sl@0
  2261
@see srand()
sl@0
  2262
@see random()
sl@0
  2263
sl@0
  2264
Bugs:
sl@0
  2265
sl@0
  2266
 About 2/3 the speed of rand The historical implementation used to have a very weak seeding; the
sl@0
  2267
random sequence did not vary much with the seed.
sl@0
  2268
The current implementation employs a better pseudo-random number
sl@0
  2269
generator for the initial state calculation. Applications requiring cryptographic quality randomness should use arc4random .
sl@0
  2270
sl@0
  2271
 
sl@0
  2272
sl@0
  2273
@publishedAll
sl@0
  2274
@externallyDefinedApi
sl@0
  2275
*/
sl@0
  2276
sl@0
  2277
/** @fn  srandom(unsigned long seed)
sl@0
  2278
@param seed
sl@0
  2279
sl@0
  2280
Refer to  random() for the documentation
sl@0
  2281
@see arc4random()
sl@0
  2282
@see rand()
sl@0
  2283
@see srand()
sl@0
  2284
@see random()
sl@0
  2285
 
sl@0
  2286
sl@0
  2287
@publishedAll
sl@0
  2288
@externallyDefinedApi
sl@0
  2289
*/
sl@0
  2290
sl@0
  2291
/** @fn  realpath(const char *pathname, char resolved_path[])
sl@0
  2292
@param pathname
sl@0
  2293
@param resolved_path[]
sl@0
  2294
@return   The realpath function returns resolved_path on success.
sl@0
  2295
If an error occurs, realpath returns NULL, and resolved_path contains the pathname which caused the problem.
sl@0
  2296
sl@0
  2297
  The realpath function resolves all symbolic links, extra "/"
sl@0
  2298
characters and references to /./ and /../ in pathname, and copies the resulting absolute pathname into
sl@0
  2299
the memory referenced by resolved_path. The resolved_path argument must refer to a buffer capable of storing at least PATH_MAX characters.
sl@0
  2300
sl@0
  2301
 The realpath function will resolve both absolute and relative paths
sl@0
  2302
and return the absolute pathname corresponding to pathname. All but the last component of pathname must exist when realpath is called.
sl@0
  2303
sl@0
  2304
Examples:
sl@0
  2305
@code
sl@0
  2306
#include<stdlib.h>
sl@0
  2307
#include<stdio.h> //printf
sl@0
  2308
#include<sys/stat.h> //S_IWUSR
sl@0
  2309
#include<sys/syslimits.h> //PATH_MAX
sl@0
  2310
#include<unistd.h> //chdir
sl@0
  2311
 
sl@0
  2312
int main()
sl@0
  2313
{
sl@0
  2314
 char resolvepath[PATH_MAX];
sl@0
  2315
 FILE *fp = NULL;
sl@0
  2316
 char *rpath = NULL;
sl@0
  2317
 int isymlink = 0;
sl@0
  2318
  
sl@0
  2319
 fp = fopen("c:\xyz.txt", "w");
sl@0
  2320
 if(!fp)
sl@0
  2321
 {
sl@0
  2322
     printf("fopen failed!!");
sl@0
  2323
     return -1;
sl@0
  2324
 }
sl@0
  2325
    
sl@0
  2326
 mkdir("c:\tmdir", S_IWUSR);
sl@0
  2327
  
sl@0
  2328
 int c = chdir("c:\");
sl@0
  2329
 if(c == -1)
sl@0
  2330
 {
sl@0
  2331
     printf("chdir failed!!");
sl@0
  2332
     return -1;
sl@0
  2333
 }
sl@0
  2334
  
sl@0
  2335
 rpath = realpath(".\tmdir\..\xyz.txt", resolvepath);
sl@0
  2336
 printf("resolvepath: %s", resolvepath);
sl@0
  2337
 if(rpath != NULL)
sl@0
  2338
    printf("rpath: %s", rpath);
sl@0
  2339
  
sl@0
  2340
 fclose(fp);
sl@0
  2341
 rmdir("c:\tmdir");
sl@0
  2342
 unlink("c:\xyz.txt");
sl@0
  2343
  
sl@0
  2344
 mkdir("c:\tdir", S_IWUSR);
sl@0
  2345
  
sl@0
  2346
 fp = fopen("c:\tdir\xyz.txt", "w");
sl@0
  2347
 if(!fp)
sl@0
  2348
 {
sl@0
  2349
     printf("fopen failed!!");
sl@0
  2350
     return -1;
sl@0
  2351
 }
sl@0
  2352
  
sl@0
  2353
 fclose(fp);
sl@0
  2354
  
sl@0
  2355
 unlink("c:\linkname.txt");
sl@0
  2356
    
sl@0
  2357
 isymlink = symlink("c:\tdir\xyz.txt", "c:\linkname.txt");
sl@0
  2358
 if (isymlink == -1)
sl@0
  2359
 {
sl@0
  2360
     printf("symlink failed!!");
sl@0
  2361
     return -1;
sl@0
  2362
 }
sl@0
  2363
   
sl@0
  2364
 rpath = realpath("c:\linkname.txt", resolvepath);
sl@0
  2365
  
sl@0
  2366
 printf("resolvepath: %s", resolvepath);
sl@0
  2367
 if(rpath != NULL)
sl@0
  2368
    printf("rpath: %s", rpath);
sl@0
  2369
  
sl@0
  2370
 unlink("c:\tdir\xyz.txt");
sl@0
  2371
 rmdir("c:\tdir");
sl@0
  2372
   
sl@0
  2373
 return 0;
sl@0
  2374
}
sl@0
  2375
sl@0
  2376
@endcode
sl@0
  2377
@code
sl@0
  2378
Output
sl@0
  2379
sl@0
  2380
resolvepath: C:\xyz.txt
sl@0
  2381
rpath: C:\xyz.txt
sl@0
  2382
resolvepath: c:	dir\xyz.txt
sl@0
  2383
rpath: c:	dir\xyz.txt
sl@0
  2384
sl@0
  2385
@endcode
sl@0
  2386
 
sl@0
  2387
sl@0
  2388
@publishedAll
sl@0
  2389
@externallyDefinedApi
sl@0
  2390
*/
sl@0
  2391
sl@0
  2392
/** @fn  setstate(char *state)
sl@0
  2393
@param state
sl@0
  2394
sl@0
  2395
Refer to  random() for the documentation
sl@0
  2396
@see arc4random()
sl@0
  2397
@see rand()
sl@0
  2398
@see srand()
sl@0
  2399
@see random()
sl@0
  2400
 
sl@0
  2401
sl@0
  2402
@publishedAll
sl@0
  2403
@externallyDefinedApi
sl@0
  2404
*/
sl@0
  2405
sl@0
  2406
/** @fn  initstate(unsigned long seed, char *state, long n)
sl@0
  2407
@param seed
sl@0
  2408
@param state
sl@0
  2409
@param n
sl@0
  2410
sl@0
  2411
Refer to  random() for the documentation
sl@0
  2412
@see arc4random()
sl@0
  2413
@see rand()
sl@0
  2414
@see srand()
sl@0
  2415
@see random()
sl@0
  2416
 
sl@0
  2417
sl@0
  2418
@publishedAll
sl@0
  2419
@externallyDefinedApi
sl@0
  2420
*/
sl@0
  2421
sl@0
  2422
sl@0
  2423
/** @fn  getprogname(void)
sl@0
  2424
sl@0
  2425
Refer to  setprogname() for the documentation
sl@0
  2426
sl@0
  2427
@publishedAll
sl@0
  2428
@externallyDefinedApi
sl@0
  2429
*/
sl@0
  2430
sl@0
  2431
/** @fn  reallocf(void *ptr, size_t size)
sl@0
  2432
@param ptr
sl@0
  2433
@param size
sl@0
  2434
sl@0
  2435
Refer to  malloc() for the documentation
sl@0
  2436
@see brk()
sl@0
  2437
@see mmap()
sl@0
  2438
@see getpagesize()
sl@0
  2439
 
sl@0
  2440
sl@0
  2441
@publishedAll
sl@0
  2442
@externallyDefinedApi
sl@0
  2443
*/
sl@0
  2444
sl@0
  2445
/** @fn setprogname(const char *programname)
sl@0
  2446
@param programname
sl@0
  2447
sl@0
  2448
These utility functions get and set the current program's name as used by
sl@0
  2449
various error-reporting functions.getprogname() returns the name of the current program.
sl@0
  2450
This function is typically useful when generating error messages or other diagnostic out-put.
sl@0
  2451
If the program name has not been set, getprogname() will return NULL.
sl@0
  2452
setprogname() sets the name of the current program to be the last path-name component of the programname argument.
sl@0
  2453
It should be invoked at the start of the program, using the argv[0] passed into the program's main() function.
sl@0
  2454
A pointer into the string pointed to by the programname argument is kept as the program name.
sl@0
  2455
Therefore, the string pointed to by programname should not be modified during the rest of the program's operation.
sl@0
  2456
A program's name can only be set once, and in NetBSD that is actually done by program start-up code that is run before main() is called.
sl@0
  2457
Therefore, in NetBSD, calling setprogname() from main() has no effect.
sl@0
  2458
However, it does serve to increase the portability of the program:
sl@0
  2459
on other operating systems, getprogname() and setprogname() may be implemented by a portability library, 
sl@0
  2460
and a call to setprogname() allows that library to know the program name without modifications to that system's program start-up code.
sl@0
  2461
@publishedAll
sl@0
  2462
@externallyDefinedApi
sl@0
  2463
*/
sl@0
  2464
sl@0
  2465
/** @fn  strtoq(const char *nptr, char **endptr, int base)
sl@0
  2466
@param nptr
sl@0
  2467
@param endptr
sl@0
  2468
@param base
sl@0
  2469
sl@0
  2470
Refer to  strtol() for the documentation
sl@0
  2471
@see atof()
sl@0
  2472
@see atoi()
sl@0
  2473
@see atol()
sl@0
  2474
@see strtod()
sl@0
  2475
@see strtoul()
sl@0
  2476
@see wcstol()
sl@0
  2477
 
sl@0
  2478
sl@0
  2479
@publishedAll
sl@0
  2480
@externallyDefinedApi
sl@0
  2481
*/
sl@0
  2482
sl@0
  2483
/** @fn  strtouq(const char *nptr, char **endptr, int base)
sl@0
  2484
@param nptr
sl@0
  2485
@param endptr
sl@0
  2486
@param base
sl@0
  2487
sl@0
  2488
Refer to  strtoul() for the documentation
sl@0
  2489
@see strtol()
sl@0
  2490
@see wcstoul()
sl@0
  2491
 
sl@0
  2492
sl@0
  2493
@publishedAll
sl@0
  2494
@externallyDefinedApi
sl@0
  2495
*/
sl@0
  2496
sl@0
  2497
sl@0
  2498
/** @struct div_t 
sl@0
  2499
sl@0
  2500
Contains the following members
sl@0
  2501
sl@0
  2502
@publishedAll
sl@0
  2503
@externallyDefinedApi
sl@0
  2504
*/
sl@0
  2505
sl@0
  2506
/** @var div_t::quot
sl@0
  2507
quotient
sl@0
  2508
*/
sl@0
  2509
sl@0
  2510
/** @var div_t::rem
sl@0
  2511
remainder
sl@0
  2512
*/
sl@0
  2513
sl@0
  2514
sl@0
  2515
/** @struct ldiv_t 
sl@0
  2516
sl@0
  2517
Contains the following members
sl@0
  2518
sl@0
  2519
@publishedAll
sl@0
  2520
@externallyDefinedApi
sl@0
  2521
*/
sl@0
  2522
sl@0
  2523
/** @var ldiv_t::quot
sl@0
  2524
quotient
sl@0
  2525
*/
sl@0
  2526
sl@0
  2527
/** @var ldiv_t::rem
sl@0
  2528
remainder
sl@0
  2529
*/
sl@0
  2530
sl@0
  2531
sl@0
  2532
/** @struct lldiv_t 
sl@0
  2533
sl@0
  2534
Contains the following members
sl@0
  2535
sl@0
  2536
@publishedAll
sl@0
  2537
@externallyDefinedApi
sl@0
  2538
*/
sl@0
  2539
sl@0
  2540
/** @var lldiv_t::quot
sl@0
  2541
quotient
sl@0
  2542
*/
sl@0
  2543
sl@0
  2544
/** @var lldiv_t::rem
sl@0
  2545
remainder
sl@0
  2546
*/
sl@0
  2547
sl@0
  2548
sl@0
  2549
/** @def EXIT_FAILURE 
sl@0
  2550
sl@0
  2551
These are arguments for the exit and _exit functions and the return values for the atexit and _onexit functions.
sl@0
  2552
sl@0
  2553
@publishedAll
sl@0
  2554
@externallyDefinedApi
sl@0
  2555
*/
sl@0
  2556
sl@0
  2557
sl@0
  2558
/** @def EXIT_SUCCESS 
sl@0
  2559
sl@0
  2560
These are arguments for the exit and _exit functions and the return values for the atexit and _onexit functions.
sl@0
  2561
sl@0
  2562
@publishedAll
sl@0
  2563
@externallyDefinedApi
sl@0
  2564
*/
sl@0
  2565
sl@0
  2566
sl@0
  2567
/** @def  RAND_MAX
sl@0
  2568
sl@0
  2569
The constant RAND_MAX is the maximum value that can be returned by the rand function.
sl@0
  2570
sl@0
  2571
@publishedAll
sl@0
  2572
@externallyDefinedApi
sl@0
  2573
*/
sl@0
  2574
sl@0
  2575
sl@0
  2576
sl@0
  2577
/** @def MB_CUR_MAX 
sl@0
  2578
sl@0
  2579
The value of MB_CUR_MAX is the maximum number of bytes in a multibyte character for the current locale.
sl@0
  2580
sl@0
  2581
@publishedAll
sl@0
  2582
@externallyDefinedApi
sl@0
  2583
*/
sl@0
  2584
sl@0
  2585
sl@0
  2586
sl@0
  2587
sl@0
  2588