Mercurial > flash_v2
annotate packages/language/c/libc/current/src/string/strlen.cxx @ 64:c38311975d4f ecos-sw-2000-01-28
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
| author | jlarmour |
|---|---|
| date | Fri, 28 Jan 2000 04:59:39 +0000 |
| parents | 443894e2e912 |
| children | bf00f99aec69 |
| rev | line source |
|---|---|
| 0 | 1 //=========================================================================== |
| 2 // | |
| 3 // strlen.cxx | |
| 4 // | |
| 5 // ANSI standard strlen() routine | |
| 6 // | |
| 7 //=========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
14 // http://sourceware.cygnus.com/ecos |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
16 // Software distributed under the License is distributed on an |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //=========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): jlarmour | |
| 2 | 35 // Contributors: jlarmour |
| 0 | 36 // Date: 1998-02-13 |
| 37 // Purpose: | |
| 38 // Description: | |
| 39 // Usage: | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 // | |
| 43 //=========================================================================== | |
| 44 | |
| 45 // CONFIGURATION | |
| 46 | |
| 47 #include <pkgconf/libc.h> // Configuration header | |
| 48 | |
| 49 // Include the C library? | |
| 50 #ifdef CYGPKG_LIBC | |
| 51 | |
| 52 // INCLUDES | |
| 53 | |
| 54 #include <cyg/infra/cyg_type.h> // Common type definitions | |
| 55 #include <cyg/infra/cyg_trac.h> // Tracing support | |
| 56 #include <cyg/infra/cyg_ass.h> // Assertion support | |
| 57 #include <string.h> // Header for this file | |
| 58 #include <stddef.h> // Compiler definitions such as size_t, NULL etc. | |
| 59 #include "clibincl/stringsupp.hxx" // Useful string function support and | |
| 60 // prototypes | |
| 61 | |
| 62 // EXPORTED SYMBOLS | |
| 63 | |
| 64 externC size_t | |
| 65 strlen( const char *s ) CYGPRI_LIBC_WEAK_ALIAS("_strlen"); | |
| 66 | |
| 67 // FUNCTIONS | |
| 68 | |
| 69 size_t | |
| 70 _strlen( const char *s ) | |
| 71 { | |
| 72 int retval; | |
| 73 | |
| 74 CYG_REPORT_FUNCNAMETYPE( "_strlen", "returning length %d" ); | |
| 75 CYG_REPORT_FUNCARG1( "s=%08x", s ); | |
| 76 | |
| 77 CYG_CHECK_DATA_PTR( s, "s is not a valid pointer!" ); | |
| 78 | |
| 79 #if defined(CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST) || defined(__OPTIMIZE_SIZE__) | |
| 80 const char *start = s; | |
| 81 | |
| 82 while (*s) | |
| 83 s++; | |
| 84 | |
| 85 retval = s - start; | |
| 86 | |
| 87 CYG_REPORT_RETVAL( retval ); | |
| 88 | |
| 89 return retval; | |
| 90 | |
| 91 #else | |
| 92 | |
| 93 const char *start = s; | |
| 94 CYG_WORD *aligned_addr; | |
| 95 | |
| 96 if (CYG_LIBC_STR_UNALIGNED (s)) | |
| 97 { | |
| 98 while (*s) | |
| 99 s++; | |
| 100 retval = s - start; | |
| 101 | |
| 102 CYG_REPORT_RETVAL( retval ); | |
| 103 | |
| 104 return retval; | |
| 105 } | |
| 106 | |
| 107 // If the string is word-aligned, we can check for the presence of | |
| 108 // a null in each word-sized block. | |
| 109 | |
| 110 aligned_addr = (CYG_WORD *)s; | |
| 111 while (!CYG_LIBC_STR_DETECTNULL (*aligned_addr)) | |
| 112 aligned_addr++; | |
| 113 | |
| 114 // Once a null is detected, we check each byte in that block for a | |
| 115 // precise position of the null. | |
| 116 s = (char*)aligned_addr; | |
| 117 while (*s) | |
| 118 s++; | |
| 119 retval = s - start; | |
| 120 | |
| 121 CYG_REPORT_RETVAL( retval ); | |
| 122 | |
| 123 return retval; | |
| 124 #endif // not defined(CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST) || | |
| 125 // defined(__OPTIMIZE_SIZE__) | |
| 126 } // _strlen() | |
| 127 | |
| 128 #endif // ifdef CYGPKG_LIBC | |
| 129 | |
| 130 // EOF strlen.cxx |
