xref: /reactos/sdk/lib/crt/string/string.c (revision 84ccccab)
1 /*
2  * PROJECT:         ReactOS CRT library
3  * LICENSE:         LGPL - See COPYING in the top level directory
4  * FILE:            lib/sdk/crt/string/string.c
5  * PURPOSE:         string CRT functions
6  * PROGRAMMERS:     Wine team
7  *                  Ported to ReactOS by Christoph von Wittich (christoph_vw@reactos.org)
8  */
9 
10 /*
11  * msvcrt.dll string functions
12  *
13  * Copyright 1996,1998 Marcus Meissner
14  * Copyright 1996 Jukka Iivonen
15  * Copyright 1997,2000 Uwe Bonnes
16  * Copyright 2000 Jon Griffiths
17  *
18  * This library is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU Lesser General Public
20  * License as published by the Free Software Foundation; either
21  * version 2.1 of the License, or (at your option) any later version.
22  *
23  * This library is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26  * Lesser General Public License for more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public
29  * License along with this library; if not, write to the Free Software
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31  */
32 
33 
34 #include <precomp.h>
35 
36 
37 /*********************************************************************
38  *      strcat_s (MSVCRT.@)
39  */
40 int CDECL strcat_s( char* dst, size_t elem, const char* src )
41 {
42     size_t i, j;
43     if(!dst) return EINVAL;
44     if(elem == 0) return EINVAL;
45     if(!src)
46     {
47         dst[0] = '\0';
48         return EINVAL;
49     }
50 
51     for(i = 0; i < elem; i++)
52     {
53         if(dst[i] == '\0')
54         {
55             for(j = 0; (j + i) < elem; j++)
56             {
57                 if((dst[j + i] = src[j]) == '\0') return 0;
58             }
59         }
60     }
61     /* Set the first element to 0, not the first element after the skipped part */
62     dst[0] = '\0';
63     return ERANGE;
64 }
65 
66 /*********************************************************************
67  *      strcpy_s (MSVCRT.@)
68  */
69 int CDECL strcpy_s( char* dst, size_t elem, const char* src )
70 {
71     size_t i;
72     if(!elem) return EINVAL;
73     if(!dst) return EINVAL;
74     if(!src)
75     {
76         dst[0] = '\0';
77         return EINVAL;
78     }
79 
80     for(i = 0; i < elem; i++)
81     {
82         if((dst[i] = src[i]) == '\0') return 0;
83     }
84     dst[0] = '\0';
85     return ERANGE;
86 }
87 
88