Cast time_t to long for printing.
[wine] / memory / string.c
1 /*
2  * String functions
3  *
4  * Copyright 1993 Yngvi Sigurjonsson
5  * Copyright 1996 Alexandre Julliard
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <ctype.h>
23 #include <stdarg.h>
24 #include <string.h>
25
26 #include "ntstatus.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wine/winbase16.h"
30 #include "wine/exception.h"
31 #include "wine/unicode.h"
32 #include "winerror.h"
33 #include "winnls.h"
34 #include "excpt.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(string);
38
39 /***********************************************************************
40  *           lstrcpyn    (KERNEL32.@)
41  *           lstrcpynA   (KERNEL32.@)
42  *
43  * Note: this function differs from the UNIX strncpy, it _always_ writes
44  * a terminating \0.
45  *
46  * Note: n is an INT but Windows treats it as unsigned, and will happily
47  * copy a gazillion chars if n is negative.
48  */
49 LPSTR WINAPI lstrcpynA( LPSTR dst, LPCSTR src, INT n )
50 {
51     LPSTR p = dst;
52     UINT count = n;
53
54     TRACE("(%p, %s, %i)\n", dst, debugstr_a(src), n);
55
56     /* In real windows the whole function is protected by an exception handler
57      * that returns ERROR_INVALID_PARAMETER on faulty parameters
58      * We currently just check for NULL.
59      */
60     if (!dst || !src) {
61         SetLastError(ERROR_INVALID_PARAMETER);
62         return 0;
63     }
64     while ((count > 1) && *src)
65     {
66         count--;
67         *p++ = *src++;
68     }
69     if (count) *p = 0;
70     return dst;
71 }
72
73
74 /***********************************************************************
75  *           lstrcpynW   (KERNEL32.@)
76  *
77  * Note: this function differs from the UNIX strncpy, it _always_ writes
78  * a terminating \0
79  *
80  * Note: n is an INT but Windows treats it as unsigned, and will happily
81  * copy a gazillion chars if n is negative.
82  */
83 LPWSTR WINAPI lstrcpynW( LPWSTR dst, LPCWSTR src, INT n )
84 {
85     LPWSTR p = dst;
86     UINT count = n;
87
88     TRACE("(%p, %s, %i)\n", dst,  debugstr_w(src), n);
89
90     /* In real windows the whole function is protected by an exception handler
91      * that returns ERROR_INVALID_PARAMETER on faulty parameters
92      * We currently just check for NULL.
93      */
94     if (!dst || !src) {
95         SetLastError(ERROR_INVALID_PARAMETER);
96         return 0;
97     }
98     while ((count > 1) && *src)
99     {
100         count--;
101         *p++ = *src++;
102     }
103     if (count) *p = 0;
104     return dst;
105 }