os/ossrv/genericopenlibs/openenvcore/include/string.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/string.h
sl@0
     2
@internalComponent
sl@0
     3
*/
sl@0
     4
sl@0
     5
/** @fn  memccpy(void *t, const void *f, int c, size_t n)
sl@0
     6
@param t
sl@0
     7
@param f
sl@0
     8
@param c
sl@0
     9
@param n
sl@0
    10
@return   memccpy function returns a pointer to the next character in t after c, or NULL if c was not found in the first n characters of f.
sl@0
    11
sl@0
    12
  The memccpy function
sl@0
    13
copies bytes from string f to string t. If the character c (as converted to an unsigned char) occurs in the string f, the copy stops and a pointer to the byte after the copy of c in the string t is returned.
sl@0
    14
Otherwise, n bytes are copied, and a NULL pointer is returned.
sl@0
    15
sl@0
    16
Examples:
sl@0
    17
@code
sl@0
    18
#include <string.h>
sl@0
    19
#include <stdio.h>
sl@0
    20
int main()
sl@0
    21
{
sl@0
    22
    char one[50] = {"\0"};
sl@0
    23
    (void) memccpy(one, "abcdefgh",8,3);
sl@0
    24
    printf("String after memcpy %s
sl@0
    25
",one);
sl@0
    26
    (void) memccpy(one, "Hello",5,1);
sl@0
    27
    printf("String after memcpy %s
sl@0
    28
",one);
sl@0
    29
    return 0;
sl@0
    30
}
sl@0
    31
sl@0
    32
@endcode
sl@0
    33
 Output
sl@0
    34
@code
sl@0
    35
String after memcpy abc
sl@0
    36
String after memcpy Hbc
sl@0
    37
sl@0
    38
@endcode
sl@0
    39
@see bcopy()
sl@0
    40
@see memcpy()
sl@0
    41
@see memmove()
sl@0
    42
@see strcpy()
sl@0
    43
sl@0
    44
sl@0
    45
 
sl@0
    46
sl@0
    47
@publishedAll
sl@0
    48
@externallyDefinedApi
sl@0
    49
*/
sl@0
    50
sl@0
    51
/** @fn  memchr(const void *s, int c, size_t n)
sl@0
    52
@param s
sl@0
    53
@param c
sl@0
    54
@param n
sl@0
    55
sl@0
    56
@return   The memchr function
sl@0
    57
returns a pointer to the byte located,
sl@0
    58
or NULL if no such byte exists within n bytes.
sl@0
    59
sl@0
    60
  The memchr function
sl@0
    61
locates the first occurrence of c (converted to an unsigned char)
sl@0
    62
in string s.
sl@0
    63
sl@0
    64
Examples:
sl@0
    65
@code
sl@0
    66
#include <string.h>
sl@0
    67
#include <stdio.h>
sl@0
    68
int main()
sl@0
    69
{
sl@0
    70
    char one[50];
sl@0
    71
    char* ret;
sl@0
    72
    strcpy(one,"abcd");
sl@0
    73
    ret = memchr("abcd", ’c’,4);
sl@0
    74
    if(!strncmp(one+2,ret,1)) printf("\ ’c\ ’ found in string \"abcd\"\n");
sl@0
    75
    ret = memchr(one, ’z’,4);
sl@0
    76
    if(ret == NULL) printf("\ ’z\ ’ not found in string \"abcd\"\n");           
sl@0
    77
    return 0;
sl@0
    78
}
sl@0
    79
sl@0
    80
@endcode
sl@0
    81
 Output
sl@0
    82
@code
sl@0
    83
 ’c’ found in string "abcd"
sl@0
    84
 ’z’ not found in string "abcd"
sl@0
    85
sl@0
    86
@endcode
sl@0
    87
@see strchr()
sl@0
    88
@see strcspn()
sl@0
    89
@see strpbrk()
sl@0
    90
@see strsep()
sl@0
    91
@see strstr()
sl@0
    92
@see strtok()
sl@0
    93
sl@0
    94
sl@0
    95
 
sl@0
    96
sl@0
    97
@publishedAll
sl@0
    98
@externallyDefinedApi
sl@0
    99
*/
sl@0
   100
sl@0
   101
/** @fn  memcmp(const void *s1, const void *s2, size_t n)
sl@0
   102
@param s1
sl@0
   103
@param s2
sl@0
   104
@param n
sl@0
   105
sl@0
   106
@return   The memcmp function
sl@0
   107
returns zero if the two strings are identical,
sl@0
   108
otherwise returns the difference between the first two differing bytes
sl@0
   109
(treated as unsigned char values, so that '\\200'
sl@0
   110
is greater than '\\0'
sl@0
   111
for example).
sl@0
   112
Zero-length strings are always identical.
sl@0
   113
sl@0
   114
  The memcmp function
sl@0
   115
compares byte string s1 against byte string s2. Both strings are assumed to be n bytes long.
sl@0
   116
sl@0
   117
Examples:
sl@0
   118
@code
sl@0
   119
#include <string.h>
sl@0
   120
#include <stdio.h>
sl@0
   121
int main()
sl@0
   122
{
sl@0
   123
   char str1[]  = "abcdefg";
sl@0
   124
   char str2[] =  "abcdefr";
sl@0
   125
   int result;
sl@0
   126
   printf( "Compare ’%.6s’ to ’%.6s\n", str1, str2 );
sl@0
   127
   result = memcmp( str1, str2, 6);
sl@0
   128
   if( result < 0 )
sl@0
   129
      printf( "str1 is less than str2.\n" );
sl@0
   130
   else if( result == 0 )
sl@0
   131
      printf( "str1 is equal to str2.\n" );
sl@0
   132
   else if( result > 0 )
sl@0
   133
      printf( "str1 is greater than str2.\n" );
sl@0
   134
   printf( "Compare ’%.7s’ to ’%.7s\n", str1, str2 );
sl@0
   135
   result = memcmp( str1, str2, 7 );
sl@0
   136
   if( result < 0 )
sl@0
   137
      printf( "str1 is less than str2.\n" );
sl@0
   138
   else if( result == 0 )
sl@0
   139
      printf( "str1 is equal to str2.\n" );
sl@0
   140
   else if( result > 0 )
sl@0
   141
      printf( "str1 is greater than str2.\n" );
sl@0
   142
   return 0;    
sl@0
   143
}
sl@0
   144
sl@0
   145
@endcode
sl@0
   146
 Output
sl@0
   147
@code
sl@0
   148
Compare ’abcdef’ to ’abcdef
sl@0
   149
str1 is equal to str2.
sl@0
   150
Compare ’abcdefg’ to ’abcdefr
sl@0
   151
str1 is less than str2.
sl@0
   152
sl@0
   153
@endcode
sl@0
   154
@see bcmp()
sl@0
   155
@see strcasecmp()
sl@0
   156
@see strcmp()
sl@0
   157
@see strcoll()
sl@0
   158
@see strxfrm()
sl@0
   159
sl@0
   160
sl@0
   161
 
sl@0
   162
sl@0
   163
@publishedAll
sl@0
   164
@externallyDefinedApi
sl@0
   165
*/
sl@0
   166
sl@0
   167
/** @fn  memcpy(void *dst, const void *src, size_t len)
sl@0
   168
@param dst
sl@0
   169
@param src
sl@0
   170
@param len
sl@0
   171
@return   The memcpy function
sl@0
   172
returns the original value of dst.
sl@0
   173
sl@0
   174
  The memcpy function
sl@0
   175
copies len bytes from string src to string dst.
sl@0
   176
sl@0
   177
Examples:
sl@0
   178
@code
sl@0
   179
#include <string.h>
sl@0
   180
#include <stdio.h>
sl@0
   181
int main()
sl@0
   182
{
sl@0
   183
    char one[50] = {"\0"};
sl@0
   184
    (void) memcpy(one, "abcdefgh",8);
sl@0
   185
    printf("String after memcpy %s
sl@0
   186
",one);
sl@0
   187
    (void) memcpy(one, "Hello",5);
sl@0
   188
    printf("String after memcpy %s
sl@0
   189
",one);
sl@0
   190
    return 0;   
sl@0
   191
}
sl@0
   192
sl@0
   193
@endcode
sl@0
   194
 Output
sl@0
   195
@code
sl@0
   196
String after memcpy abcdefgh
sl@0
   197
String after memcpy Hellofgh
sl@0
   198
sl@0
   199
@endcode
sl@0
   200
@see bcopy()
sl@0
   201
@see memccpy()
sl@0
   202
@see memmove()
sl@0
   203
@see strcpy()
sl@0
   204
sl@0
   205
sl@0
   206
 
sl@0
   207
sl@0
   208
@publishedAll
sl@0
   209
@externallyDefinedApi
sl@0
   210
*/
sl@0
   211
sl@0
   212
/** @fn  memmove(void *dst, const void *src, size_t len)
sl@0
   213
@param dst
sl@0
   214
@param src
sl@0
   215
@param len
sl@0
   216
sl@0
   217
  The memmove function copies len bytes from string src to string dst. The two strings may overlap. The copy is always done in a non-destructive 
sl@0
   218
manner.
sl@0
   219
sl@0
   220
Examples:
sl@0
   221
@code
sl@0
   222
#include <string.h>
sl@0
   223
#include <stdio.h>
sl@0
   224
int main()
sl@0
   225
{
sl@0
   226
    char one[50];
sl@0
   227
    (void) strcpy(one, "abcdefgh");
sl@0
   228
    printf("String before memmove %s
sl@0
   229
",one);
sl@0
   230
    (void) memmove(one+1, "xyz", 2);
sl@0
   231
    printf("String after memmove %s
sl@0
   232
",one);
sl@0
   233
    (void) strcpy(one, "abcdefgh");
sl@0
   234
    printf("String before memmove %s
sl@0
   235
",one);
sl@0
   236
    (void) memmove(one+1, "xyz", 0);
sl@0
   237
    printf("String after memmove %s
sl@0
   238
",one);
sl@0
   239
    return 0;   
sl@0
   240
}
sl@0
   241
sl@0
   242
@endcode
sl@0
   243
 Output
sl@0
   244
@code
sl@0
   245
String before memmove abcdefgh
sl@0
   246
String after memmove axydefgh
sl@0
   247
String before memmove abcdefgh
sl@0
   248
String after memmove abcdefgh
sl@0
   249
sl@0
   250
@endcode
sl@0
   251
@return   The memmove function returns pointer to dst dst.
sl@0
   252
sl@0
   253
@see bcopy()
sl@0
   254
@see memcpy()
sl@0
   255
@see strcpy()
sl@0
   256
sl@0
   257
sl@0
   258
 
sl@0
   259
sl@0
   260
@publishedAll
sl@0
   261
@externallyDefinedApi
sl@0
   262
*/
sl@0
   263
sl@0
   264
/** @fn  memset(void *dst0, int c0, size_t length)
sl@0
   265
@param dst0
sl@0
   266
@param c0
sl@0
   267
@param length
sl@0
   268
sl@0
   269
  The memset function
sl@0
   270
writes length bytes of value c0 (converted to an unsigned char) to the string dst0.
sl@0
   271
sl@0
   272
Examples:
sl@0
   273
@code
sl@0
   274
#include <string.h>
sl@0
   275
#include <stdio.h>
sl@0
   276
int main()
sl@0
   277
{
sl@0
   278
    char one[50];       
sl@0
   279
    strcpy(one, "abcdefgh");
sl@0
   280
    printf("String before memset %s
sl@0
   281
",one);
sl@0
   282
    memset(one+1, 'x', 3);
sl@0
   283
    printf("String after calling memset first time %s
sl@0
   284
",one);          
sl@0
   285
    memset(one+2, 'y', 0);
sl@0
   286
    printf("String after calling memset second time %s
sl@0
   287
",one);
sl@0
   288
    return 0;   
sl@0
   289
}
sl@0
   290
sl@0
   291
@endcode
sl@0
   292
 Output
sl@0
   293
@code
sl@0
   294
String before memset abcdefgh
sl@0
   295
String after calling memset first time axxxefgh
sl@0
   296
String after calling memset second time axxxefgh
sl@0
   297
sl@0
   298
@endcode
sl@0
   299
@return   The memset function returns its first argument.
sl@0
   300
sl@0
   301
@see bzero()
sl@0
   302
@see swab()
sl@0
   303
sl@0
   304
sl@0
   305
 
sl@0
   306
sl@0
   307
@publishedAll
sl@0
   308
@externallyDefinedApi
sl@0
   309
*/
sl@0
   310
sl@0
   311
/** @fn  stpcpy(char *to, const char *from)
sl@0
   312
@param to
sl@0
   313
@param from
sl@0
   314
sl@0
   315
Note: This description also covers the following functions -
sl@0
   316
 strcpy()  strncpy() 
sl@0
   317
sl@0
   318
@return   The strcpy and strncpy functions
sl@0
   319
return to. The stpcpy function returns a pointer to the terminating ‘\\0’
sl@0
   320
character of to.
sl@0
   321
sl@0
   322
  The stpcpy and strcpy functions
sl@0
   323
copy the string from to to (including the terminating ‘\\0’
sl@0
   324
character.)
sl@0
   325
sl@0
   326
 The strncpy function copies at most len characters from from into to. If from is less than len characters long,
sl@0
   327
the remainder of to is filled with '\\0'
sl@0
   328
characters.
sl@0
   329
Otherwise, to is not terminated.
sl@0
   330
sl@0
   331
Examples:
sl@0
   332
@code
sl@0
   333
#include <string.h>
sl@0
   334
#include <stdio.h>
sl@0
   335
int main()
sl@0
   336
{
sl@0
   337
    char one[50] = {"abcdefgh"};        
sl@0
   338
    printf("String before strcpy %s
sl@0
   339
",one);
sl@0
   340
    strcpy(one,"Hello");
sl@0
   341
    printf("String after strcpy %s
sl@0
   342
",one);
sl@0
   343
    strncpy(one + 5, " ",1);
sl@0
   344
    strncpy(one + 6, "World",5);
sl@0
   345
    printf("String after strncpy %s
sl@0
   346
",one);
sl@0
   347
    return 0;   
sl@0
   348
}
sl@0
   349
sl@0
   350
@endcode
sl@0
   351
 Output
sl@0
   352
@code
sl@0
   353
String before strcpy abcdefgh
sl@0
   354
String after strcpy Hello
sl@0
   355
String after strncpy Hello World
sl@0
   356
sl@0
   357
@endcode
sl@0
   358
Examples:
sl@0
   359
 The following sets chararray to "abc\\0\\0\\0"
sl@0
   360
@code
sl@0
   361
char chararray[6];
sl@0
   362
(void)strncpy(chararray, "abc", sizeof(chararray));
sl@0
   363
sl@0
   364
@endcode
sl@0
   365
 The following sets chararray to "abcdef:"
sl@0
   366
@code
sl@0
   367
char chararray[6];
sl@0
   368
(void)strncpy(chararray, "abcdefgh", sizeof(chararray));
sl@0
   369
sl@0
   370
@endcode
sl@0
   371
 Note that it does not NULL terminate chararray because the length of the source string is greater than or equal
sl@0
   372
to the length argument. The following copies as many characters from input to buf as will fit and NULL terminates the result.
sl@0
   373
Because strncpy does not guarantee to NULL terminate the string itself, this must be done explicitly.
sl@0
   374
@code
sl@0
   375
char buf[1024];
sl@0
   376
(void)strncpy(buf, input, sizeof(buf) - 1);
sl@0
   377
buf[sizeof(buf) - 1] = ’\0’;
sl@0
   378
sl@0
   379
@endcode
sl@0
   380
sl@0
   381
Security considerations:
sl@0
   382
sl@0
   383
 The strcpy function is easily misused in a manner which enables malicious users
sl@0
   384
to arbitrarily change a running program's functionality through a
sl@0
   385
buffer overflow attack.
sl@0
   386
@see bcopy()
sl@0
   387
@see memcpy()
sl@0
   388
@see memmove()
sl@0
   389
sl@0
   390
sl@0
   391
 
sl@0
   392
sl@0
   393
@publishedAll
sl@0
   394
@externallyDefinedApi
sl@0
   395
*/
sl@0
   396
sl@0
   397
