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

 1 kumpf 1.2 /*
 2           //%2006////////////////////////////////////////////////////////////////////////
 3           //
 4           // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 5           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 6           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
 7           // IBM Corp.; EMC Corporation, The Open Group.
 8           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
 9           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
10           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
11           // EMC Corporation; VERITAS Software Corporation; The Open Group.
12           // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
13           // EMC Corporation; Symantec Corporation; The Open Group.
14           //
15           // Permission is hereby granted, free of charge, to any person obtaining a copy
16           // of this software and associated documentation files (the "Software"), to
17           // deal in the Software without restriction, including without limitation the
18           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19           // sell copies of the Software, and to permit persons to whom the Software is
20           // furnished to do so, subject to the following conditions:
21           // 
22 kumpf 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
23           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
24           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
25           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
26           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30           //
31           //%/////////////////////////////////////////////////////////////////////////////
32           */
33           
34           #ifndef _Executor_Strlcat_h
35           #define _Executor_Strlcat_h
36           
37           #include <stdlib.h>
38           
39           /*
40           **==============================================================================
41           **
42           ** Strlcat()
43 kumpf 1.2 **
44           **     This is an original implementation of the strlcat() function as described
45           **     by Todd C. Miller in his popular security paper entitled "strlcpy and
46           **     strlcat - consistent, safe, string copy and concatenation".
47           **
48           **     Note that this implementation favors readability over efficiency. More
49           **     efficient implementations are possible but would be too complicated
50           **     to verify in a security audit.
51           **
52           **==============================================================================
53           */
54           
55           static size_t Strlcat(char* dest, const char* src, size_t size)
56           {
57               size_t i;
58               size_t j;
59           
60               /* Find dest null terminator. */
61           
62               for (i = 0; i < size && dest[i]; i++)
63                   ;
64 kumpf 1.2 
65               /* If no-null terminator found, return size. */
66           
67               if (i == size)
68 kumpf 1.3     {
69                   int j = 0;
70                   while (src[j])
71                   {
72                       j++;
73                   }
74                   return size + j;
75               }
76 kumpf 1.2 
77               /* Copy src characters to dest. */
78           
79               for (j = 0; src[j] && i + 1 < size; i++, j++)
80                   dest[i] = src[j];
81           
82 kumpf 1.3     /* Null terminate the destination.  We are guaranteed that size is
83                * non-zero, because the (i == size) condition above is always true
84                * when size is zero.
85                */
86 kumpf 1.2 
87 kumpf 1.3     dest[i] = '\0';
88 kumpf 1.2 
89               while (src[j])
90               {
91                   j++;
92                   i++;
93               }
94           
95               return i;
96           }
97           
98           #endif /* _Executor_Strlcat_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2