* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / libc / misc / syslib.c
blob3aa596302354951bf6ce5503ac79fd254eafbd94
1 /* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
2 * This file is part of the Linux-8086 C library and is distributed
3 * under the GNU Library General Public License.
4 */
6 #include <sys/types.h>
7 #include <sys/time.h>
8 #include <errno.h>
9 #include <time.h>
10 #include <signal.h>
11 #include <sys/stat.h>
13 /* This only for the various unix version */
14 #ifdef __unix__
16 /********************** Function time ************************************/
18 #ifdef L_time
19 time_t time(where)
20 time_t *where;
22 struct timeval rv;
23 if( gettimeofday(&rv, (void*)0) < 0 ) return -1;
24 if(where) *where = rv.tv_sec;
25 return rv.tv_sec;
27 #endif
29 /********************** Function abort ************************************/
31 #ifdef L_abort
33 int abort()
35 signal(SIGABRT, SIG_DFL);
36 kill(SIGABRT, getpid()); /* Correct one */
37 pause(); /* System may just schedule */
38 signal(SIGKILL, SIG_DFL);
39 kill(SIGKILL, getpid()); /* Can't trap this! */
40 __exit(255); /* WHAT!! */
42 #endif
44 /********************** Function wait ************************************/
46 #ifdef L_wait
47 int
48 wait(status)
49 int * status;
51 return wait4(-1, status, 0, (void*)0);
53 #endif
55 /********************** Function wait3 **************************************/
57 #ifdef L_wait3
58 int
59 wait3(status, opts, usage)
60 int * status;
61 int opts;
62 struct rusage * usage;
64 return wait4(-1, status, opts, usage);
66 #endif
68 /********************** Function waitpid ************************************/
70 #ifdef L_waitpid
71 int
72 waitpid(pid, status, opts)
73 int pid;
74 int * status;
75 int opts;
77 return wait4(pid, status, opts, (void*)0);
79 #endif
81 /********************** Function killpg ************************************/
83 #ifdef L_killpg
84 int
85 killpg(pid, sig)
86 int pid;
87 int sig;
89 if(pid == 0)
90 pid = getpgrp();
91 if(pid > 1)
92 return kill(-pid, sig);
93 errno = EINVAL;
94 return -1;
96 #endif
98 /********************** Function setpgrp ************************************/
100 #ifdef L_setpgrp
102 setpgrp()
104 return setpgid(0,0);
106 #endif
108 /********************** Function sleep ************************************/
110 #ifdef L_sleep
112 #ifdef __ELKS__
113 /* This uses SIGALRM, it does keep the previous alarm call but will lose
114 * any alarms that go off during the sleep
117 static void alrm() { }
119 unsigned int sleep(seconds)
120 unsigned int seconds;
122 void (*last_alarm)();
123 unsigned int prev_sec;
125 prev_sec = alarm(0);
126 if( prev_sec <= seconds ) prev_sec = 1; else prev_sec -= seconds;
128 last_alarm = signal(SIGALRM, alrm);
129 alarm(seconds);
130 pause();
131 seconds = alarm(prev_sec);
132 signal(SIGALRM, last_alarm);
133 return seconds;
136 #else
137 /* Is this a better way ? If we have select of course :-) */
138 unsigned int
139 sleep(seconds)
140 unsigned int seconds;
142 struct timeval timeout;
143 time_t start = time((void*)0);
144 timeout.tv_sec = seconds;
145 timeout.tv_usec = 0;
146 select(1, NULL, NULL, NULL, &timeout);
147 return seconds - (time((void*)0) - start);
149 #endif
151 #endif
153 /********************** Function usleep ************************************/
155 #ifdef L_usleep
156 void
157 usleep(useconds)
158 unsigned long useconds;
160 struct timeval timeout;
161 timeout.tv_sec = useconds%1000000L;
162 timeout.tv_usec = useconds/1000000L;
163 select(1, NULL, NULL, NULL, &timeout);
165 #endif
167 /********************** Function mkfifo ************************************/
169 #ifdef L_mkfifo
171 mkfifo(path, mode)
172 char * path;
173 int mode;
175 return mknod(path, mode | S_IFIFO, 0);
177 #endif
179 /********************** THE END ********************************************/
181 #endif /* __unix__ */