File: sequence.c

package info (click to toggle)
inn2 2.6.3-1%2Bdeb10u2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,304 kB
  • sloc: ansic: 96,539; sh: 15,562; perl: 13,281; makefile: 3,700; yacc: 842; python: 309; lex: 262
file content (37 lines) | stat: -rw-r--r-- 899 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*  $Id: sequence.c 4871 2001-07-09 08:09:58Z alexk $
**
**  Sequence space arithmetic routines.
**
**  This is a set of routines for implementing so called sequence
**  space arithmetic (typically used for DNS serial numbers). The
**  implementation here is taken from RFC 1982.
*/

#include "config.h"
#include "clibrary.h"
#include <limits.h>
#include "inn/sequence.h"


/*
**  compare two unsigned long numbers using sequence space arithmetic
**
**    returns:
**     0 - i1 = i2
**    -1 - i1 < i2
**     1 - i1 > i2
**     INT_MAX - undefined
*/
int
seq_lcompare(unsigned long i1, unsigned long i2)
{
    if (i1 == i2)
	return 0;
    else if ((i1 < i2 && i2 - i1 < (1 + ULONG_MAX / 2)) ||
	     (i1 > i2 && i1 - i2 > (1 + ULONG_MAX / 2)))
	return -1;
    else if ((i1 < i2 && i2 - i1 > (1 + ULONG_MAX / 2)) ||
	     (i1 > i2 && i1 - i2 < (1 + ULONG_MAX / 2)))
	return 1;
    return INT_MAX;
}