1 /* strutil.c
2
3 Copyright (c) 1993-2017. Free Software Foundation, Inc.
4
5 This file is part of GNU MCSim.
6
7 GNU MCSim is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 3
10 of the License, or (at your option) any later version.
11
12 GNU MCSim 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
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU MCSim; if not, see <http://www.gnu.org/licenses/>
19
20 The following routines are provided as alternates to the standard
21 library routines. They handle NULL string pointer cases in a
22 reasonable manner and ultimately call the standard library routines
23 for non-NULL cases. Some routines are implemented as macros.
24
25 Use the header file "strutil.h"
26
27 Currently supported are:
28
29 MyStrlen(), MyStrcpy(), MyStrcmp(), MyStrchr(), MyStrtok()
30 */
31
32 #include <string.h>
33
34 #include "strutil.h"
35
36 /* ---------------------------------------------------------------------------
37 */
MyStrcmp(const char * sz1,const char * sz2)38 int MyStrcmp(const char* sz1, const char* sz2)
39 {
40 if (!sz1) {
41 if (sz2)
42 return (-1); /* NULL comes before the -something- */
43 else
44 return (0); /* Two NULL strings compare equal */
45 } /* if */
46
47 else { /* assert (sz1) */
48 if (sz2)
49 return (strcmp(sz1, sz2)); /* Normal comparison */
50 else
51 return (1); /* -Something- comes after the NULL */
52 } /* else */
53
54 /* Prevent compiler complaints */
55 return 0; /* Never reached! */
56
57 } /* MyStrcmp */
58
59
60 /* End */
61
62
63