File: nullstrcmp.c

package info (click to toggle)
xtruss 0.0~git20241011.27fafffe-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,172 kB
  • sloc: ansic: 17,121; sh: 20; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 449 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Compare two strings, just like strcmp, except that we tolerate null
 * pointers as a legal input, and define them to compare before any
 * non-null string (even the empty string).
 */

#include <string.h>

#include "defs.h"
#include "misc.h"

int nullstrcmp(const char *a, const char *b)
{
    if (a == NULL && b == NULL)
        return 0;
    if (a == NULL)
        return -1;
    if (b == NULL)
        return +1;
    return strcmp(a, b);
}