|
| 1 | +/*------------------------------------------------------------------------- |
| 2 | + * |
| 3 | + * port.c-- |
| 4 | + * Intel x86/Intel SVR4-specific routines |
| 5 | + * |
| 6 | + * Copyright (c) 1994, Regents of the University of California |
| 7 | + * |
| 8 | + * |
| 9 | + * IDENTIFICATION |
| 10 | + * /usr/local/devel/pglite/cvs/src/backend/port/svr4/port.c,v 1.2 1995/03/17 06:40:19 andrew Exp |
| 11 | + * |
| 12 | + *------------------------------------------------------------------------- |
| 13 | + */ |
| 14 | +#include <math.h> /* for pow() prototype */ |
| 15 | + |
| 16 | +#include <errno.h> |
| 17 | +#include "rusagestub.h" |
| 18 | + |
| 19 | +long |
| 20 | +random() |
| 21 | +{ |
| 22 | + return(lrand48()); |
| 23 | +} |
| 24 | + |
| 25 | +void |
| 26 | +srandom(int seed) |
| 27 | +{ |
| 28 | + srand48((long int) seed); |
| 29 | +} |
| 30 | + |
| 31 | +int |
| 32 | +getrusage(int who, struct rusage *rusage) |
| 33 | +{ |
| 34 | + struct tms tms; |
| 35 | + register int tick_rate = CLK_TCK; /* ticks per second */ |
| 36 | + clock_t u, s; |
| 37 | + |
| 38 | + if (rusage == (struct rusage *) NULL) { |
| 39 | + errno = EFAULT; |
| 40 | + return(-1); |
| 41 | + } |
| 42 | + if (times(&tms) < 0) { |
| 43 | + /* errno set by times */ |
| 44 | + return(-1); |
| 45 | + } |
| 46 | + switch (who) { |
| 47 | + case RUSAGE_SELF: |
| 48 | + u = tms.tms_utime; |
| 49 | + s = tms.tms_stime; |
| 50 | + break; |
| 51 | + case RUSAGE_CHILDREN: |
| 52 | + u = tms.tms_cutime; |
| 53 | + s = tms.tms_cstime; |
| 54 | + break; |
| 55 | + default: |
| 56 | + errno = EINVAL; |
| 57 | + return(-1); |
| 58 | + } |
| 59 | +#define TICK_TO_SEC(T, RATE) ((T)/(RATE)) |
| 60 | +#define TICK_TO_USEC(T,RATE) (((T)%(RATE)*1000000)/RATE) |
| 61 | + rusage->ru_utime.tv_sec = TICK_TO_SEC(u, tick_rate); |
| 62 | + rusage->ru_utime.tv_usec = TICK_TO_USEC(u, tick_rate); |
| 63 | + rusage->ru_stime.tv_sec = TICK_TO_SEC(s, tick_rate); |
| 64 | + rusage->ru_stime.tv_usec = TICK_TO_USEC(u, tick_rate); |
| 65 | + return(0); |
| 66 | +} |
| 67 | + |
| 68 | +/* |
| 69 | + * Copyright (c) 1987 Regents of the University of California. |
| 70 | + * All rights reserved. |
| 71 | + * |
| 72 | + * Redistribution and use in source and binary forms are permitted |
| 73 | + * provided that this notice is preserved and that due credit is given |
| 74 | + * to the University of California at Berkeley. The name of the University |
| 75 | + * may not be used to endorse or promote products derived from this |
| 76 | + * software without specific written prior permission. This software |
| 77 | + * is provided ``as is'' without express or implied warranty. |
| 78 | + */ |
| 79 | + |
| 80 | +#if defined(LIBC_SCCS) && !defined(lint) |
| 81 | +static char sccsid[] = "@(#)strcasecmp.c 5.5 (Berkeley) 11/24/87"; |
| 82 | +#endif /* LIBC_SCCS and not lint */ |
| 83 | + |
| 84 | +#include <sys/types.h> |
| 85 | +#include <string.h> |
| 86 | + |
| 87 | +/* |
| 88 | + * This array is designed for mapping upper and lower case letter |
| 89 | + * together for a case independent comparison. The mappings are |
| 90 | +p * based upon ascii character sequences. |
| 91 | + */ |
| 92 | +static unsigned char charmap[] = { |
| 93 | + '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', |
| 94 | + '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', |
| 95 | + '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', |
| 96 | + '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', |
| 97 | + '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', |
| 98 | + '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', |
| 99 | + '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', |
| 100 | + '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', |
| 101 | + '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', |
| 102 | + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', |
| 103 | + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', |
| 104 | + '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', |
| 105 | + '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', |
| 106 | + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', |
| 107 | + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', |
| 108 | + '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', |
| 109 | + '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', |
| 110 | + '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', |
| 111 | + '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', |
| 112 | + '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', |
| 113 | + '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', |
| 114 | + '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', |
| 115 | + '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', |
| 116 | + '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', |
| 117 | + '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', |
| 118 | + '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', |
| 119 | + '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', |
| 120 | + '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', |
| 121 | + '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', |
| 122 | + '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', |
| 123 | + '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', |
| 124 | + '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', |
| 125 | +}; |
| 126 | + |
| 127 | +int |
| 128 | +strcasecmp(char *s1, char *s2) |
| 129 | +{ |
| 130 | + register unsigned char u1, u2; |
| 131 | + |
| 132 | + for (;;) { |
| 133 | + u1 = (unsigned char) *s1++; |
| 134 | + u2 = (unsigned char) *s2++; |
| 135 | + if (charmap[u1] != charmap[u2]) { |
| 136 | + return charmap[u1] - charmap[u2]; |
| 137 | + } |
| 138 | + if (u1 == '\0') { |
| 139 | + return 0; |
| 140 | + } |
| 141 | + } |
| 142 | +} |
| 143 | + |
0 commit comments