/** @fn  strcasestr(const char *s, const char *find)
sl@0
   398
@param s
sl@0
   399
@param find
sl@0
   400
sl@0
   401
Refer to  strstr() for the documentation
sl@0
   402
@see memchr()
sl@0
   403
@see strchr()
sl@0
   404
@see strcspn()
sl@0
   405
@see strpbrk()
sl@0
   406
@see strrchr()
sl@0
   407
@see strsep()
sl@0
   408
@see strspn()
sl@0
   409
@see strtok()
sl@0
   410
sl@0
   411
sl@0
   412
 
sl@0
   413
sl@0
   414
@publishedAll
sl@0
   415
@externallyDefinedApi
sl@0
   416
*/
sl@0
   417
sl@0
   418
/** @fn  strcat(char *  s, const char *  append)
sl@0
   419
@param s
sl@0
   420
@param append
sl@0
   421
sl@0
   422
Note: This description also covers the following functions -
sl@0
   423
 strncat() 
sl@0
   424
sl@0
   425
@return   The strcat and strncat functions
sl@0
   426
return the pointer s.
sl@0
   427
sl@0
   428
  The strcat and strncat functions
sl@0
   429
append a copy of the null-terminated string append to the end of the null-terminated string s, then add a terminating ‘\\0’
sl@0
   430
The string s must have sufficient space to hold the result.
sl@0
   431
sl@0
   432
 The strncat function
sl@0
   433
appends not more than count characters from append, and then adds a terminating ‘\\0’
sl@0
   434
sl@0
   435
Examples:
sl@0
   436
@code
sl@0
   437
#include <string.h>
sl@0
   438
#include <stdio.h>
sl@0
   439
int main()
sl@0
   440
{
sl@0
   441
    char one[50] = {"\0"};              
sl@0
   442
    strcpy(one,"Hello");
sl@0
   443
    strcat(one," World");
sl@0
   444
    printf("Concatenated String %s
sl@0
   445
",one);
sl@0
   446
    return 0;   
sl@0
   447
}
sl@0
   448
sl@0
   449
@endcode
sl@0
   450
 Output
sl@0
   451
@code
sl@0
   452
Concatenated String Hello World
sl@0
   453
sl@0
   454
@endcode
sl@0
   455
sl@0
   456
Security considerations:
sl@0
   457
sl@0
   458
 The strcat function is easily misused in a manner
sl@0
   459
which enables malicious users to arbitrarily change
sl@0
   460
a running program's functionality through a buffer overflow attack. Avoid using strcat. Instead, use strncat or strlcat and ensure that no more characters are copied to the destination buffer
sl@0
   461
than it can hold. Note that strncat can also be problematic.
sl@0
   462
It may be a security concern for a string to be truncated at all.
sl@0
   463
Since the truncated string will not be as long as the original,
sl@0
   464
it may refer to a completely different resource
sl@0
   465
and usage of the truncated resource
sl@0
   466
could result in very incorrect behavior.
sl@0
   467
Example:
sl@0
   468
sl@0
   469
@see bcopy()
sl@0
   470
@see memcpy()
sl@0
   471
@see memmove()
sl@0
   472
@see strcpy()
sl@0
   473
sl@0
   474
sl@0
   475
 
sl@0
   476
sl@0
   477
@publishedAll
sl@0
   478
@externallyDefinedApi
sl@0
   479
*/
sl@0
   480
sl@0
   481
/** @fn  strchr(const char *s, int c)
sl@0
   482
@param s
sl@0
   483
@param c
sl@0
   484
sl@0
   485
Note: This description also covers the following functions -
sl@0
   486
 strrchr() 
sl@0
   487
sl@0
   488
@return   The functions strchr and strrchr return a pointer to the located character, or NULL if the character does not appear in the string.
sl@0
   489
sl@0
   490
  The strchr function locates the first occurrence of c (converted to a char)
sl@0
   491
in the string pointed to by s. The terminating null character is considered part of the string;
sl@0
   492
therefore if c is ‘\\0’
sl@0
   493
the functions locate the terminating ‘\\0’
sl@0
   494
sl@0
   495
 The strrchr function is identical to strchr except it locates the last occurrence of c.
sl@0
   496
sl@0
   497
Examples:
sl@0
   498
@code
sl@0
   499
#include <string.h>
sl@0
   500
#include <stdio.h>
sl@0
   501
int main()
sl@0
   502
{
sl@0
   503
        char one[50];
sl@0
   504
        char* ret;
sl@0
   505
        strcpy(one,"abcd");
sl@0
   506
        ret = strchr("abcd", 'c');
sl@0
   507
        if(!strncmp(one+2,ret,1)) printf("\ 'c\ ' found in string \"abcd\"
sl@0
   508
");
sl@0
   509
        ret = strchr(one, 'z');
sl@0
   510
        if(ret == NULL) printf("\ 'z\ ' not found in string \"abcd\"
sl@0
   511
");               
sl@0
   512
        return 0;
sl@0
   513
}
sl@0
   514
sl@0
   515
@endcode
sl@0
   516
 Output
sl@0
   517
@code
sl@0
   518
 ’c’ found in string "abcd"
sl@0
   519
 ’z’ not found in string "abcd"
sl@0
   520
sl@0
   521
@endcode
sl@0
   522
@see memchr()
sl@0
   523
@see strcspn()
sl@0
   524
@see strpbrk()
sl@0
   525
@see strsep()
sl@0
   526
@see strspn()
sl@0
   527
@see strstr()
sl@0
   528
@see strtok()
sl@0
   529
sl@0
   530
sl@0
   531
 
sl@0
   532
sl@0
   533
@publishedAll
sl@0
   534
@externallyDefinedApi
sl@0
   535
*/
sl@0
   536
sl@0
   537
/** @fn  strcmp(const char *s1, const char *s2)
sl@0
   538
@param s1
sl@0
   539
@param s2
sl@0
   540
sl@0
   541
Note: This description also covers the following functions -
sl@0
   542
 strncmp() 
sl@0
   543
sl@0
   544
@return   The strcmp and strncmp return an integer greater than, equal to, or less than 0, according 
sl@0
   545
to whether the string s1 is greater than, equal to, or less than the string s2.
sl@0
   546
sl@0
   547
  The strcmp and strncmp functions
sl@0
   548
lexicographically compare the null-terminated strings s1 and s2.
sl@0
   549
sl@0
   550
 The strncmp function
sl@0
   551
compares not more than len characters.
sl@0
   552
Because strncmp is designed for comparing strings rather than binary data,
sl@0
   553
characters that appear after a ‘\\0’
sl@0
   554
character are not compared.
sl@0
   555
sl@0
   556
Examples:
sl@0
   557
@code
sl@0
   558
#include <string.h>
sl@0
   559
#include <stdio.h>
sl@0
   560
int main()
sl@0
   561
{
sl@0
   562
   char str1[]  = "abcdefg";
sl@0
   563
   char str2[] =  "abcdefr";
sl@0
   564
   int result;
sl@0
   565
   printf( "Compare '%s' to '%s
sl@0
   566
", str1, str2 );
sl@0
   567
   result = strcmp( str1, str2);
sl@0
   568
   if( result < 0 )
sl@0
   569
      printf( "str1 is less than str2.
sl@0
   570
" );
sl@0
   571
   else if( result == 0 )
sl@0
   572
      printf( "str1 is equal to str2.
sl@0
   573
" );
sl@0
   574
   else if( result > 0 )
sl@0
   575
      printf( "str1 is greater than str2.
sl@0
   576
" );
sl@0
   577
   printf( "Compare '%.6s' to '%.6s
sl@0
   578
", str1, str2 );
sl@0
   579
   result = strncmp( str1, str2, 6 );
sl@0
   580
   if( result < 0 )
sl@0
   581
      printf( "str1 is less than str2.
sl@0
   582
" );
sl@0
   583
   else if( result == 0 )
sl@0
   584
      printf( "str1 is equal to str2.
sl@0
   585
" );
sl@0
   586
   else if( result > 0 )
sl@0
   587
      printf( "str1 is greater than str2.
sl@0
   588
" );
sl@0
   589
   return 0;    
sl@0
   590
}
sl@0
   591
sl@0
   592
@endcode
sl@0
   593
 Output
sl@0
   594
@code
sl@0
   595
Compare ’abcdefg’ to ’abcdefr
sl@0
   596
str1 is less than str2.
sl@0
   597
Compare ’abased’ to ’abcdef
sl@0
   598
str1 is equal to str2.
sl@0
   599
sl@0
   600
@endcode
sl@0
   601
@see bcmp()
sl@0
   602
@see memcmp()
sl@0
   603
@see strcasecmp()
sl@0
   604
@see strcoll()
sl@0
   605
@see strxfrm()
sl@0
   606
sl@0
   607
sl@0
   608
 
sl@0
   609
sl@0
   610
@publishedAll
sl@0
   611
@externallyDefinedApi
sl@0
   612
*/
sl@0
   613
