summaryrefslogtreecommitdiff
path: root/xc/lib/Xbsd
diff options
context:
space:
mode:
authorrws <empty>1991-01-11 13:32:14 +0000
committerrws <empty>1991-01-11 13:32:14 +0000
commit1ec08ce65721f721a192cdcfee64d9ee5ecf997c (patch)
tree3ecbb3488eac764279ef68ac4ea7f2192111f6d1 /xc/lib/Xbsd
parent151f3e8fae1a8559f90963ac898d034cb0d9722b (diff)
more frobbing
Diffstat (limited to 'xc/lib/Xbsd')
-rw-r--r--xc/lib/Xbsd/Berklib.c168
1 files changed, 121 insertions, 47 deletions
diff --git a/xc/lib/Xbsd/Berklib.c b/xc/lib/Xbsd/Berklib.c
index 217d0532d..44829a55d 100644
--- a/xc/lib/Xbsd/Berklib.c
+++ b/xc/lib/Xbsd/Berklib.c
@@ -1,4 +1,4 @@
-/* $XConsortium: Berklib.c,v 1.8 91/01/10 20:21:56 rws Exp $ */
+/* $XConsortium: Berklib.c,v 1.9 91/01/11 09:16:20 rws Exp $ */
/*
* These are routines found in BSD but not on all other systems. The core
@@ -20,13 +20,71 @@
#define WANT_RANDOM
#endif
+#ifdef SVR4
+#define WANT_BFUNCS
+#define WANT_FFS
+#define WANT_RANDOM
+#endif
+/* you should use Xfuncs.h in code instead of relying on Berklib */
#ifdef WANT_BFUNCS
-/* you should use Xfuncs.h instead of this in most cases */
-bcopy (b1, b2, length)
+#if __STDC__ && !defined(NOSTDHDRS)
+
+#include <string.h>
+
+void bcopy (b1, b2, length)
+ register char *b1, *b2;
+ register int length;
+{
+ memmove((void *)b2, (void *)b1, (size_t)length);
+}
+
+int bcmp (b1, b2, length)
+ register char *b1, *b2;
+ register int length;
+{
+ return memcmp((void *)b1, (void *)b2, (size_t)length);
+}
+
+void bzero (b, length)
+ register char *b;
+ register int length;
+{
+ memset((void *)b, 0, (size_t)length);
+}
+
+#else
+#if defined(SVR4) || defined(hpux)
+
+#include <string.h>
+
+void bcopy (b1, b2, length)
+ register char *b1, *b2;
+ register int length;
+{
+ memmove(b2, b1, length);
+}
+
+int bcmp (b1, b2, length)
+ register char *b1, *b2;
+ register int length;
+{
+ return memcmp(b1, b2, length);
+}
+
+bzero (b, length)
+ register char *b;
+ register int length;
+{
+ memset(b, 0, length);
+}
+
+#else
+
+void bcopy (b1, b2, length)
register char *b1, *b2;
- register length;
+ register int length;
{
if (b1 < b2) {
b2 += length;
@@ -39,38 +97,49 @@ bcopy (b1, b2, length)
}
}
-/* you should use Xfuncs.h instead of this in most cases */
-bcmp (b1, b2, length)
+#if defined(SYSV)
+
+#include <memory.h>
+
+int bcmp (b1, b2, length)
+ register char *b1, *b2;
+ register int length;
+{
+ return memcmp(b1, b2, length);
+}
+
+bzero (b, length)
+ register char *b;
+ register int length;
+{
+ memset(b, 0, length);
+}
+
+#else
+
+int bcmp (b1, b2, length)
register char *b1, *b2;
- register length;
+ register int length;
{
while (length--) {
if (*b1++ != *b2++) return 1;
}
return 0;
}
-#endif
-/* you should use Xfuncs.h instead of this in most cases */
-bzero (b, length)
+void bzero (b, length)
register char *b;
- register length;
+ register int length;
{
while (length--)
*b++ = '\0';
}
+#endif
+#endif
+#endif
#endif /* WANT_BFUNCS */
-/* Find the first set bit
- * i.e. least signifigant 1 bit:
- * 0 => 0
- * 1 => 1
- * 2 => 2
- * 3 => 1
- * 4 => 3
- */
-
#ifdef WANT_FFS
int
ffs(mask)
@@ -88,6 +157,38 @@ unsigned int mask;
}
#endif
+#ifdef WANT_RANDOM
+#if defined(SYSV) || defined(SVR4)
+
+long lrand48();
+
+long random()
+{
+ return (lrand48());
+}
+
+void srandom(seed)
+ int seed;
+{
+ srand48(seed);
+}
+
+#else
+
+long random()
+{
+ return (rand());
+}
+
+void srandom(seed)
+ int seed;
+{
+ srand(seed);
+}
+
+#endif
+#endif /* WANT_RANDOM */
+
/*
* insque, remque - insert/remove element from a queue
*
@@ -135,33 +236,6 @@ register struct qelem *elem;
#endif /* WANT_QUE */
/*
- * Berkeley random()
- *
- * We simulate via System V's rand()
- */
-
-#ifdef WANT_RANDOM
-int
-random()
-{
- return (rand());
-}
-
-/*
- * Berkeley srandom()
- *
- * We simulate via System V's rand()
- */
-
-int
-srandom(seed)
-int seed;
-{
- return (srand(seed));
-}
-#endif /* WANT_RANDOM */
-
-/*
* gettimeofday emulation
* Caution -- emulation is incomplete
* - has only second, not microsecond, resolution.