| 1 | ////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 2 | // File     : string.c | 
|---|
| 3 | // Date     : 23/05/2013 | 
|---|
| 4 | // Author   : Alexandre JOANNOU, Laurent LAMBERT | 
|---|
| 5 | // Copyright (c) UPMC-LIP6 | 
|---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 7 |  | 
|---|
| 8 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 9 | // char * strcpy ( char * destination, const char * source ) | 
|---|
| 10 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 11 | char * strcpy ( char * destination, const char * source ) | 
|---|
| 12 | { | 
|---|
| 13 | if (!destination || !source) | 
|---|
| 14 | return destination; | 
|---|
| 15 |  | 
|---|
| 16 | while (*source) | 
|---|
| 17 | *(destination++) = *(source++); | 
|---|
| 18 |  | 
|---|
| 19 | return destination; | 
|---|
| 20 | } | 
|---|
| 21 |  | 
|---|
| 22 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 23 | // int strcmp ( const char * str1, const char * str2 ) | 
|---|
| 24 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 25 | int strcmp ( const char * str1, const char * str2 ) | 
|---|
| 26 | { | 
|---|
| 27 | if (!str1 || !str2) | 
|---|
| 28 | return -123456; // return a value out of the char's bounds | 
|---|
| 29 |  | 
|---|
| 30 | while (*str1 && *str1 == *str2) | 
|---|
| 31 | { | 
|---|
| 32 | str1++; | 
|---|
| 33 | str2++; | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | return (*str1 - *str2); | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 40 | // int strlen ( const char * str ) | 
|---|
| 41 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 42 | int strlen ( const char * str ) | 
|---|
| 43 | { | 
|---|
| 44 | const char *s = str; | 
|---|
| 45 |  | 
|---|
| 46 | while (*s) | 
|---|
| 47 | s++; | 
|---|
| 48 |  | 
|---|
| 49 | return (s - str); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | // Local Variables: | 
|---|
| 53 | // tab-width: 4 | 
|---|
| 54 | // c-basic-offset: 4 | 
|---|
| 55 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) | 
|---|
| 56 | // indent-tabs-mode: nil | 
|---|
| 57 | // End: | 
|---|
| 58 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|