1%%	options
2
3copyright owner	=	Dirk Krause
4copyright year	=	2015-xxxx
5SPDX-License-Identifier:	BSD-3-Clause
6
7
8%%	header
9
10/**	@file
11	Compare unique file identifiers.
12*/
13
14#ifndef	DK4CONF_H_INCLUDED
15#if DK4_BUILDING_DKTOOLS4
16#include "dk4conf.h"
17#else
18#include <dktools-4/dk4conf.h>
19#endif
20#endif
21
22#ifndef DK4UFIT_H_INCLUDED
23#if DK4_BUILDING_DKTOOLS4
24#include <libdk4c/dk4ufit.h>
25#else
26#include <dktools-4/dk4ufit.h>
27#endif
28#endif
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/**	Compare two unique file identifiers.
35	@param	l	Left identifier.
36	@param	r	Right identifier.
37	@return	1 if l>r, 0 if l=r, -1 if l<r.
38*/
39int
40dk4ufi_compare(const dk4_ufi_t *l, const dk4_ufi_t *r);
41
42#ifdef __cplusplus
43}
44#endif
45
46
47%%	module
48
49#include "dk4conf.h"
50#include <libdk4c/dk4ufic.h>
51
52
53
54$!trace-include
55
56
57
58int
59dk4ufi_compare(const dk4_ufi_t *l, const dk4_ufi_t *r)
60{
61  int back = 0;
62  $? "+ dk4ufi_compare"
63  if (NULL != l) {
64    if (NULL != r) {
65#if DK4_ON_WINDOWS
66      if (l->ser > r->ser) {
67        back = 1;
68      } else {
69        if (l->ser < r->ser) {
70	  back = -1;
71	}
72      }
73      if (0 == back) {
74        if (l->inh > r->inh) {
75	  back = 1;
76	} else {
77	  if (l->inh < r->inh) {
78	    back = -1;
79	  }
80	}
81      }
82      if (0 == back) {
83        if (l->inl > r->inl) {
84	  back = 1;
85	} else {
86	  if (l->inl < r->inl) {
87	    back = -1;
88	  }
89	}
90      }
91#else
92      if (l->dev > r->dev) {
93        back = 1;		$? ". left dev larger"
94      } else {
95        if (l->dev < r->dev) {
96	  back = -1;		$? ". right dev larger"
97	}
98      }
99      if (0 == back) {
100        if (l->ino > r->ino) {
101	  back = 1;		$? ". left ino larger"
102	} else {
103	  if (l->ino < r->ino) {
104	    back = -1;		$? ". right ino larger"
105	  }
106	}
107      }
108      $? ". %lu/%lu   %lu/%lu", (unsigned long)(l->dev), (unsigned long)(l->ino), (unsigned long)(r->dev), (unsigned long)(r->ino)
109#endif
110    } else {
111      back = 1;
112    }
113  } else {
114    if (NULL != r) {
115      back = -1;
116    }
117  }
118  $? "- dk4ufi_compare %d", back
119  return back;
120}
121
122