(file) Return to Strlcat.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Executor

 1 kumpf 1.2 /*
 2 martin 1.5 //%LICENSE////////////////////////////////////////////////////////////////
 3 martin 1.6 //
 4 martin 1.5 // Licensed to The Open Group (TOG) under one or more contributor license
 5            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
 6            // this work for additional information regarding copyright ownership.
 7            // Each contributor licenses this file to you under the OpenPegasus Open
 8            // Source License; you may not use this file except in compliance with the
 9            // License.
10 martin 1.6 //
11 martin 1.5 // Permission is hereby granted, free of charge, to any person obtaining a
12            // copy of this software and associated documentation files (the "Software"),
13            // to deal in the Software without restriction, including without limitation
14            // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15            // and/or sell copies of the Software, and to permit persons to whom the
16            // Software is furnished to do so, subject to the following conditions:
17 martin 1.6 //
18 martin 1.5 // The above copyright notice and this permission notice shall be included
19            // in all copies or substantial portions of the Software.
20 martin 1.6 //
21 martin 1.5 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 martin 1.6 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 martin 1.5 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24            // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25            // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26            // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27            // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 martin 1.6 //
29 martin 1.5 //////////////////////////////////////////////////////////////////////////
30 kumpf  1.2 */
31            
32            #ifndef _Executor_Strlcat_h
33            #define _Executor_Strlcat_h
34            
35            #include <stdlib.h>
36            
37            /*
38            **==============================================================================
39            **
40            ** Strlcat()
41            **
42            **     This is an original implementation of the strlcat() function as described
43            **     by Todd C. Miller in his popular security paper entitled "strlcpy and
44            **     strlcat - consistent, safe, string copy and concatenation".
45            **
46            **     Note that this implementation favors readability over efficiency. More
47            **     efficient implementations are possible but would be too complicated
48            **     to verify in a security audit.
49            **
50            **==============================================================================
51 kumpf  1.2 */
52            
53            static size_t Strlcat(char* dest, const char* src, size_t size)
54            {
55                size_t i;
56                size_t j;
57            
58                /* Find dest null terminator. */
59            
60                for (i = 0; i < size && dest[i]; i++)
61                    ;
62            
63                /* If no-null terminator found, return size. */
64            
65                if (i == size)
66 kumpf  1.3     {
67 kumpf  1.4         int k = 0;
68                    while (src[k])
69 kumpf  1.3         {
70 kumpf  1.4             k++;
71 kumpf  1.3         }
72 kumpf  1.4         return size + k;
73 kumpf  1.3     }
74 kumpf  1.2 
75                /* Copy src characters to dest. */
76            
77                for (j = 0; src[j] && i + 1 < size; i++, j++)
78                    dest[i] = src[j];
79            
80 kumpf  1.3     /* Null terminate the destination.  We are guaranteed that size is
81                 * non-zero, because the (i == size) condition above is always true
82                 * when size is zero.
83                 */
84 kumpf  1.2 
85 kumpf  1.3     dest[i] = '\0';
86 kumpf  1.2 
87                while (src[j])
88                {
89                    j++;
90                    i++;
91                }
92            
93                return i;
94            }
95            
96            #endif /* _Executor_Strlcat_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2