2
|
1 /*--------------------------------------------------------------------------
|
|
2 NETREK II -- Paradise
|
|
3
|
|
4 Permission to use, copy, modify, and distribute this software and its
|
|
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
|
|
6 purpose and without fee is hereby granted, provided that this copyright
|
|
7 notice appear in all copies. No representations are made about the
|
|
8 suitability of this software for any purpose. This software is provided
|
|
9 "as is" without express or implied warranty.
|
|
10
|
|
11 Xtrek Copyright 1986 Chris Guthrie
|
|
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
|
|
13 Scott Silvey
|
|
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
|
|
15 Kurt Olsen
|
|
16 Brandon Gillespie
|
|
17 --------------------------------------------------------------------------*/
|
|
18
|
|
19 /* cutil.c - misc utility fuctions common to all the binaries */
|
|
20
|
|
21 #include "config.h"
|
|
22 #ifndef apollo
|
|
23 #include <unistd.h>
|
|
24 #endif
|
|
25 #include <stdio.h>
|
|
26 #include <stdlib.h>
|
|
27 #include <string.h>
|
|
28 #include <signal.h>
|
|
29 #include <sys/types.h>
|
|
30 #ifdef hpux
|
|
31 #include <time.h>
|
|
32 #else
|
|
33 #include <sys/time.h>
|
|
34 #endif
|
|
35 #ifdef SYSV
|
|
36 #include <utime.h>
|
|
37 #endif
|
|
38 #include <math.h>
|
|
39 #include "data.h"
|
|
40
|
|
41 /*
|
|
42 * r_signal - reliable version of signal() the System-V signal() function
|
|
43 * provides the older, unreliable signal semantics. So, this is an
|
|
44 * implementation of signal using sigaction.
|
|
45 */
|
|
46
|
|
47 void (*
|
|
48 r_signal(sig, func)) ()
|
|
49 int sig;
|
|
50 void (*func) ();
|
|
51 {
|
|
52 struct sigaction act, oact;
|
|
53
|
|
54 act.sa_handler = func;
|
|
55
|
|
56 sigemptyset(&act.sa_mask);
|
|
57 act.sa_flags = 0;
|
|
58 #ifdef SA_RESTART
|
|
59 #ifdef BAD_SVR4_HACKS
|
|
60 if (sig != SIGALRM)
|
|
61 #endif /* BAD_SVR4_HACKS */
|
|
62 act.sa_flags |= SA_RESTART;
|
|
63 #endif
|
|
64
|
|
65 if (sigaction(sig, &act, &oact) < 0)
|
|
66 return (SIG_ERR);
|
|
67
|
|
68 return (oact.sa_handler);
|
|
69 }
|
|
70
|
|
71
|
|
72 int
|
|
73 touch(file)
|
|
74 char *file;
|
|
75 {
|
|
76 time_t now[2];
|
|
77
|
|
78 now[0] = now[1] = time(0);
|
|
79
|
|
80 return utime(file, (void *) now);
|
|
81 }
|
|
82
|
|
83 #ifdef NO_STRDUP
|
|
84 char *
|
|
85 strdup(str)
|
|
86 char *str;
|
|
87 {
|
|
88 char *s;
|
|
89
|
|
90 s = (char *) malloc(strlen(str) + 1);
|
|
91 if (!s)
|
|
92 return NULL;
|
|
93 strcpy(s, str);
|
|
94 return s;
|
|
95 }
|
|
96 #endif
|
|
97
|
|
98
|
|
99 /* dunno if any other systems have anyting like this */
|
|
100 #ifdef hpux
|
|
101
|
|
102 int
|
|
103 matherr(x)
|
|
104 struct exception *x;
|
|
105 {
|
|
106 char *t;
|
|
107
|
|
108 switch (x->type)
|
|
109 {
|
|
110 case DOMAIN:
|
|
111 t = "domain";
|
|
112 break;
|
|
113 case SING:
|
|
114 t = "singularity";
|
|
115 break;
|
|
116 case OVERFLOW:
|
|
117 t = "overflow";
|
|
118 break;
|
|
119 case UNDERFLOW:
|
|
120 t = "underflow";
|
|
121 break;
|
|
122 case TLOSS:
|
|
123 t = "tloss";
|
|
124 break;
|
|
125 case PLOSS:
|
|
126 t = "ploss";
|
|
127 break;
|
|
128 default:
|
|
129 t = "buh??";
|
|
130 break;
|
|
131 }
|
|
132 fprintf(stderr, "%s: %s error: %s(%f [, %f]) = %f\n",
|
|
133 argv0, t, x->name, x->arg1, x->arg2, x->retval);
|
|
134 }
|
|
135
|
|
136 #endif
|