Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSvc / DtEncap / sbstdinc.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  * File:         sbstdinc.c $TOG: sbstdinc.c /main/5 1999/10/14 15:06:26 mgreess $
25  * Language:     C
26  *
27  * (c) Copyright 1988, Hewlett-Packard Company, all rights reserved.
28  *
29  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
30  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
31  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
32  * (c) Copyright 1993, 1994 Novell, Inc.                                *
33  */
34
35 #define  SBSTDINC_H_NO_REDEFINE
36
37 #include <bms/sbport.h> /* NOTE: sbport.h must be the first include. */
38
39 #include <stdarg.h>
40
41 static XeChar XESTRING_SAFE_NULL[1] = {(XeChar)0};
42
43 /************************************************************************/
44 /* Routines from <string.h>                                             */
45 /************************************************************************/
46
47 XeString Xestrcat(XeString s1, ConstXeString s2) 
48
49     if (!s1) return XeString_NULL; 
50     if (!s2) return s1;
51   
52    return (XeString) strcat(s1, s2); 
53 }
54
55 XeString Xestrncat(XeString s1, ConstXeString s2, size_t n) 
56 {
57     if (!s1) return XeString_NULL; 
58     if (!s2) return s1; 
59
60     return (XeString) strncat(s1, s2, n); 
61 }
62
63 int Xestrcmp(ConstXeString s1, ConstXeString s2) 
64
65     if (s1 == s2) return 0; 
66     {
67         const XeChar * p1 = (s1) ? s1 : XESTRING_SAFE_NULL;
68         const XeChar * p2 = (s2) ? s2 : XESTRING_SAFE_NULL;
69
70         return strcmp(p1, p2); 
71     }
72 }
73
74 int Xestrncmp(ConstXeString s1, ConstXeString s2, size_t n) 
75 {
76     if (s1 == s2) return 0; 
77     {
78         ConstXeString p1 = (s1) ? s1 : XESTRING_SAFE_NULL; 
79         ConstXeString p2 = (s2) ? s2 : XESTRING_SAFE_NULL; 
80         return strncmp( (char *) p1, (char *) p2, n); 
81     }
82 }
83
84 XeString Xestrcpy(XeString s1, ConstXeString s2) 
85
86     if (!s1) return s1; 
87     if (!s2) { 
88         *s1 = (XeChar)0; 
89         return s1; 
90     } 
91
92    return (XeString) strcpy(s1, s2); 
93 }
94
95 XeString Xestrncpy(XeString s1, ConstXeString s2, size_t n) 
96 {
97     if (!s1) return s1; 
98     if (!s2 && n) { 
99         *s1 = (XeChar)0; 
100         return s1; 
101     } 
102
103    return (XeString) strncpy(s1, s2, n); 
104 }
105
106 int Xestrcoll(ConstXeString s1, ConstXeString s2) 
107
108     if (s1 == s2) return 0; 
109     {
110         XeString p1 = (s1) ? (XeString) s1 : XESTRING_SAFE_NULL; 
111         XeString p2 = (s2) ? (XeString) s2 : XESTRING_SAFE_NULL; 
112         return strcoll(p1, p2);
113     }
114 }
115
116 size_t Xestrxfrm(XeString s1, ConstXeString s2, size_t n) 
117
118     return strxfrm(s1, s2, n); 
119 }
120
121 XeString Xestrchr(ConstXeString s, int c) 
122
123     if (!s) return XeString_NULL; 
124
125     return (XeString) strchr(s, c); 
126 }
127
128 XeString Xestrrchr(ConstXeString s, int c) 
129
130     if (!s) return XeString_NULL; 
131
132     return (XeString) strrchr(s, c); 
133 }
134
135 XeString Xestrpbrk(ConstXeString s1, ConstXeString s2) 
136
137     if (!s1) return XeString_NULL; 
138     if (!s2) return XeString_NULL; 
139
140     return (XeString) strpbrk(s1, s2); 
141 }
142
143 XeString Xestrstr(ConstXeString s1, ConstXeString s2) 
144
145     if (!s1) return XeString_NULL; 
146     if (!s2) return XeString_NULL;
147
148     return (XeString) strstr(s1, s2); 
149 }
150
151 XeString Xestrtok(XeString s1, ConstXeString s2) 
152
153     /* s1 is null except after the first call */
154     if (!s2) return XeString_NULL;
155
156     return (XeString) strtok(s1, s2); 
157 }
158
159 size_t Xestrlen(ConstXeString const s) 
160
161     if (!s) return (size_t)0; 
162
163     return strlen((char *) s); 
164 }
165
166 XeString Xestrdup(ConstXeString s) 
167
168     if (!s) return XeString_NULL; 
169
170     return (XeString) strdup(s); 
171 }