sl@0
   614
/** @fn  strcoll(const char *s1, const char *s2)
sl@0
   615
@param s1   
sl@0
   616
@param s2      
sl@0
   617
sl@0
   618
  This function lexicographically compares the null-terminated strings s1 and s2 according to the current locale collation, if locale is set. 
sl@0
   619
  Calls strcmp and returns an integer greater than, equal to, or less than 0, to whether s1 is greater than, equal to, or less than s2 if C locale is set.
sl@0
   620
  Otherwise it will compare the strings according to the smartphone's locale collation.
sl@0
   621
sl@0
   622
Examples:
sl@0
   623
@code
sl@0
   624
#include <string.h>
sl@0
   625
#include <stdio.h>
sl@0
   626
#include <locale.h>
sl@0
   627
int main()
sl@0
   628
{
sl@0
   629
    int res;
sl@0
   630
    setlocale(LC_ALL,"ar_AE.ISO-8859-6");
sl@0
   631
    if(strcoll("abcde","abcde")==0)
sl@0
   632
       printf("Strings are same
sl@0
   633
");
sl@0
   634
    return 0;
sl@0
   635
}
sl@0
   636
sl@0
   637
@endcode
sl@0
   638
 Output
sl@0
   639
@code
sl@0
   640
Strings are same
sl@0
   641
sl@0
   642
@endcode
sl@0
   643
@return   This  function  returns  an  integer  less than, equal to, or
sl@0
   644
greater than zero if s1 is found, respectively, to  be  less  than,  to
sl@0
   645
match,  or be greater than s2, when both are interpreted as appropriate
sl@0
   646
for the current locale.
sl@0
   647
sl@0
   648
@see setlocale()
sl@0
   649
@see strcmp()
sl@0
   650
@see strxfrm()
sl@0
   651
@see wcscoll()
sl@0
   652
sl@0
   653
sl@0
   654
 
sl@0
   655
sl@0
   656
@publishedAll
sl@0
   657
@externallyDefinedApi
sl@0
   658
*/
sl@0
   659
sl@0
   660
/** @fn  strcpy(char *  from, const char *  to)
sl@0
   661
@param from
sl@0
   662
@param to
sl@0
   663
sl@0
   664
Refer to  stpcpy() for the documentation
sl@0
   665
@see bcopy()
sl@0
   666
@see memcpy()
sl@0
   667
@see memmove()
sl@0
   668
sl@0
   669
sl@0
   670
 
sl@0
   671
sl@0
   672
@publishedAll
sl@0
   673
@externallyDefinedApi
sl@0
   674
*/
sl@0
   675
sl@0
   676
/** @fn  strcspn(const char *s, const char *charset)
sl@0
   677
@param s
sl@0
   678
@param charset
sl@0
   679
@return   The strcspn function
sl@0
   680
returns the number of characters spanned.
sl@0
   681
sl@0
   682
  The strcspn function
sl@0
   683
spans the initial part of the null-terminated string s as long as the characters from s do not occur in string charset (it
sl@0
   684
spans the complement of charset). In other words, it computes the string array index in s of the first character of s which is also in charset, else the index of the first null character.
sl@0
   685
sl@0
   686
Examples:
sl@0
   687
@code
sl@0
   688
#include <string.h>
sl@0
   689
#include <stdio.h>
sl@0
   690
int main()
sl@0
   691
{
sl@0
   692
    printf("Number of characters present in s
sl@0
   693
 which are not in charset is %d",strcspn("abcde","df"));
sl@0
   694
    return 0;
sl@0
   695
}
sl@0
   696
sl@0
   697
@endcode
sl@0
   698
 Output
sl@0
   699
@code
sl@0
   700
Number of characters present in s
sl@0
   701
 which are not in charset is 3
sl@0
   702
sl@0
   703
@endcode
sl@0
   704
@see memchr()
sl@0
   705
@see strchr()
sl@0
   706
@see strpbrk()
sl@0
   707
@see strrchr()
sl@0
   708
@see strsep()
sl@0
   709
@see strspn()
sl@0
   710
@see strstr()
sl@0
   711
@see strtok()
sl@0
   712
sl@0
   713
sl@0
   714
 
sl@0
   715
sl@0
   716
@publishedAll
sl@0
   717
@externallyDefinedApi
sl@0
   718
*/
sl@0
   719
sl@0
   720
/** @fn  strdup(const char *str)
sl@0
   721
@param str
sl@0
   722
sl@0
   723
  The strdup function
sl@0
   724
allocates sufficient memory for a copy
sl@0
   725
of the string str ,
sl@0
   726
does the copy, and returns a pointer to it.
sl@0
   727
The pointer may subsequently be used as an
sl@0
   728
argument to the function free .
sl@0
   729
sl@0
   730
 If insufficient memory is available, NULL is returned and errno is set to ENOMEM .
sl@0
   731
sl@0
   732
Examples:
sl@0
   733
@code
sl@0
   734
#include <string.h>
sl@0
   735
#include <stdio.h>
sl@0
   736
int main()
sl@0
   737
{
sl@0
   738
    char* ptr;
sl@0
   739
    ptr = (char *)strdup("abcde");
sl@0
   740
    printf("Duplicated string %s
sl@0
   741
",ptr);
sl@0
   742
    ptr = (char *)strdup("Hello Hi");
sl@0
   743
    printf("Duplicated string %s
sl@0
   744
",ptr);
sl@0
   745
    return 0;   
sl@0
   746
}
sl@0
   747
sl@0
   748
@endcode
sl@0
   749
 Output
sl@0
   750
@code
sl@0
   751
Duplicated string abcde
sl@0
   752
Duplicated string Hello Hi
sl@0
   753
sl@0
   754
@endcode
sl@0
   755
@return   The  strdup()  function  returns a pointer to the duplicated string, or
sl@0
   756
NULL if insufficient memory was available.
sl@0
   757
sl@0
   758
@see free()
sl@0
   759
@see malloc()
sl@0
   760
sl@0
   761
sl@0
   762
 
sl@0
   763
sl@0
   764
@publishedAll
sl@0
   765
@externallyDefinedApi
sl@0
   766
*/
sl@0
   767
sl@0
   768
/** @fn  strndup(const char *old, size_t sz)
sl@0
   769
@param old
sl@0
   770
@param sz
sl@0
   771
sl@0
   772
  The strndup function
sl@0
   773
allocates sufficient memory for a copy
sl@0
   774
of the string old ,
sl@0
   775
does the copy of at most sz characters, and returns a pointer to it.
sl@0
   776
If old is longer than sz, only sz characters are copied and a terminating NULL is added.
sl@0
   777
The pointer may subsequently be used as an
sl@0
   778
argument to the function free .
sl@0
   779
sl@0
   780
 If insufficient memory is available, NULL is returned and errno is set to ENOMEM .
sl@0
   781
sl@0
   782
Examples:
sl@0
   783
@code
sl@0
   784
#include <string.h>
sl@0
   785
#include <stdio.h>
sl@0
   786
#include <stdlib.h>
sl@0
   787
int main()
sl@0
   788
{
sl@0
   789
    char* ptr;
sl@0
   790
    ptr = (char *)strndup("abcde",3);
sl@0
   791
    printf("Duplicated string %s
sl@0
   792
",ptr);
sl@0
   793
    ptr = (char *)strndup("Hello Hi",5);
sl@0
   794
    printf("Duplicated string %s
sl@0
   795
",ptr);
sl@0
   796
    free(ptr);
sl@0
   797
    return 0;   
sl@0
   798
}
sl@0
   799
sl@0
   800
@endcode
sl@0
   801
 Output
sl@0
   802
@code
sl@0
   803
Duplicated string abc
sl@0
   804
Duplicated string Hello
sl@0
   805
sl@0
   806
@endcode
sl@0
   807
@return   The  strdup()  function  returns a pointer to the duplicated string, or
sl@0
   808
NULL if insufficient memory was available.
sl@0
   809
sl@0
   810
@see free()
sl@0
   811
@see malloc()
sl@0
   812
sl@0
   813
sl@0
   814
 
sl@0
   815
sl@0
   816
@publishedAll
sl@0
   817
@externallyDefinedApi
sl@0
   818
*/
sl@0
   819
