#include "util.h"
int strcmp_ptr(const char *a, const char *b) {
-
/* Like strcmp(), but tries to make sense of NULL pointers */
+
if (a && b)
return strcmp(a, b);
+ return CMP(a, b); /* Direct comparison of pointers, one of which is NULL */
+}
- if (!a && b)
- return -1;
-
- if (a && !b)
- return 1;
+int strcasecmp_ptr(const char *a, const char *b) {
+ /* Like strcasecmp(), but tries to make sense of NULL pointers */
- return 0;
+ if (a && b)
+ return strcasecmp(a, b);
+ return CMP(a, b); /* Direct comparison of pointers, one of which is NULL */
}
char* endswith(const char *s, const char *postfix) {
#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
int strcmp_ptr(const char *a, const char *b) _pure_;
+int strcasecmp_ptr(const char *a, const char *b) _pure_;
static inline bool streq_ptr(const char *a, const char *b) {
return strcmp_ptr(a, b) == 0;
}
static int compare_unit_info(const UnitInfo *a, const UnitInfo *b) {
- const char *d1, *d2;
int r;
/* First, order by machine */
- if (!a->machine && b->machine)
- return -1;
- if (a->machine && !b->machine)
- return 1;
- if (a->machine && b->machine) {
- r = strcasecmp(a->machine, b->machine);
- if (r != 0)
- return r;
- }
+ r = strcasecmp_ptr(a->machine, b->machine);
+ if (r != 0)
+ return r;
/* Second, order by unit type */
- d1 = strrchr(a->id, '.');
- d2 = strrchr(b->id, '.');
- if (d1 && d2) {
- r = strcasecmp(d1, d2);
- if (r != 0)
- return r;
- }
+ r = strcasecmp_ptr(strrchr(a->id, '.'), strrchr(b->id, '.'));
+ if (r != 0)
+ return r;
/* Third, order by name */
return strcasecmp(a->id, b->id);
assert(a);
assert(b);
- if (!a->machine && b->machine)
- return -1;
- if (a->machine && !b->machine)
- return 1;
- if (a->machine && b->machine) {
- r = strcasecmp(a->machine, b->machine);
- if (r != 0)
- return r;
- }
+ r = strcasecmp_ptr(a->machine, b->machine);
+ if (r != 0)
+ return r;
r = strcmp(a->path, b->path);
- if (r == 0)
- r = strcmp(a->type, b->type);
+ if (r != 0)
+ return r;
- return r;
+ return strcmp(a->type, b->type);
}
static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) {
assert(a);
assert(b);
- if (!a->machine && b->machine)
- return -1;
- if (a->machine && !b->machine)
- return 1;
- if (a->machine && b->machine) {
- r = strcasecmp(a->machine, b->machine);
- if (r != 0)
- return r;
- }
+ r = strcasecmp_ptr(a->machine, b->machine);
+ if (r != 0)
+ return r;
r = CMP(a->next_elapse, b->next_elapse);
if (r != 0)