home *** CD-ROM | disk | FTP | other *** search
- /*
- l_compat.c
- */
- /* Copyright (c) 1994 Christian F. Tschudin. All rights reserved.
-
- Distributed under the terms of the GNU General Public License
- version 2 of june 1991 as published by the Free Software
- Foundation, Inc.
-
- This file is part of M0.
-
- M0 is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY. No author or distributor accepts responsibility to anyone for
- the consequences of using it or for whether it serves any particular
- purpose or works at all, unless he says so in writing. Refer to the GNU
- General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute M0, but
- only under the conditions described in the GNU General Public License.
- A copy of this license is supposed to have been given to you along with
- M0 so you can know your rights and responsibilities. It should be in a
- file named LICENSE. Among other things, the copyright notice and this
- notice must be preserved on all copies. */
-
- #include "l_proto.h"
-
-
- /* fillin_hostid -------------------------------------------------- */
-
- void
- fillin_hostid(byteptr s)
- {
- #ifdef __MSDOS__
- memcpy((char*)s, " MS/DOS ", 8);
- #else
- #include <sys/utsname.h>
- struct utsname uts;
- byteptr p = (byteptr) &uts;
- int i;
-
- memset((char*)p, 0, sizeof(uts));
- uname(&uts);
- memset((char*)s, 0, 8);
- for (i = 0; i < sizeof(uts); i++)
- s[i%8] ^= *p++;
- #endif
- }
-
-
- /* get_utc ---------------------------------------------------------- */
-
- #include <time.h>
-
- void
- get_utc(uint *sec, uint *usec)
- {
- #ifdef SUNOS5
- struct timespec t;
- clock_gettime(CLOCK_REALTIME, &t);
- *sec = t.tv_sec;
- *usec = t.tv_nsec / 1000;
- #else /* !SUNOS5 */
- # include <sys/timeb.h>
- struct timeb t;
- ftime(&t);
- *sec = t.time;
- *usec = 1000L * t.millitm;
- #endif /* !SUNOS5 */
- }
-
-
- /* random ---------------------------------------------------------- */
-
- #ifdef SUNOS5
- long
- random()
- {
- uint r = 0;
- int i;
-
- for (i = 0; i < 5; i++)
- r ^= lrand48() << (7*i);
- return (long) r;
- }
-
- void
- srandom(long t)
- {
- srand48(t);
- }
- #endif /* SUNOS5 *.
-
-
- #ifdef unix
- void
- randomize()
- {
- srandom(time(NULL));
- }
- #endif /* unix */
-
-
- /* strdup ---------------------------------------------------------- */
-
- #ifdef __ultrix
- byteptr
- strdup(byteptr s)
- {
- return (byteptr)strcpy(malloc(strlen((char *)s)+1), (char *)s);
- }
- #endif /* __ultrix */
-