sl@0
   820
/** @fn strnlen(const char *s, size_t len)
sl@0
   821
@param s
sl@0
   822
@param len
sl@0
   823
sl@0
   824
@return The  strnlen function returns strlen(s), if that is less than len, or len if there is no "\\0" character among the first len characters pointed to by s.
sl@0
   825
sl@0
   826
Examples:
sl@0
   827
@code
sl@0
   828
#include <string.h>
sl@0
   829
#include <stdio.h>
sl@0
   830
int main()
sl@0
   831
{
sl@0
   832
    char one[50];
sl@0
   833
    int ret;
sl@0
   834
    strcpy(one,"abcdef");
sl@0
   835
    ret = strnlen(one,5);
sl@0
   836
    printf("Length obtained using strnlen = %d\n",ret);
sl@0
   837
    ret = strnlen(one,10);
sl@0
   838
    printf("Length obtained using strnlen = %d\n",ret);
sl@0
   839
}
sl@0
   840
sl@0
   841
@endcode
sl@0
   842
 Output
sl@0
   843
@code
sl@0
   844
Length obtained using strnlen = 5
sl@0
   845
Length obtained using strnlen = 6
sl@0
   846
sl@0
   847
@endcode
sl@0
   848
Feedback For additional information or queries on this page send feedback
sl@0
   849
 
sl@0
   850
sl@0
   851
@publishedAll
sl@0
   852
@externallyDefinedApi
sl@0
   853
*/
sl@0
   854
sl@0
   855
sl@0
   856
/** @fn  strerror(int num)
sl@0
   857
@param num
sl@0
   858
sl@0
   859
Refer to  perror() for the documentation
sl@0
   860
@see intro()
sl@0
   861
sl@0
   862
sl@0
   863
 
sl@0
   864
sl@0
   865
@publishedAll
sl@0
   866
@externallyDefinedApi
sl@0
   867
*/
sl@0
   868
sl@0
   869
/** @fn  strerror_r(int errnum, char *strerrbuf, size_t buflen)
sl@0
   870
@param errnum
sl@0
   871
@param strerrbuf
sl@0
   872
@param buflen
sl@0
   873
sl@0
   874
Refer to  perror() for the documentation
sl@0
   875
@see intro()
sl@0
   876
sl@0
   877
sl@0
   878
 
sl@0
   879
sl@0
   880
@publishedAll
sl@0
   881
@externallyDefinedApi
sl@0
   882
*/
sl@0
   883
sl@0
   884
/** @fn  strlcat(char *dst, const char *src, size_t size)
sl@0
   885
@param dst
sl@0
   886
@param src
sl@0
   887
@param size
sl@0
   888
sl@0
   889
Refer to  strlcpy() for the documentation
sl@0
   890
@see snprintf()
sl@0
   891
@see strncat()
sl@0
   892
@see strncpy()
sl@0
   893
sl@0
   894
sl@0
   895
 
sl@0
   896
sl@0
   897
@publishedAll
sl@0
   898
@externallyDefinedApi
sl@0
   899
*/
sl@0
   900
sl@0
   901
/** @fn  strlcpy(char *dst, const char *src, size_t size)
sl@0
   902
@param dst
sl@0
   903
@param src
sl@0
   904
@param size
sl@0
   905
sl@0
   906
Note: This description also covers the following functions -
sl@0
   907
 strlcat() 
sl@0
   908
sl@0
   909
@return   The strlcpy and strlcat functions return the total length of the string they tried to
sl@0
   910
create.
sl@0
   911
For strlcpy that means the length of src .
sl@0
   912
For strlcat that means the initial length of dst plus
sl@0
   913
the length of src .
sl@0
   914
While this may seem somewhat confusing it was done to make
sl@0
   915
truncation detection simple. Note however, that if strlcat traverses size characters without finding a NULL, the length of the string is 
sl@0
   916
  considered to be size and the destination string will not be NULL-terminated (since there 
sl@0
   917
  was no space for the NULL). This prevents strlcat from running off the end of a string. In practice this should 
sl@0
   918
  not happen (as it means that either size is incorrect or that dst is not a proper "C" string). The check exists to prevent potential security problems in incorrect 
sl@0
   919
  code.
sl@0
   920
sl@0
   921
  The strlcpy and strlcat functions copy and concatenate strings respectively. They are 
sl@0
   922
designed to be safer, more consistent, and less error prone replacements for strncpy and strncat. Unlike those functions, strlcpy and strlcat take the full size of the buffer (not just the length) and guarantee 
sl@0
   923
to NULL-terminate the result (as long as size is larger than 0 or, in the case of strlcat , as long as there is at least one byte free in dst ). Note that you should include a byte for the NULL in size . Also note that strlcpy and strlcat only operate on true "C" strings. This means that for strlcpy src must be NUL-terminated and for strlcat both src and dst must be NULL-terminated.
sl@0
   924
sl@0
   925
 The strlcpy function copies up to size - 1 characters from the NULL-terminated string src to dst , NULL-terminating the result.
sl@0
   926
sl@0
   927
 The strlcat function appends the NULL-terminated string src to the end of dst . It will append at most size - strlen(dst) - 1 bytes, NULL-terminating the result.
sl@0
   928
sl@0
   929
sl@0
   930
sl@0
   931
Examples:
sl@0
   932
 The following code fragment illustrates the simple case:
sl@0
   933
@code
sl@0
   934
char *s, *p, buf[BUFSIZ];
sl@0
   935
...
sl@0
   936
(void)strlcpy(buf, s, sizeof(buf));
sl@0
   937
(void)strlcat(buf, p, sizeof(buf));
sl@0
   938
sl@0
   939
@endcode
sl@0
   940
 To detect truncation, perhaps while building a pathname, something
sl@0
   941
like the following might be used:
sl@0
   942
@code
sl@0
   943
char *dir, *file, pname[MAXPATHLEN];
sl@0
   944
...
sl@0
   945
if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname))
sl@0
   946
        goto toolong;
sl@0
   947
if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
sl@0
   948
        goto toolong;
sl@0
   949
sl@0
   950
@endcode
sl@0
   951
 Since we know how many characters we copied the first time, we can
sl@0
   952
speed things up a bit by using a copy instead of an append:
sl@0
   953
@code
sl@0
   954
char *dir, *file, pname[MAXPATHLEN];
sl@0
   955
size_t n;
sl@0
   956
...
sl@0
   957
n = strlcpy(pname, dir, sizeof(pname));
sl@0
   958
if (n >= sizeof(pname))
sl@0
   959
        goto toolong;
sl@0
   960
if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n)
sl@0
   961
        goto toolong;
sl@0
   962
sl@0
   963
@endcode
sl@0
   964
 However, one may question the validity of such optimizations, as they
sl@0
   965
defeat the whole purpose of strlcpy and strlcat .
sl@0
   966
As a matter of fact, the first version of this manual page got it wrong.
sl@0
   967
Examples:
sl@0
   968
@code
sl@0
   969
#include <string.h>
sl@0
   970
#include <stdio.h>
sl@0
   971
int main()
sl@0
   972
{
sl@0
   973
    char one[50] = {"abcdefgh"};
sl@0
   974
    printf("String before strcpy %s
sl@0
   975
",one);
sl@0
   976
    strlcpy(one,"Hello");
sl@0
   977
    printf("String after strcpy %s
sl@0
   978
",one);
sl@0
   979
    strlcpy(one + 5, " ",1);
sl@0
   980
    strlcpy(one + 6, "World",5);
sl@0
   981
    printf("String after strncpy %s
sl@0
   982
",one);
sl@0
   983
    return 0;
sl@0
   984
}
sl@0
   985
sl@0
   986
@endcode
sl@0
   987
@see snprintf()
sl@0
   988
@see strncat()
sl@0
   989
@see strncpy()
sl@0
   990
sl@0
   991
sl@0
   992
 
sl@0
   993
sl@0
   994
@publishedAll
sl@0
   995
@externallyDefinedApi
sl@0
   996
*/
sl@0
   997
sl@0
   998
