📄 lib.txt
字号:
01819 if (numer == 0) {
01820 r.quot = numer / denom; /* might trap if denom == 0 */
01821 r.rem = numer % denom;
01822 } else if ( !tmp && ((numer < 0) != (denom < 0))) {
01823 r.quot = (numer / denom) + 1;
01824 r.rem = numer - (numer / denom + 1) * denom;
01825 } else {
01826 r.quot = numer / denom;
01827 r.rem = numer % denom;
01828 }
01829 return r;
01830 }
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/lib/ansi/errlist.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01900 /*
01901 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
01902 * See the copyright notice in the ACK home directory, in the file "Copyright".
01903 */
01904 /* $Header: errlist.c,v 1.1 89/05/10 16:22:20 eck Exp $ */
01905
01906 #include <errno.h>
01907
01908 static const char unknown[] = "Unknown error";
01909
01910 const char *_sys_errlist[] = {
01911 "Error 0", /* EGENERIC */
01912 "Not owner", /* EPERM */
01913 "No such file or directory", /* ENOENT */
01914 "No such process", /* ESRCH */
01915 "Interrupted system call", /* EINTR */
01916 "I/O error", /* EIO */
01917 "No such device or address", /* ENXIO */
01918 "Arg list too long", /* E2BIG */
01919 "Exec format error", /* ENOEXEC */
01920 "Bad file number", /* EBADF */
01921 "No children", /* ECHILD */
01922 "No more processes", /* EAGAIN */
01923 "Not enough core", /* ENOMEM */
01924 "Permission denied", /* EACCES */
01925 "Bad address", /* EFAULT */
01926 "Block device required", /* ENOTBLK */
01927 "Resource busy", /* EBUSY */
01928 "File exists", /* EEXIST */
01929 "Cross-device link", /* EXDEV */
01930 "No such device", /* ENODEV */
01931 "Not a directory", /* ENOTDIR */
01932 "Is a directory", /* EISDIR */
01933 "Invalid argument", /* EINVAL */
01934 "File table overflow", /* ENFILE */
01935 "Too many open files", /* EMFILE */
01936 "Not a typewriter", /* ENOTTY */
01937 "Text file busy", /* ETXTBSY */
01938 "File too large", /* EFBIG */
01939 "No space left on device", /* ENOSPC */
01940 "Illegal seek", /* ESPIPE */
01941 "Read-only file system", /* EROFS */
01942 "Too many links", /* EMLINK */
01943 "Broken pipe", /* EPIPE */
01944 "Math argument", /* EDOM */
01945 "Result too large", /* ERANGE */
01946 "Resource deadlock avoided", /* EDEADLK */
01947 "File name too long", /* ENAMETOOLONG */
01948 "No locks available", /* ENOLCK */
01949 "Function not implemented", /* ENOSYS */
01950 "Directory not empty", /* ENOTEMPTY */
01951 unknown, /* 40 */
01952 unknown, /* 41 */
01953 unknown, /* 42 */
01954 unknown, /* 43 */
01955 unknown, /* 44 */
01956 unknown, /* 45 */
01957 unknown, /* 46 */
01958 unknown, /* 47 */
01959 unknown, /* 48 */
01960 unknown, /* 49 */
01961 "Invalid packet size", /* EPACKSIZE */
01962 "Not enough buffers left", /* EOUTOFBUFS */
01963 "Illegal ioctl for device", /* EBADIOCTL */
01964 "Bad mode for ioctl", /* EBADMODE */
01965 "Would block", /* EWOULDBLOCK */
01966 "Bad destination address", /* EBADDEST */
01967 "Destination not reachable", /* EDSTNOTRCH */
01968 "Already connected", /* EISCONN */
01969 "Address in use", /* EADDRINUSE */
01970 "Connection refused", /* ECONNREFUSED */
01971 "Connection reset", /* ECONNRESET */
01972 "Connection timed out", /* ETIMEDOUT */
01973 "Urgent data present", /* EURG */
01974 "No urgent data present", /* ENOURG */
01975 "No connection", /* ENOTCONN */
01976 "Already shutdown", /* ESHUTDOWN */
01977 "No such connection", /* ENOCONN */
01978 };
01979
01980 const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/lib/ansi/exit.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
02000 /*
02001 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
02002 * See the copyright notice in the ACK home directory, in the file "Copyright".
02003 */
02004 /* $Header: exit.c,v 1.3 90/01/22 13:00:04 eck Exp $ */
02005
02006 #include <stdio.h>
02007 #include <stdlib.h>
02008
02009 #define NEXITS 32
02010
02011 void (*__functab[NEXITS])(void);
02012 int __funccnt = 0;
02013
02014 extern void _exit(int);
02015
02016 /* only flush output buffers when necessary */
02017 int (*_clean)(void) = NULL;
02018
02019 static void
02020 _calls(void)
02021 {
02022 register int i = __funccnt;
02023
02024 /* "Called in reversed order of their registration" */
02025 while (--i >= 0)
02026 (*__functab[i])();
02027 }
02029 void
02030 exit(int status)
02031 {
02032 _calls();
02033 if (_clean) _clean();
02034 _exit(status) ;
02035 }
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/lib/ansi/ext_comp.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
02100 /*
02101 (c) copyright 1989 by the Vrije Universiteit, Amsterdam, The Netherlands.
02102 See the copyright notice in the ACK home directory, in the file "Copyright".
02103 */
02104
02105 /* $Id: ext_comp.c,v 1.10 1994/06/24 11:53:36 ceriel Exp $ */
02106
02107 /* extended precision arithmetic for the strtod() and cvt() routines */
02108
02109 /* This may require some more work when long doubles get bigger than 8
02110 bytes. In this case, these routines may become obsolete. ???
02111 */
02112
02113 #include "ext_fmt.h"
02114 #include <float.h>
02115 #include <errno.h>
02116 #include <ctype.h>
02117
02118 static int b64_add(struct mantissa *e1, struct mantissa *e2);
02119 static b64_sft(struct mantissa *e1, int n);
02120
02121 static
02122 mul_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3)
02123 {
02124 /* Multiply the extended numbers e1 and e2, and put the
02125 result in e3.
02126 */
02127 register int i,j; /* loop control */
02128 unsigned short mp[4];
02129 unsigned short mc[4];
02130 unsigned short result[8]; /* result */
02131
02132 register unsigned short *pres;
02133
02134 /* first save the sign (XOR) */
02135 e3->sign = e1->sign ^ e2->sign;
02136
02137 /* compute new exponent */
02138 e3->exp = e1->exp + e2->exp + 1;
02139
02140 /* check for overflow/underflow ??? */
02141
02142 /* 128 bit multiply of mantissas */
02143
02144 /* assign unknown long formats */
02145 /* to known unsigned word formats */
02146 mp[0] = e1->m1 >> 16;
02147 mp[1] = (unsigned short) e1->m1;
02148 mp[2] = e1->m2 >> 16;
02149 mp[3] = (unsigned short) e1->m2;
02150 mc[0] = e2->m1 >> 16;
02151 mc[1] = (unsigned short) e2->m1;
02152 mc[2] = e2->m2 >> 16;
02153 mc[3] = (unsigned short) e2->m2;
02154 for (i = 8; i--;) {
02155 result[i] = 0;
02156 }
02157 /*
02158 * fill registers with their components
02159 */
02160 for(i=4, pres = &result[4];i--;pres--) if (mp[i]) {
02161 unsigned short k = 0;
02162 unsigned long mpi = mp[i];
02163 for(j=4;j--;) {
02164 unsigned long tmp = (unsigned long)pres[j] + k;
02165 if (mc[j]) tmp += mpi * mc[j];
02166 pres[j] = tmp;
02167 k = tmp >> 16;
02168 }
02169 pres[-1] = k;
02170 }
02171
02172 if (! (result[0] & 0x8000)) {
02173 e3->exp--;
02174 for (i = 0; i <= 3; i++) {
02175 result[i] <<= 1;
02176 if (result[i+1]&0x8000) result[i] |= 1;
02177 }
02178 result[4] <<= 1;
02179 }
02180 /*
02181 * combine the registers to a total
02182 */
02183 e3->m1 = ((unsigned long)(result[0]) << 16) + result[1];
02184 e3->m2 = ((unsigned long)(result[2]) << 16) + result[3];
02185 if (result[4] & 0x8000) {
02186 if (++e3->m2 == 0) {
02187 if (++e3->m1 == 0) {
02188 e3->m1 = 0x80000000;
02189 e3->exp++;
02190 }
02191 }
02192 }
02193 }
02195 static
02196 add_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3)
02197 {
02198 /* Add two extended numbers e1 and e2, and put the result
02199 in e3
02200 */
02201 struct EXTEND ce2;
02202 int diff;
02203
02204 if ((e2->m1 | e2->m2) == 0L) {
02205 *e3 = *e1;
02206 return;
02207 }
02208 if ((e1->m1 | e1->m2) == 0L) {
02209 *e3 = *e2;
02210 return;
02211 }
02212 ce2 = *e2;
02213 *e3 = *e1;
02214 e1 = &ce2;
02215
02216 /* adjust mantissas to equal power */
02217 diff = e3->exp - e1->exp;
02218 if (diff < 0) {
02219 diff = -diff;
02220 e3->exp += diff;
02221 b64_sft(&(e3->mantissa), diff);
02222 }
02223 else if (diff > 0) {
02224 e1->exp += diff;
02225 b64_sft(&(e1->mantissa), diff);
02226 }
02227 if (e1->sign != e3->sign) {
02228 /* e3 + e1 = e3 - (-e1) */
02229 if (e1->m1 > e3->m1 ||
02230 (e1->m1 == e3->m1 && e1->m2 > e3->m2)) {
02231 /* abs(e1) > abs(e3) */
02232 if (e3->m2 > e1->m2) {
02233 e1->m1 -= 1; /* carry in */
02234 }
02235 e1->m1 -= e3->m1;
02236 e1->m2 -= e3->m2;
02237 *e3 = *e1;
02238 }
02239 else {
02240 if (e1->m2 > e3->m2)
02241 e3->m1 -= 1; /* carry in */
02242 e3->m1 -= e1->m1;
02243 e3->m2 -= e1->m2;
02244 }
02245 }
02246 else {
02247 if (b64_add(&e3->mantissa,&e1->mantissa)) {/* addition carry */
02248 b64_sft(&e3->mantissa,1);/* shift mantissa one bit RIGHT */
02249 e3->m1 |= 0x80000000L; /* set max bit */
02250 e3->exp++; /* increase the exponent */
02251 }
02252 }
02253 if ((e3->m2 | e3->m1) != 0L) {
02254 /* normalize */
02255 if (e3->m1 == 0L) {
02256 e3->m1 = e3->m2; e3->m2 = 0L; e3->exp -= 32;
02257 }
02258 if (!(e3->m1 & 0x80000000)) {
02259 unsigned long l = 0x40000000;
02260 int cnt = -1;
02261
02262 while (! (l & e3->m1)) {
02263 l >>= 1; cnt--;
02264 }
02265 e3->exp += cnt;
02266 b64_sft(&(e3->mantissa), cnt);
02267 }
02268 }
02269 }
02271 static int
02272 cmp_ext(struct EXTEND *e1, struct EXTEND *e2)
02273 {
02274 struct EXTEND tmp;
02275
02276 e2->sign = ! e2->sign;
02277 add_ext(e1, e2, &tmp);
02278 e2->sign = ! e2->sign;
02279 if (tmp.m1 == 0 && tmp.m2 == 0) return 0;
02280 if (tmp.sign) return -1;
02281 return 1;
02282 }
02284 static
02285 b64_sft(struct mantissa *e1, int n)
02286 {
02287 if (n > 0) {
02288 if (n > 63) {
02289 e1->l_32 = 0;
02290 e1->h_32 = 0;
02291 return;
02292 }
02293 if (n >= 32) {
02294 e1->l_32 = e1->h_32;
02295 e1->h_32 = 0;
02296 n -= 32;
02297 }
02298 if (n > 0) {
02299 e1->l_32 >>= n;
02300 if (e1->h_32 != 0) {
02301 e1->l_32 |= (e1->h_32 << (32 - n));
02302 e1->h_32 >>= n;
02303 }
02304 }
02305 return;
02306 }
02307 n = -n;
02308 if (n > 0) {
02309 if (n > 63) {
02310 e1->l_32 = 0;
02311 e1->h_32 = 0;
02312 return;
02313 }
02314 if (n >= 32) {
02315 e1->h_32 = e1->l_32;
02316 e1->l_32 = 0;
02317 n -= 32;
02318 }
02319 if (n > 0) {
02320 e1->h_32 <<= n;
02321 if (e1->l_32 != 0) {
02322 e1->h_32 |= (e1->l_32 >> (32 - n));
02323 e1->l_32 <<= n;
02324 }
02325 }
02326 }
02327 }
02329 static int
02330 b64_add(struct mantissa *e1, struct mantissa *e2)
02331 /*
02332 * pointers to 64 bit 'registers'
02333 */
02334 {
02335 register int overflow;
02336 int carry;
02337
02338 /* add higher pair of 32 bits */
02339 overflow = ((unsigned long) 0xFFFFFFFF - e1->h_32 < e2->h_32);
02340 e1->h_32 += e2->h_32;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -