1 /* strutil.c
2
3 Originally written by Don Robert Maszle
4
5 Copyright (c) 1992-2017 Free Software Foundation, Inc.
6
7 This file is part of GNU MCSim.
8
9 GNU MCSim is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 3
12 of the License, or (at your option) any later version.
13
14 GNU MCSim is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU MCSim; if not, see <http://www.gnu.org/licenses/>
21
22 The following routines are provided as alternates to the standard
23 library routines. They handle NULL string pointer cases in a
24 reasonable manner and ultimately call the standard library routines
25 for non-NULL cases. Some routines are implemented as macros.
26
27 Use the header file "strutil.h"
28
29 Currently supported are:
30
31 MyStrlen(), MyStrcpy(), MyStrcmp(), MyStrchr(), MyStrtok()
32 */
33
34 #include <string.h>
35
36 #include "strutil.h"
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