/** @fn  strlen(const char *str)
sl@0
   999
@param str
sl@0
  1000
@return  The strlen() function shall return the length of s; no return value shall be reserved to indicate an error.
sl@0
  1001
sl@0
  1002
The strlen() function shall compute the number of bytes in the string to which s points,
sl@0
  1003
 not including the terminating null byte.
sl@0
  1004
sl@0
  1005
Examples:
sl@0
  1006
@code
sl@0
  1007
#include <string.h>
sl@0
  1008
#include <stdio.h>
sl@0
  1009
int main()
sl@0
  1010
{
sl@0
  1011
    char one[50];
sl@0
  1012
    int ret;
sl@0
  1013
    strcpy(one,"abcdef");
sl@0
  1014
    ret = strnlen(one,5);
sl@0
  1015
    printf("Length obtained using strnlen = %d
sl@0
  1016
",ret);
sl@0
  1017
    ret = strnlen(one,10);
sl@0
  1018
    printf("Length obtained using strnlen = %d
sl@0
  1019
",ret);
sl@0
  1020
}
sl@0
  1021
sl@0
  1022
@endcode
sl@0
  1023
 Output
sl@0
  1024
@code
sl@0
  1025
Length obtained using strnlen = 5
sl@0
  1026
Length obtained using strnlen = 6
sl@0
  1027
@endcode
sl@0
  1028
sl@0
  1029
 
sl@0
  1030
sl@0
  1031
@publishedAll
sl@0
  1032
@externallyDefinedApi
sl@0
  1033
*/
sl@0
  1034
sl@0
  1035
/** @fn  strncat(char * dst, const char * src, size_t n)
sl@0
  1036
@param dst
sl@0
  1037
@param src
sl@0
  1038
@param n
sl@0
  1039
sl@0
  1040
Refer to  strcat() for the documentation
sl@0
  1041
@see bcopy()
sl@0
  1042
@see memcpy()
sl@0
  1043
@see memmove()
sl@0
  1044
@see strcpy()
sl@0
  1045
sl@0
  1046
sl@0
  1047
 
sl@0
  1048
sl@0
  1049
@publishedAll
sl@0
  1050
@externallyDefinedApi
sl@0
  1051
*/
sl@0
  1052
sl@0
  1053
/** @fn  strncmp(const char *s1, const char *s2, size_t n)
sl@0
  1054
@param s1
sl@0
  1055
@param s2
sl@0
  1056
@param n
sl@0
  1057
sl@0
  1058
Refer to  strcmp() for the documentation
sl@0
  1059
@see bcmp()
sl@0
  1060
@see memcmp()
sl@0
  1061
@see strcasecmp()
sl@0
  1062
@see strcoll()
sl@0
  1063
@see strxfrm()
sl@0
  1064
sl@0
  1065
sl@0
  1066
 
sl@0
  1067
sl@0
  1068
@publishedAll
sl@0
  1069
@externallyDefinedApi
sl@0
  1070
*/
sl@0
  1071
sl@0
  1072
/** @fn  strncpy(char *  dst, const char *  src, size_t n)
sl@0
  1073
@param dst
sl@0
  1074
@param src
sl@0
  1075
@param n
sl@0
  1076
sl@0
  1077
Refer to  stpcpy() for the documentation
sl@0
  1078
@see bcopy()
sl@0
  1079
@see memcpy()
sl@0
  1080
@see memmove()
sl@0
  1081
sl@0
  1082
sl@0
  1083
 
sl@0
  1084
sl@0
  1085
@publishedAll
sl@0
  1086
@externallyDefinedApi
sl@0
  1087
*/
sl@0
  1088
sl@0
  1089
/** @fn  strnstr(const char *s, const char *find, size_t slen)
sl@0
  1090
@param s
sl@0
  1091
@param find
sl@0
  1092
@param slen
sl@0
  1093
sl@0
  1094
Refer to  strstr() for the documentation
sl@0
  1095
@see memchr()
sl@0
  1096
@see strchr()
sl@0
  1097
@see strcspn()
sl@0
  1098
@see strpbrk()
sl@0
  1099
@see strrchr()
sl@0
  1100
@see strsep()
sl@0
  1101
@see strspn()
sl@0
  1102
@see strtok()
sl@0
  1103
sl@0
  1104
sl@0
  1105
 
sl@0
  1106
sl@0
  1107
@publishedAll
sl@0
  1108
@externallyDefinedApi
sl@0
  1109
*/
sl@0
  1110
sl@0
  1111
/** @fn  strpbrk(const char *s1, const char *s2)
sl@0
  1112
@param s1
sl@0
  1113
@param s2
sl@0
  1114
sl@0
  1115
  The strpbrk function
sl@0
  1116
locates in the null-terminated string s1 the first occurrence of any character in the string s2 and returns a pointer to this character.
sl@0
  1117
If no characters from s2 occur anywhere in s1 strpbrk returns NULL.
sl@0
  1118
sl@0
  1119
Examples:
sl@0
  1120
@code
sl@0
  1121
#include <string.h>
sl@0
  1122
#include <stdio.h>
sl@0
  1123
int main()
sl@0
  1124
{
sl@0
  1125
    char one[50];
sl@0
  1126
    char *res;
sl@0
  1127
    strcpy(one,"acdb");
sl@0
  1128
    res = strpbrk(one, "bc");
sl@0
  1129
    if(res != NULL)
sl@0
  1130
       printf("%s
sl@0
  1131
",res);
sl@0
  1132
    return 0;
sl@0
  1133
}
sl@0
  1134
sl@0
  1135
@endcode
sl@0
  1136
 Output
sl@0
  1137
@code
sl@0
  1138
cdb
sl@0
  1139
sl@0
  1140
@endcode
sl@0
  1141
@return   The strpbrk() function returns a pointer to the  character  in  s1  that
sl@0
  1142
matches  one  of the characters in accept, or NULL if no such character
sl@0
  1143
is found.
sl@0
  1144
sl@0
  1145
@see memchr()
sl@0
  1146
@see strchr()
sl@0
  1147
@see strcspn()
sl@0
  1148
@see strsep()
sl@0
  1149
@see strspn()
sl@0
  1150
@see strstr()
sl@0
  1151
@see strtok()
sl@0
  1152
sl@0
  1153
sl@0
  1154
 
sl@0
  1155
sl@0
  1156
@publishedAll
sl@0
  1157
@externallyDefinedApi
sl@0
  1158
*/
sl@0
  1159
sl@0
  1160
/** @fn  strrchr(const char *s, int c)
sl@0
  1161
@param s
sl@0
  1162
@param c
sl@0
  1163
sl@0
  1164
Refer to  strchr() for the documentation
sl@0
  1165
@see memchr()
sl@0
  1166
@see strcspn()
sl@0
  1167
@see strpbrk()
sl@0
  1168
@see strsep()
sl@0
  1169
@see strspn()
sl@0
  1170
@see strstr()
sl@0
  1171
@see strtok()
sl@0
  1172
sl@0
  1173
sl@0
  1174
 
sl@0
  1175
sl@0
  1176
@publishedAll
sl@0
  1177
@externallyDefinedApi
sl@0
  1178
*/
sl@0
  1179
sl@0
  1180
/** @fn  strsep(char **stringp, const char *delim)
sl@0
  1181
@param stringp
sl@0
  1182
@param delim
sl@0
  1183
@return   strsep function returns a pointer to the token, i.e it returns the original value of *stringp
sl@0
  1184
sl@0
  1185
  The strsep function locates, in the string referenced by *stringp ,
sl@0
  1186
the first occurrence of any character in the string delim (or the terminating ‘\\0’
sl@0
  1187
character) and replaces it with a ‘\\0’.
sl@0
  1188
The location of the next character after the delimiter character
sl@0
  1189
(or NULL, if the end of the string was reached) is stored in *stringp .
sl@0
  1190
The original value of *stringp is returned.
sl@0
  1191
sl@0
  1192
 An "empty"
sl@0
  1193
field (i.e., a character in the string delim occurs as the first character of *stringp )
sl@0
  1194
can be detected by comparing the location referenced by the returned pointer
sl@0
  1195
to ‘\\0’.
sl@0
  1196
sl@0
  1197
 If *stringp is initially NULL , strsep returns NULL .
sl@0
  1198
sl@0
  1199
Examples:
sl@0
  1200
@code
sl@0
  1201
#include <string.h>
sl@0
  1202
#include <stdio.h>
sl@0
  1203
int main()
sl@0
  1204
{
sl@0
  1205
    char *one=(char *)malloc(12);
sl@0
  1206
    char *res;
sl@0
  1207
    char **two=&one;
sl@0
  1208
    strcpy(one,"Hello,World");
sl@0
  1209
    res=strsep(two,",");
sl@0
  1210
    if(strcmp(res,"hello"))
sl@0
  1211
    printf("%s
sl@0
  1212
",res);      
sl@0
  1213
    return 0;
sl@0
  1214
}
sl@0
  1215
sl@0
  1216
@endcode
sl@0
  1217
 Output
sl@0
  1218
@code
sl@0
  1219
Hello
sl@0
  1220
sl@0
  1221
@endcode
sl@0
  1222
@see memchr()
sl@0
  1223
@see strchr()
sl@0
  1224
@see strcspn()
sl@0
  1225
@see strpbrk()
sl@0
  1226
@see strspn()
sl@0
  1227
@see strstr()
sl@0
  1228
@see strtok()
sl@0
  1229
sl@0
  1230
sl@0
  1231
 
sl@0
  1232
sl@0
  1233
@publishedAll
sl@0
  1234
@externallyDefinedApi
sl@0
  1235
*/
sl@0
  1236
