1 /*****************************************************************************
2 * RRDtool 1.0.33 Copyright Tobias Oetiker, 1999
3 * This code is stolen from rateup (mrtg-2.x) by Dave Rand
4 *****************************************************************************
5 * diff calculate the difference between two very long integers available as
7 *****************************************************************************
10 * Revision 1.1 2001/02/25 22:25:05 oetiker
13 * Revision 1.1 1998/10/08 18:21:45 oetiker
16 * Revision 1.3 1998/02/06 21:10:52 oetiker
17 * removed max define .. it is now in rrd_tool.h
19 * Revision 1.2 1997/12/07 20:38:03 oetiker
22 * Revision 1.1 1997/11/28 23:31:59 oetiker
25 *****************************************************************************/
30 rrd_diff(char *a, char *b)
32 char res[LAST_DS_LEN+1], *a1, *b1, *r1, *fix;
35 while (!isdigit((int)*a) || *a==0)
38 while (isdigit((int)*fix))
40 *fix = 0; /* maybe there is some non digit data in the string */
41 while (!isdigit((int)*b) || *b==0)
44 while (isdigit((int)*fix))
46 *fix = 0; /* maybe there is some non digit data in the string */
47 if(!isdigit((int)*a) || !isdigit((int)*b))
50 m = max(strlen(a),strlen(b));
51 if (m > LAST_DS_LEN) return DNAN; /* result string too short */
54 for (b1 = res;b1 <= r1; b1++) *b1 = ' ';
56 r1[1] = 0; /* Null terminate result */
59 if (a1 >= a && b1 >= b) {
60 *r1 = ((*a1 - c) - *b1) + '0';
64 *r1 = ('0' - *b1 - c) + '0';
70 if (*r1 > '9') { /* 0 - 10 */
80 for (x=0; isdigit((int)*r1) && x<m; x++,r1--) {
81 *r1 = ('9' - *r1 + c) + '0';