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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
1 //===========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
2 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
3 // strncat.cxx
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
4 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
5 // ANSI standard strncat() routine
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
6 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
7 //===========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
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
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
30 //####COPYRIGHTEND####
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
31 //===========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
32 //#####DESCRIPTIONBEGIN####
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
33 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
34 // Author(s): jlarmour
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
35 // Contributors: jlarmour
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
36 // Date: 1998-02-13
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
37 // Purpose:
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
38 // Description:
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
39 // Usage:
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
40 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
41 //####DESCRIPTIONEND####
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
42 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
43 //===========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
44
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
45 // CONFIGURATION
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
46
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
47 #include <pkgconf/libc.h> // Configuration header
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
48
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
49 // Include the C library?
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
50 #ifdef CYGPKG_LIBC
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
51
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
52 // INCLUDES
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
53
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
54 #include <cyg/infra/cyg_type.h> // Common type definitions
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
55 #include <cyg/infra/cyg_trac.h> // Tracing support
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
56 #include <cyg/infra/cyg_ass.h> // Assertion support
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
57 #include <string.h> // Header for this file
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
58 #include <stddef.h> // Compiler definitions such as size_t, NULL etc.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
59 #include "clibincl/stringsupp.hxx" // Useful string function support and
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
60 // prototypes
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
61
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
62 // EXPORTED SYMBOLS
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
63
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
64 externC char *
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
65 strncat( char *s1, const char *s2, size_t n ) \
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
66 CYGPRI_LIBC_WEAK_ALIAS("_strncat");
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
67
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
68 // FUNCTIONS
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
69
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
70 char *
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
71 _strncat( char *s1, const char *s2, size_t n)
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
72 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
73 CYG_REPORT_FUNCNAMETYPE( "_strncat", "returning %08x" );
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
74 CYG_REPORT_FUNCARG3( "s1=%08x, s2=%08x, n=%d", s1, s2, n );
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
75
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
76 CYG_CHECK_DATA_PTR( s1, "s1 is not a valid pointer!" );
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
77 CYG_CHECK_DATA_PTR( s2, "s2 is not a valid pointer!" );
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
78
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
79 #if defined(CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST) || defined(__OPTIMIZE_SIZE__)
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
80 char *s = s1;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
81
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
82 while (*s1)
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
83 s1++;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
84 while (n-- != 0 && (*s1++ = *s2++))
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
85 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
86 if (n == 0)
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
87 *s1 = '\0';
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
88 }
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
89
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
90 CYG_REPORT_RETVAL( s );
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
91
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
92 return s;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
93 #else
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
94 char *s = s1;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
95
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
96 // Skip over the data in s1 as quickly as possible.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
97 if (!CYG_LIBC_STR_UNALIGNED (s1))
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
98 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
99 CYG_WORD *aligned_s1 = (CYG_WORD *)s1;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
100 while (!CYG_LIBC_STR_DETECTNULL (*aligned_s1))
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
101 aligned_s1++;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
102
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
103 s1 = (char *)aligned_s1;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
104 }
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
105
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
106 while (*s1)
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
107 s1++;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
108
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
109 // s1 now points to the its trailing null character, now copy
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
110 // up to N bytes from S2 into S1 stopping if a NULL is encountered
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
111 // in S2.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
112 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
113 // It is not safe to use strncpy here since it copies EXACTLY N
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
114 // characters, NULL padding if necessary.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
115
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
116 while (n-- != 0 && (*s1++ = *s2++))
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
117 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
118 if (n == 0)
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
119 *s1 = '\0';
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
120 }
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
121
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
122 CYG_REPORT_RETVAL( s );
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
123
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
124 return s;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
125 #endif // not defined(CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST) ||
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
126 // defined(__OPTIMIZE_SIZE__)
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
127 } // _strncat()
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
128
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
129 #endif // ifdef CYGPKG_LIBC
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
130
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
131 // EOF strncat.cxx