sl@0
  1237
/** @fn  strspn(const char *s, const char *charset)
sl@0
  1238
@param s
sl@0
  1239
@param charset
sl@0
  1240
@return   strspn function returns the number of characters in the initial segment of s which consists only of characters from accept
sl@0
  1241
sl@0
  1242
  The strspn function
sl@0
  1243
spans the initial part of the null-terminated string s as long as the characters from s occur in the null-terminated string charset .
sl@0
  1244
In other words, it computes the string array index in s of the first character of s which is not in charset ,
sl@0
  1245
else the index of the first null character.
sl@0
  1246
sl@0
  1247
Examples:
sl@0
  1248
@code
sl@0
  1249
#include <string.h>
sl@0
  1250
#include <stdio.h>
sl@0
  1251
int main()
sl@0
  1252
{
sl@0
  1253
    char one[50];
sl@0
  1254
    int res;
sl@0
  1255
    strcpy(one,"abcba");
sl@0
  1256
    res = strspn(one, "abc");
sl@0
  1257
    printf(" %d times characters found in the string 
sl@0
  1258
",res);
sl@0
  1259
    return 0;
sl@0
  1260
}
sl@0
  1261
sl@0
  1262
@endcode
sl@0
  1263
 Output
sl@0
  1264
@code
sl@0
  1265
5 times characters found in the string
sl@0
  1266
sl@0
  1267
@endcode
sl@0
  1268
@return   The strspn function
sl@0
  1269
returns the number of characters spanned.
sl@0
  1270
sl@0
  1271
@see memchr()
sl@0
  1272
@see strchr()
sl@0
  1273
@see strpbrk()
sl@0
  1274
@see strsep()
sl@0
  1275
@see strstr()
sl@0
  1276
@see strtok()
sl@0
  1277
sl@0
  1278
sl@0
  1279
 
sl@0
  1280
sl@0
  1281
@publishedAll
sl@0
  1282
@externallyDefinedApi
sl@0
  1283
*/
sl@0
  1284
sl@0
  1285
/** @fn  strstr(const char *s, const char *find)
sl@0
  1286
@param s
sl@0
  1287
@param find
sl@0
  1288
sl@0
  1289
Note: This description also covers the following functions -
sl@0
  1290
 strcasestr()  strnstr() 
sl@0
  1291
sl@0
  1292
@return   The strstr function returns a pointer to the beginning of the substring, or NULL if the substring is not found.If find is an empty string, s is returned;
sl@0
  1293
if find occurs nowhere in s , NULL is returned;
sl@0
  1294
otherwise a pointer to the first character of the first occurrence of find is returned.
sl@0
  1295
sl@0
  1296
sl@0
  1297
  The strstr function
sl@0
  1298
locates the first occurrence of the null-terminated string find in the null-terminated string s .
sl@0
  1299
sl@0
  1300
 The strcasestr function is similar to strstr ,
sl@0
  1301
but ignores the case of both strings.
sl@0
  1302
sl@0
  1303
 The strnstr function
sl@0
  1304
locates the first occurrence of the null-terminated string find in the string s ,
sl@0
  1305
where not more than slen characters are searched.
sl@0
  1306
Characters that appear after a ‘\\0’
sl@0
  1307
character are not searched.
sl@0
  1308
Since the strnstr function is a specific API, it should only be used when portability is not a concern.
sl@0
  1309
sl@0
  1310
Examples:
sl@0
  1311
@code
sl@0
  1312
#include <string.h>
sl@0
  1313
#include <stdio.h>
sl@0
  1314
int main()
sl@0
  1315
{
sl@0
  1316
    char *ptr;
sl@0
  1317
    ptr = strstr("abcd", "z");
sl@0
  1318
    if(ptr == NULL)
sl@0
  1319
       printf("strstr: \"z\" not found in \"abcd\"
sl@0
  1320
");
sl@0
  1321
    else
sl@0
  1322
       printf("strstr: \"z\" found in \"abcd\"
sl@0
  1323
");
sl@0
  1324
    ptr = strstr("abcd", "ab");
sl@0
  1325
    if(ptr == NULL)
sl@0
  1326
       printf("strstr: \"ab\" not found in \"abcd\"
sl@0
  1327
");
sl@0
  1328
    else
sl@0
  1329
       printf("strstr: \"ab\" found in \"abcd\"
sl@0
  1330
");
sl@0
  1331
    ptr = strstr("abcd", "abcde");
sl@0
  1332
    if(ptr == NULL)
sl@0
  1333
       printf("strstr: \"abcde\" found in \"abcd\"
sl@0
  1334
");
sl@0
  1335
    else
sl@0
  1336
       printf("strstr: \"abbcde\" not found in \"abcd\"
sl@0
  1337
");
sl@0
  1338
    return 0;
sl@0
  1339
}
sl@0
  1340
sl@0
  1341
@endcode
sl@0
  1342
 Output
sl@0
  1343
@code
sl@0
  1344
strstr: "z" not found in "abcd"
sl@0
  1345
strstr: "ab" found in "abcd"
sl@0
  1346
strstr: "abcde" found in "abcd"
sl@0
  1347
sl@0
  1348
@endcode
sl@0
  1349
Examples:
sl@0
  1350
 The following sets the pointer ptr to the "Bar Baz"
sl@0
  1351
portion of largestring :
sl@0
  1352
@code
sl@0
  1353
const char *largestring = "Foo Bar Baz";
sl@0
  1354
const char *smallstring = "Bar";
sl@0
  1355
char *ptr;
sl@0
  1356
ptr = strstr(largestring, smallstring);
sl@0
  1357
sl@0
  1358
@endcode
sl@0
  1359
 The following sets the pointer ptr to NULL ,
sl@0
  1360
because only the first 4 characters of largestring are searched:
sl@0
  1361
@code
sl@0
  1362
const char *largestring = "Foo Bar Baz";
sl@0
  1363
const char *smallstring = "Bar";
sl@0
  1364
char *ptr;
sl@0
  1365
ptr = strnstr(largestring, smallstring, 4);
sl@0
  1366
sl@0
  1367
@endcode
sl@0
  1368
@see memchr()
sl@0
  1369
@see strchr()
sl@0
  1370
@see strcspn()
sl@0
  1371
@see strpbrk()
sl@0
  1372
@see strrchr()
sl@0
  1373
@see strsep()
sl@0
  1374
@see strspn()
sl@0
  1375
@see strtok()
sl@0
  1376
sl@0
  1377
sl@0
  1378
 
sl@0
  1379
sl@0
  1380
@publishedAll
sl@0
  1381
@externallyDefinedApi
sl@0
  1382
*/
sl@0
  1383
sl@0
  1384
