Mercurial > ecos
annotate packages/language/c/libc/current/src/string/strncat.cxx @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children |
| rev | line source |
|---|---|
| 0 | 1 //=========================================================================== |
| 2 // | |
| 3 // strncat.cxx | |
| 4 // | |
| 5 // ANSI standard strncat() 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 |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
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 |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
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 char * | |
| 65 strncat( char *s1, const char *s2, size_t n ) \ | |
| 66 CYGPRI_LIBC_WEAK_ALIAS("_strncat"); | |
| 67 | |
| 68 // FUNCTIONS | |
| 69 | |
| 70 char * | |
| 71 _strncat( char *s1, const char *s2, size_t n) | |
| 72 { | |
| 73 CYG_REPORT_FUNCNAMETYPE( "_strncat", "returning %08x" ); | |
| 74 CYG_REPORT_FUNCARG3( "s1=%08x, s2=%08x, n=%d", s1, s2, n ); | |
| 75 | |
| 76 CYG_CHECK_DATA_PTR( s1, "s1 is not a valid pointer!" ); | |
| 77 CYG_CHECK_DATA_PTR( s2, "s2 is not a valid pointer!" ); | |
| 78 | |
| 79 #if defined(CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST) || defined(__OPTIMIZE_SIZE__) | |
| 80 char *s = s1; | |
| 81 | |
| 82 while (*s1) | |
| 83 s1++; | |
| 84 while (n-- != 0 && (*s1++ = *s2++)) | |
| 85 { | |
| 86 if (n == 0) | |
| 87 *s1 = '\0'; | |
| 88 } | |
| 89 | |
| 90 CYG_REPORT_RETVAL( s ); | |
| 91 | |
| 92 return s; | |
| 93 #else | |
| 94 char *s = s1; | |
| 95 | |
| 96 // Skip over the data in s1 as quickly as possible. | |
| 97 if (!CYG_LIBC_STR_UNALIGNED (s1)) | |
| 98 { | |
| 99 CYG_WORD *aligned_s1 = (CYG_WORD *)s1; | |
| 100 while (!CYG_LIBC_STR_DETECTNULL (*aligned_s1)) | |
| 101 aligned_s1++; | |
| 102 | |
| 103 s1 = (char *)aligned_s1; | |
| 104 } | |
| 105 | |
| 106 while (*s1) | |
| 107 s1++; | |
| 108 | |
| 109 // s1 now points to the its trailing null character, now copy | |
| 110 // up to N bytes from S2 into S1 stopping if a NULL is encountered | |
| 111 // in S2. | |
| 112 // | |
| 113 // It is not safe to use strncpy here since it copies EXACTLY N | |
| 114 // characters, NULL padding if necessary. | |
| 115 | |
| 116 while (n-- != 0 && (*s1++ = *s2++)) | |
| 117 { | |
| 118 if (n == 0) | |
| 119 *s1 = '\0'; | |
| 120 } | |
| 121 | |
| 122 CYG_REPORT_RETVAL( s ); | |
| 123 | |
| 124 return s; | |
| 125 #endif // not defined(CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST) || | |
| 126 // defined(__OPTIMIZE_SIZE__) | |
| 127 } // _strncat() | |
| 128 | |
| 129 #endif // ifdef CYGPKG_LIBC | |
| 130 | |
| 131 // EOF strncat.cxx |
