diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-07-19 02:36:11 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-07-19 02:36:11 -0400 |
commit | 94f85f216ae4b6196d2a3438bfaf328375ebaad6 (patch) | |
tree | b47b9c81e3722e8c41d35ade6c844a9dd7ebc0a5 /src/common/util.c | |
parent | 891ccd3cd0690e83f1dc4dde7698c3bd9d7fe98d (diff) | |
download | tor-94f85f216ae4b6196d2a3438bfaf328375ebaad6.tar tor-94f85f216ae4b6196d2a3438bfaf328375ebaad6.tar.gz |
Turn streq_opt into a generic strcmp_opt.
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index bf0bbe060..15b6e7130 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -521,6 +521,23 @@ tor_strisnonupper(const char *s) return 1; } +/** As strcmp, except that either string may be NULL. The NULL string is + * considered to be before any non-NULL string. */ +int +strcmp_opt(const char *s1, const char *s2) +{ + if (!s1) { + if (!s2) + return 0; + else + return -1; + } else if (!s2) { + return 1; + } else { + return strcmp(s1, s2); + } +} + /** Compares the first strlen(s2) characters of s1 with s2. Returns as for * strcmp. */ |