File: sequence.c

package info (click to toggle)
inn2 2.4.5-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,912 kB
  • ctags: 7,860
  • sloc: ansic: 85,104; perl: 11,427; sh: 9,863; makefile: 2,498; yacc: 1,563; python: 298; lex: 252; tcl: 7
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;
}