From: Volker Lendecke Date: Sat, 7 Sep 2019 16:55:57 +0000 (+0200) Subject: lib: Add server_id_cmp() X-Git-Tag: talloc-2.3.1~819 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d9ce9c42cb6abd3263d639d6474a92b85776ba8d;p=thirdparty%2Fsamba.git lib: Add server_id_cmp() Will be used later for sorting the share mode array Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/lib/util/server_id.c b/lib/util/server_id.c index 2904e803196..ca998116bf4 100644 --- a/lib/util/server_id.c +++ b/lib/util/server_id.c @@ -30,6 +30,23 @@ bool server_id_same_process(const struct server_id *p1, return ((p1->pid == p2->pid) && (p1->vnn == p2->vnn)); } +int server_id_cmp(const struct server_id *p1, const struct server_id *p2) +{ + if (p1->vnn != p2->vnn) { + return (p1->vnn < p2->vnn) ? -1 : 1; + } + if (p1->pid != p2->pid) { + return (p1->pid < p2->pid) ? -1 : 1; + } + if (p1->task_id != p2->task_id) { + return (p1->task_id < p2->task_id) ? -1 : 1; + } + if (p1->unique_id != p2->unique_id) { + return (p1->unique_id < p2->unique_id) ? -1 : 1; + } + return 0; +} + bool server_id_equal(const struct server_id *p1, const struct server_id *p2) { if (!server_id_same_process(p1, p2)) { diff --git a/lib/util/server_id.h b/lib/util/server_id.h index 6dda86ced73..5b723d5cda4 100644 --- a/lib/util/server_id.h +++ b/lib/util/server_id.h @@ -28,6 +28,7 @@ struct server_id_buf { char buf[48]; }; /* probably a bit too large ... */ bool server_id_same_process(const struct server_id *p1, const struct server_id *p2); +int server_id_cmp(const struct server_id *p1, const struct server_id *p2); bool server_id_equal(const struct server_id *p1, const struct server_id *p2); char *server_id_str_buf(struct server_id id, struct server_id_buf *dst); size_t server_id_str_buf_unique(struct server_id id, char *buf, size_t buflen);