/** @fn  strtok(char *s, const char *delim)
sl@0
  1385
@param s
sl@0
  1386
@param delim
sl@0
  1387
sl@0
  1388
Note: This description also covers the following functions -
sl@0
  1389
 strtok_r() 
sl@0
  1390
sl@0
  1391
@return   strtok function returns a pointer to the next token, or NULL if there are no more tokens.
sl@0
  1392
sl@0
  1393
  This interface is superceded by strsep .
sl@0
  1394
sl@0
  1395
 The strtok function
sl@0
  1396
is used to isolate sequential tokens in a null-terminated string, s .
sl@0
  1397
These tokens are separated in the string by at least one of the
sl@0
  1398
characters in delim .
sl@0
  1399
The first time that strtok is called, s should be specified; subsequent calls, wishing to obtain further tokens
sl@0
  1400
from the same string, should pass a null pointer instead.
sl@0
  1401
The separator string, delim ,
sl@0
  1402
must be supplied each time, and may change between calls.
sl@0
  1403
sl@0
  1404
 The implementation will behave as if no library function calls strtok .
sl@0
  1405
sl@0
  1406
 The strtok_r function is a reentrant version of strtok .
sl@0
  1407
The context pointer last must be provided on each call.
sl@0
  1408
The strtok_r function
sl@0
  1409
may also be used to nest two parsing loops within one another, as
sl@0
  1410
long as separate context pointers are used.
sl@0
  1411
sl@0
  1412
 The strtok and strtok_r functions
sl@0
  1413
return a pointer to the beginning of each subsequent token in the string,
sl@0
  1414
after replacing the token itself with a NUL character.
sl@0
  1415
When no more tokens remain, a null pointer is returned.
sl@0
  1416
sl@0
  1417
Examples:
sl@0
  1418
@code
sl@0
  1419
#include <string.h>
sl@0
  1420
#include <stdio.h>
sl@0
  1421
int main()
sl@0
  1422
{
sl@0
  1423
    char one[50];
sl@0
  1424
    char *res;
sl@0
  1425
    strcpy(one,"Hello,World,Hi");
sl@0
  1426
    res=strtok(one,",");
sl@0
  1427
    if(!strcmp(res,"Hello"))
sl@0
  1428
    printf("%s
sl@0
  1429
",res);
sl@0
  1430
    res=strtok(NULL,",");
sl@0
  1431
    if(!strcmp(res,"World"))
sl@0
  1432
    printf("%s
sl@0
  1433
",res);
sl@0
  1434
    return 0;
sl@0
  1435
}
sl@0
  1436
sl@0
  1437
@endcode
sl@0
  1438
 Output
sl@0
  1439
@code
sl@0
  1440
Hello
sl@0
  1441
World
sl@0
  1442
sl@0
  1443
@endcode
sl@0
  1444
@see memchr()
sl@0
  1445
@see strchr()
sl@0
  1446
@see strcspn()
sl@0
  1447
@see strpbrk()
sl@0
  1448
@see strsep()
sl@0
  1449
@see strspn()
sl@0
  1450
@see strstr()
sl@0
  1451
@see wcstok()
sl@0
  1452
sl@0
  1453
sl@0
  1454
Bugs:
sl@0
  1455
sl@0
  1456
 The System V strtok ,
sl@0
  1457
if handed a string containing only delimiter characters,
sl@0
  1458
will not alter the next starting point, so that a call to strtok with a different (or empty) delimiter string
sl@0
  1459
may return a non- NULL value.
sl@0
  1460
Since this implementation always alters the next starting point,
sl@0
  1461
such a sequence of calls would always return NULL . 
sl@0
  1462
 
sl@0
  1463
sl@0
  1464
@publishedAll
sl@0
  1465
@externallyDefinedApi
sl@0
  1466
*/
sl@0
  1467
sl@0
  1468
/** @fn  strtok_r(char *s1, const char *s2, char **lasts)
sl@0
  1469
@param s1
sl@0
  1470
@param s2
sl@0
  1471
@param lasts
sl@0
  1472
sl@0
  1473
Refer to  strtok() for the documentation
sl@0
  1474
@see memchr()
sl@0
  1475
@see strchr()
sl@0
  1476
@see strcspn()
sl@0
  1477
@see strpbrk()
sl@0
  1478
@see strsep()
sl@0
  1479
@see strspn()
sl@0
  1480
@see strstr()
sl@0
  1481
@see wcstok()
sl@0
  1482
sl@0
  1483
sl@0
  1484
 
sl@0
  1485
sl@0
  1486
@publishedAll
sl@0
  1487
@externallyDefinedApi
sl@0
  1488
*/
sl@0
  1489
sl@0
  1490
/** @fn  strxfrm(char *  dest, const char *  src, size_t n)
sl@0
  1491
@param dest
sl@0
  1492
@param src
sl@0
  1493
@param n
sl@0
  1494
@return   Upon successful completion, strxfrm returns the length of the transformed string not including
sl@0
  1495
the terminating null character.
sl@0
  1496
If this value is n or more, the contents of dst are indeterminate.
sl@0
  1497
sl@0
  1498
  The strxfrm function transforms a null-terminated string pointed to by src according to the current locale collation if any,
sl@0
  1499
then copies the transformed string
sl@0
  1500
into dst .
sl@0
  1501
Not more than n characters are copied into dst ,
sl@0
  1502
including the terminating null character added.
sl@0
  1503
If n is set to 0
sl@0
  1504
(it helps to determine an actual size needed
sl@0
  1505
for transformation), dst is permitted to be a NULL pointer.
sl@0
  1506
sl@0
  1507
 Comparing two strings using strcmp after strxfrm is equal to comparing
sl@0
  1508
two original strings with strcoll .
sl@0
  1509
sl@0
  1510
Examples:
sl@0
  1511
@code
sl@0
  1512
#include <string.h>
sl@0
  1513
#include <stdio.h>
sl@0
  1514
int main()
sl@0
  1515
{
sl@0
  1516
    char src2[20] = "abc";
sl@0
  1517
    char dst1[20] = {’\0’};
sl@0
  1518
    char src1[20] = "abc";
sl@0
  1519
    char dst2[20] = {’\0’};
sl@0
  1520
    int retx1;
sl@0
  1521
    int retx2;
sl@0
  1522
    int retc;
sl@0
  1523
    retx1 = strxfrm(dst1,src1,strlen(src1));
sl@0
  1524
    retx2 = strxfrm(dst2,src2,strlen(src2));
sl@0
  1525
    if((retc = strcmp(dst1,dst2))== 0)
sl@0
  1526
        printf("Strings are same
sl@0
  1527
");
sl@0
  1528
}
sl@0
  1529
sl@0
  1530
@endcode
sl@0
  1531
 Output
sl@0
  1532
@code
sl@0
  1533
Strings are same
sl@0
  1534
sl@0
  1535
@endcode
sl@0
  1536
@see setlocale()
sl@0
  1537
@see strcmp()
sl@0
  1538
@see strcoll()
sl@0
  1539
@see wcsxfrm()
sl@0
  1540
sl@0
  1541
sl@0
  1542
 
sl@0
  1543
sl@0
  1544
@publishedAll
sl@0
  1545
@externallyDefinedApi
sl@0
  1546
*/
sl@0
  1547
sl@0
  1548
/** @fn  swab(const void *from, void *to, ssize_t len)
sl@0
  1549
@param from
sl@0
  1550
@param to
sl@0
  1551
@param len
sl@0
  1552
sl@0
  1553
  The function swab copies len bytes from the location referenced by from to the location referenced by to ,
sl@0
  1554
swapping adjacent bytes.
sl@0
  1555
sl@0
  1556
 The argument len must be an even number.
sl@0
  1557
sl@0
  1558
Examples:
sl@0
  1559
@code
sl@0
  1560
#include <string.h>
sl@0
  1561
#include <stdio.h>
sl@0
  1562
int main()
sl@0
  1563
{
sl@0
  1564
    int i=0x00003366,j=0x0;
sl@0
  1565
    swab((void *)&i;,(void *)&j;,2);
sl@0
  1566
    if(j==0x6633)
sl@0
  1567
       printf("Ouput val = %#x
sl@0
  1568
",j);
sl@0
  1569
    return 0;
sl@0
  1570
}
sl@0
  1571
sl@0
  1572
@endcode
sl@0
  1573
 Output
sl@0
  1574
@code
sl@0
  1575
Ouput val = 0x6633
sl@0
  1576
sl@0
  1577
@endcode
sl@0
  1578
@see bzero()
sl@0
  1579
@see memset()
sl@0
  1580
sl@0
  1581
sl@0
  1582
 
sl@0
  1583
sl@0
  1584
@publishedAll
sl@0
  1585
@externallyDefinedApi
sl@0
  1586
*/
sl@0
  1587