003 File Manager
Current Path:
/usr/src/contrib/ntp/libntp
usr
/
src
/
contrib
/
ntp
/
libntp
/
📁
..
📄
Makefile.am
(3.27 KB)
📄
Makefile.in
(105.83 KB)
📄
README
(272 B)
📄
a_md5encrypt.c
(6.76 KB)
📄
adjtime.c
(10.29 KB)
📄
adjtimex.c
(334 B)
📄
atoint.c
(801 B)
📄
atolfp.c
(1.88 KB)
📄
atouint.c
(885 B)
📄
audio.c
(13.09 KB)
📄
authkeys.c
(19.92 KB)
📄
authreadkeys.c
(9.06 KB)
📄
authusekey.c
(748 B)
📄
bsd_strerror.c
(1.35 KB)
📄
buftvtots.c
(643 B)
📄
caljulian.c
(891 B)
📄
caltontp.c
(2.25 KB)
📄
calyearstart.c
(2.1 KB)
📄
clocktime.c
(4.49 KB)
📄
clocktypes.c
(3.69 KB)
📄
decodenetnum.c
(3.93 KB)
📄
dofptoa.c
(2.19 KB)
📄
dolfptoa.c
(3.14 KB)
📄
emalloc.c
(3.4 KB)
📄
findconfig.c
(1.46 KB)
📄
getopt.c
(2.21 KB)
📄
hextoint.c
(673 B)
📄
hextolfp.c
(1.35 KB)
📄
humandate.c
(1.1 KB)
📄
icom.c
(4.22 KB)
📄
iosignal.c
(12.27 KB)
📄
is_ip_address.c
(2.02 KB)
📄
lib_strbuf.c
(633 B)
📄
libssl_compat.c
(6.13 KB)
📄
machines.c
(13.05 KB)
📄
mktime.c
(8.29 KB)
📄
modetoa.c
(507 B)
📄
mstolfp.c
(2.01 KB)
📄
msyslog.c
(12.67 KB)
📄
netof.c
(1.17 KB)
📄
ntp_calendar.c
(58.49 KB)
📄
ntp_calgps.c
(15.73 KB)
📄
ntp_crypto_rnd.c
(2.11 KB)
📄
ntp_intres.c
(28.64 KB)
📄
ntp_libopts.c
(1.27 KB)
📄
ntp_lineedit.c
(3.88 KB)
📄
ntp_random.c
(17.63 KB)
📄
ntp_rfc2553.c
(14.85 KB)
📄
ntp_worker.c
(7.21 KB)
📄
numtoa.c
(963 B)
📄
numtohost.c
(908 B)
📄
octtoint.c
(578 B)
📄
prettydate.c
(5.53 KB)
📄
recvbuff.c
(7.3 KB)
📄
refidsmear.c
(1.05 KB)
📄
refnumtoa.c
(673 B)
📄
snprintf.c
(52.56 KB)
📄
socket.c
(4.88 KB)
📄
socktoa.c
(2.88 KB)
📄
socktohost.c
(2.54 KB)
📄
ssl_init.c
(5.09 KB)
📄
statestr.c
(11.4 KB)
📄
strdup.c
(854 B)
📄
strl_obsd.c
(3.65 KB)
📄
syssignal.c
(2.69 KB)
📄
systime.c
(17.51 KB)
📄
systime_s.c
(33 B)
📄
timespecops.c
(4.27 KB)
📄
timetoa.c
(2.75 KB)
📄
timevalops.c
(12.97 KB)
📄
timexsup.c
(1.17 KB)
📄
uglydate.c
(958 B)
📄
vint64ops.c
(5.1 KB)
📄
work_fork.c
(12.73 KB)
📄
work_thread.c
(22.88 KB)
📄
xsbprintf.c
(2.06 KB)
📄
ymd2yd.c
(582 B)
Editing: vint64ops.c
/* * vint64ops.c - operations on 'vint64' values * * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. * The contents of 'html/copyright.html' apply. * ---------------------------------------------------------------------- * This is an attempt to get the vint64 calculations stuff centralised. */ #include <config.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <errno.h> #include "ntp_types.h" #include "ntp_fp.h" #include "vint64ops.h" /* --------------------------------------------------------------------- * GCC is rather sticky with its 'const' attribute. We have to do it more * explicit than with a cast if we want to get rid of a CONST qualifier. * Greetings from the PASCAL world, where casting was only possible via * untagged unions... */ static inline void* noconst( const void* ptr ) { union { const void * cp; void * vp; } tmp; tmp.cp = ptr; return tmp.vp; } /* -------------------------------------------------------------------------*/ vint64 strtouv64( const char * begp, char ** endp, int base ) { vint64 res; u_char digit; int sig, num; const u_char *src; num = sig = 0; src = (const u_char*)begp; while (isspace(*src)) src++; if (*src == '-') { src++; sig = 1; } else if (*src == '+') { src++; } if (base == 0) { base = 10; if (*src == '0') { base = 8; if (toupper(*++src) == 'X') { src++; base = 16; } } } else if (base == 16) { /* remove optional leading '0x' or '0X' */ if (src[0] == '0' && toupper(src[1]) == 'X') src += 2; } else if (base <= 2 || base > 36) { memset(&res, 0xFF, sizeof(res)); errno = ERANGE; return res; } memset(&res, 0, sizeof(res)); while (*src) { if (isdigit(*src)) digit = *src - '0'; else if (isupper(*src)) digit = *src - 'A' + 10; else if (islower(*src)) digit = *src - 'a' + 10; else break; if (digit >= base) break; num = 1; #if defined(HAVE_INT64) res.Q_s = res.Q_s * base + digit; #else /* res *= base, using 16x16->32 bit * multiplication. Slow but portable. */ { uint32_t accu; accu = (uint32_t)res.W_s.ll * base; res.W_s.ll = (uint16_t)accu; accu = (accu >> 16) + (uint32_t)res.W_s.lh * base; res.W_s.lh = (uint16_t)accu; /* the upper bits can be done in one step: */ res.D_s.hi = res.D_s.hi * base + (accu >> 16); } M_ADD(res.D_s.hi, res.D_s.lo, 0, digit); #endif src++; } if (!num) errno = EINVAL; if (endp) *endp = (char*)noconst(src); if (sig) M_NEG(res.D_s.hi, res.D_s.lo); return res; } /* -------------------------------------------------------------------------*/ int icmpv64( const vint64 * lhs, const vint64 * rhs ) { int res; #if defined(HAVE_INT64) res = (lhs->q_s > rhs->q_s) - (lhs->q_s < rhs->q_s); #else res = (lhs->d_s.hi > rhs->d_s.hi) - (lhs->d_s.hi < rhs->d_s.hi); if ( ! res ) res = (lhs->D_s.lo > rhs->D_s.lo) - (lhs->D_s.lo < rhs->D_s.lo); #endif return res; } /* -------------------------------------------------------------------------*/ int ucmpv64( const vint64 * lhs, const vint64 * rhs ) { int res; #if defined(HAVE_INT64) res = (lhs->Q_s > rhs->Q_s) - (lhs->Q_s < rhs->Q_s); #else res = (lhs->D_s.hi > rhs->D_s.hi) - (lhs->D_s.hi < rhs->D_s.hi); if ( ! res ) res = (lhs->D_s.lo > rhs->D_s.lo) - (lhs->D_s.lo < rhs->D_s.lo); #endif return res; } /* -------------------------------------------------------------------------*/ vint64 addv64( const vint64 *lhs, const vint64 *rhs ) { vint64 res; #if defined(HAVE_INT64) res.Q_s = lhs->Q_s + rhs->Q_s; #else res = *lhs; M_ADD(res.D_s.hi, res.D_s.lo, rhs->D_s.hi, rhs->D_s.lo); #endif return res; } /* -------------------------------------------------------------------------*/ vint64 subv64( const vint64 *lhs, const vint64 *rhs ) { vint64 res; #if defined(HAVE_INT64) res.Q_s = lhs->Q_s - rhs->Q_s; #else res = *lhs; M_SUB(res.D_s.hi, res.D_s.lo, rhs->D_s.hi, rhs->D_s.lo); #endif return res; } /* -------------------------------------------------------------------------*/ vint64 addv64i32( const vint64 * lhs, int32_t rhs ) { vint64 res; res = *lhs; #if defined(HAVE_INT64) res.q_s += rhs; #else M_ADD(res.D_s.hi, res.D_s.lo, -(rhs < 0), rhs); #endif return res; } /* -------------------------------------------------------------------------*/ vint64 subv64i32( const vint64 * lhs, int32_t rhs ) { vint64 res; res = *lhs; #if defined(HAVE_INT64) res.q_s -= rhs; #else M_SUB(res.D_s.hi, res.D_s.lo, -(rhs < 0), rhs); #endif return res; } /* -------------------------------------------------------------------------*/ vint64 addv64u32( const vint64 * lhs, uint32_t rhs ) { vint64 res; res = *lhs; #if defined(HAVE_INT64) res.Q_s += rhs; #else M_ADD(res.D_s.hi, res.D_s.lo, 0, rhs); #endif return res; } /* -------------------------------------------------------------------------*/ vint64 subv64u32( const vint64 * lhs, uint32_t rhs ) { vint64 res; res = *lhs; #if defined(HAVE_INT64) res.Q_s -= rhs; #else M_SUB(res.D_s.hi, res.D_s.lo, 0, rhs); #endif return res; }
Upload File
Create Folder