author | Claus Gittinger <cg@exept.de> |
Sun, 04 Feb 1996 20:06:39 +0100 | |
changeset 932 | f57ec42ceb44 |
parent 914 | d00401a9450e |
child 947 | 2d067b1d716c |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
185 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
13 |
'From Smalltalk/X, Version:2.10.8 on 29-dec-1995 at 00:13:58' ! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
14 |
|
1 | 15 |
Object subclass:#OperatingSystem |
798
90a518c71a7f
recursiveRemoveDirectory does not print garbage to stderr any longer; computeDateAndTimeFrom: now returns the utcOffset
Stefan Vogel <sv@exept.de>
parents:
792
diff
changeset
|
16 |
instanceVariableNames:'' |
90a518c71a7f
recursiveRemoveDirectory does not print garbage to stderr any longer; computeDateAndTimeFrom: now returns the utcOffset
Stefan Vogel <sv@exept.de>
parents:
792
diff
changeset
|
17 |
classVariableNames:'HostName DomainName LastErrorNumber LastExecStatus OSSignals |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
18 |
SlowFork ForkFailed ErrorSignal AccessDeniedErrorSignal |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
19 |
FileNotFoundErrorSignal |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
20 |
LocaleInfo' |
798
90a518c71a7f
recursiveRemoveDirectory does not print garbage to stderr any longer; computeDateAndTimeFrom: now returns the utcOffset
Stefan Vogel <sv@exept.de>
parents:
792
diff
changeset
|
21 |
poolDictionaries:'' |
90a518c71a7f
recursiveRemoveDirectory does not print garbage to stderr any longer; computeDateAndTimeFrom: now returns the utcOffset
Stefan Vogel <sv@exept.de>
parents:
792
diff
changeset
|
22 |
category:'System-Support' |
1 | 23 |
! |
24 |
||
437 | 25 |
!OperatingSystem primitiveDefinitions! |
406 | 26 |
%{ |
792 | 27 |
#define UNIX_LIKE |
28 |
||
831 | 29 |
#if defined(MSWINDOWS) || defined(OS2) || defined(MSDOS) || defined(WIN32) |
792 | 30 |
# ifndef MSDOS_LIKE |
31 |
# define MSDOS_LIKE |
|
32 |
# endif |
|
33 |
# undef UNIX_LIKE |
|
831 | 34 |
# ifdef i386 |
35 |
# define _X86_ |
|
36 |
# endif |
|
792 | 37 |
#endif |
38 |
||
39 |
#if defined(transputer) |
|
40 |
# undef MSDOS_LIKE |
|
41 |
# undef UNIX_LIKE |
|
42 |
#endif |
|
43 |
||
443 | 44 |
#if defined(_AIX) |
439 | 45 |
# ifndef WANT_REALPATH |
46 |
# define WANT_REALPATH |
|
47 |
# endif |
|
513
0347f6d11d76
interruptable system() on AIX
Claus Gittinger <cg@exept.de>
parents:
512
diff
changeset
|
48 |
# ifndef WANT_SYSTEM |
0347f6d11d76
interruptable system() on AIX
Claus Gittinger <cg@exept.de>
parents:
512
diff
changeset
|
49 |
# define WANT_SYSTEM |
0347f6d11d76
interruptable system() on AIX
Claus Gittinger <cg@exept.de>
parents:
512
diff
changeset
|
50 |
# endif |
406 | 51 |
#endif |
52 |
||
433 | 53 |
#ifdef LINUX |
439 | 54 |
# ifndef WANT_SYSTEM |
55 |
# define WANT_SYSTEM |
|
56 |
# endif |
|
443 | 57 |
# define WANT_SHM |
433 | 58 |
#endif |
59 |
||
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
60 |
#ifdef IRIX5 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
61 |
# define WANT_SYSTEM |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
62 |
#endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
63 |
|
514
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
64 |
#ifdef ultrix |
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
65 |
# define WANT_SYSTEM |
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
66 |
#endif |
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
67 |
|
515
43d76695a662
interruptable system() on hpux
Claus Gittinger <cg@exept.de>
parents:
514
diff
changeset
|
68 |
#ifdef hpux |
43d76695a662
interruptable system() on hpux
Claus Gittinger <cg@exept.de>
parents:
514
diff
changeset
|
69 |
# define WANT_SYSTEM |
43d76695a662
interruptable system() on hpux
Claus Gittinger <cg@exept.de>
parents:
514
diff
changeset
|
70 |
#endif |
43d76695a662
interruptable system() on hpux
Claus Gittinger <cg@exept.de>
parents:
514
diff
changeset
|
71 |
|
805 | 72 |
#if defined(SYSV4) && defined(i386) /* e.g. unixware */ |
520
9620f7dc79d2
interruptable system() on unixware - should now move WANT_SYSTEM into xxxIntern files
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
73 |
# define WANT_SYSTEM |
9620f7dc79d2
interruptable system() on unixware - should now move WANT_SYSTEM into xxxIntern files
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
74 |
#endif |
9620f7dc79d2
interruptable system() on unixware - should now move WANT_SYSTEM into xxxIntern files
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
75 |
|
831 | 76 |
/* |
77 |
* notice: although many systems' include files |
|
78 |
* already block against multiple inclusion, some |
|
79 |
* do not. Therefore, this is done here again. |
|
80 |
* (it does not hurt) |
|
81 |
*/ |
|
82 |
||
439 | 83 |
#ifdef WANT_REALPATH |
831 | 84 |
|
439 | 85 |
# include <sys/param.h> |
86 |
# define _SYS_PARAM_H_INCLUDED_ |
|
87 |
||
88 |
# include <errno.h> |
|
89 |
# define _ERRNO_H_INCLUDED_ |
|
90 |
||
91 |
# include <sys/stat.h> |
|
92 |
# define _SYS_STAT_H_INCLUDED_ |
|
443 | 93 |
|
439 | 94 |
#endif /* WANT_REALPATH */ |
95 |
||
831 | 96 |
|
97 |
||
434 | 98 |
#ifdef WANT_SHM |
443 | 99 |
extern int shmctl(), shmget(), shmdt(); |
100 |
extern char * shmat(); |
|
101 |
||
434 | 102 |
# include <sys/types.h> |
437 | 103 |
# define _SYS_TYPES_H_INCLUDED_ |
439 | 104 |
|
434 | 105 |
# include <sys/ipc.h> |
437 | 106 |
# define _SYS_IPC_H_INCLUDED_ |
439 | 107 |
|
434 | 108 |
# include <sys/shm.h> |
437 | 109 |
# define _SYS_SHM_H_INCLUDED_ |
831 | 110 |
|
439 | 111 |
#endif /* WANT_SHM */ |
434 | 112 |
|
831 | 113 |
|
434 | 114 |
#ifdef IRIX5 |
115 |
# include <sys/syssgi.h> |
|
116 |
#endif |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
117 |
|
831 | 118 |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
119 |
#ifdef transputer |
831 | 120 |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
121 |
# define unlink(f) ((remove(f) == 0) ? 0 : -1) |
831 | 122 |
|
123 |
#else /* not transputer */ |
|
124 |
||
125 |
# ifndef _SIGNAL_H_INCLUDED_ |
|
126 |
# include <signal.h> |
|
127 |
# define _SIGNAL_H_INCLUDED_ |
|
128 |
# endif |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
129 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
130 |
# ifdef SYSV |
831 | 131 |
# ifndef _SYS_TYPES_H_INCLUDED_ |
132 |
# include <sys/types.h> |
|
133 |
# define _SYS_TYPES_H_INCLUDED_ |
|
134 |
# endif |
|
135 |
# ifndef _SYS_PARAM_H_INCLUDED_ |
|
136 |
# include <sys/param.h> |
|
137 |
# define _SYS_PARAM_H_INCLUDED_ |
|
138 |
# endif |
|
139 |
# ifndef _SYS_TIMES_H_INCLUDED_ |
|
140 |
# include <sys/times.h> |
|
141 |
# define _SYS_TIMES_H_INCLUDED_ |
|
142 |
# endif |
|
143 |
# ifndef _SYS_FILE_H_INCLUDED_ |
|
144 |
# include <sys/file.h> |
|
145 |
# define _SYS_FILE_H_INCLUDED_ |
|
146 |
# endif |
|
147 |
||
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
148 |
# if ! defined(sco3_2) |
831 | 149 |
# ifndef _UNISTD_H_INCLUDED_ |
150 |
# include <unistd.h> |
|
151 |
# define _UNISTD_H_INCLUDED_ |
|
152 |
# endif |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
153 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
154 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
155 |
# if defined(isc3_2) || defined(sco3_2) |
831 | 156 |
# ifndef _SYS_TIME_H_INCLUDED_ |
157 |
# include <sys/time.h> |
|
158 |
# define _SYS_TIME_H_INCLUDED_ |
|
159 |
# endif |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
160 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
161 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
162 |
# if !defined(isc3_2) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
163 |
# if defined(PCS) && defined(mips) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
164 |
# include "/usr/include/bsd/sys/time.h" |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
165 |
# include "/usr/include/sys/time.h" |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
166 |
# else |
831 | 167 |
# ifndef _TIME_H_INCLUDED_ |
168 |
# include <time.h> |
|
169 |
# define _TIME_H_INCLUDED_ |
|
170 |
# endif |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
171 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
172 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
173 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
174 |
# if defined(isc3_2) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
175 |
# include <sys/bsdtypes.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
176 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
177 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
178 |
# else /* not SYSV */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
179 |
|
802 | 180 |
# ifdef MSDOS_LIKE |
831 | 181 |
|
182 |
# ifndef _SYS_TYPES_H_INCLUDED_ |
|
183 |
# include <sys/types.h> |
|
184 |
# define _SYS_TYPES_H_INCLUDED_ |
|
185 |
# endif |
|
186 |
# ifndef _TIME_H_INCLUDED_ |
|
187 |
# include <time.h> |
|
188 |
# define _TIME_H_INCLUDED_ |
|
189 |
# endif |
|
190 |
# ifndef _SYS_TIMEB_H_INCLUDED_ |
|
191 |
# include <sys/timeb.h> |
|
192 |
# define _SYS_TIMEB_H_INCLUDED_ |
|
193 |
# endif |
|
194 |
||
195 |
# else /* not MSDOS_like */ |
|
196 |
||
197 |
# ifndef _SYS_TIME_H_INCLUDED_ |
|
198 |
# include <sys/time.h> |
|
199 |
# define _SYS_TIME_H_INCLUDED_ |
|
200 |
# endif |
|
201 |
# ifndef _SYS_TYPES_H_INCLUDED_ |
|
202 |
# include <sys/types.h> |
|
203 |
# define _SYS_TYPES_H_INCLUDED_ |
|
204 |
# endif |
|
205 |
||
206 |
# endif /* not MSDOS */ |
|
792 | 207 |
# endif /* not SYSV */ |
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
208 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
209 |
# ifdef aix |
831 | 210 |
|
211 |
# ifndef _TIME_H_INCLUDED_ |
|
212 |
# include <time.h> |
|
914
d00401a9450e
Fix syntax error (#defined -> #define).
Stefan Vogel <sv@exept.de>
parents:
855
diff
changeset
|
213 |
# define _TIME_H_INCLUDED_ |
831 | 214 |
# endif |
215 |
# ifndef _SYS_SELECT_H_INCLUDED_ |
|
216 |
# include <sys/select.h> |
|
217 |
# define _SYS_SELECT_H_INCLUDED_ |
|
218 |
# endif |
|
219 |
||
792 | 220 |
# endif /* aix */ |
221 |
||
222 |
# ifndef MSDOS_LIKE |
|
223 |
# include <pwd.h> |
|
224 |
# include <grp.h> |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
225 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
226 |
|
831 | 227 |
# ifndef _SYS_STAT_H_INCLUDED_ |
228 |
# include <sys/stat.h> |
|
229 |
# endif |
|
230 |
||
231 |
# ifndef _ERRNO_H_INCLUDED_ |
|
232 |
# include <errno.h> |
|
233 |
# define _ERRNO_H_INCLUDED_ |
|
234 |
# endif |
|
235 |
||
236 |
# ifndef _STDIO_H_INCLUDED_ |
|
237 |
# include <stdio.h> |
|
238 |
# define _STDIO_H_INCLUDED_ |
|
239 |
# endif |
|
240 |
||
241 |
# ifndef _FCNTL_H_INCLUDED_ |
|
242 |
# include <fcntl.h> |
|
243 |
# define _FCNTL_H_INCLUDED_ |
|
244 |
# endif |
|
245 |
||
246 |
# ifdef WIN32 |
|
247 |
# undef INT |
|
248 |
# undef Array |
|
249 |
# undef Number |
|
250 |
# undef Method |
|
251 |
# undef Point |
|
252 |
||
253 |
/* # include <windows.h> /* */ |
|
254 |
# include <stdarg.h> /* */ |
|
255 |
# include <windef.h> /* */ |
|
256 |
# include <winbase.h> /* */ |
|
257 |
# include <wingdi.h> /* */ |
|
258 |
# include <winuser.h> /* */ |
|
259 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
260 |
# ifdef __VM_Array |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
261 |
# define Array __VM_Array |
831 | 262 |
# endif |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
263 |
# ifdef __VM_Number |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
264 |
# define Number __VM_Number |
831 | 265 |
# endif |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
266 |
# ifdef __VM_Method |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
267 |
# define Method __VM_Method |
831 | 268 |
# endif |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
269 |
# ifdef __VM_Point |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
270 |
# define Point __VM_Point |
831 | 271 |
# endif |
272 |
# endif |
|
273 |
||
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
274 |
|
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
275 |
# if defined(LINUX) |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
276 |
# define HAS_LOCALECONV |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
277 |
# endif |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
278 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
279 |
# if defined (HAS_LOCALECONV) |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
280 |
# ifndef _LOCALE_H_INCLUDED_ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
281 |
# include <locale.h> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
282 |
# define _LOCALE_H_INCLUDED_ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
283 |
# endif |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
284 |
# endif |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
285 |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
286 |
/* |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
287 |
* posix systems should define these ... |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
288 |
* but on some (older) systems, they are not. |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
289 |
*/ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
290 |
# ifndef S_IXUSR |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
291 |
# ifdef S_IEXEC |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
292 |
# define S_IXUSR S_IEXEC |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
293 |
# define S_IXGRP (S_IEXEC>>3) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
294 |
# define S_IXOTH (S_IEXEC>>6) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
295 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
296 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
297 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
298 |
# ifndef S_IXUSR |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
299 |
# define S_IXUSR 0100 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
300 |
# define S_IXGRP 0010 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
301 |
# define S_IXOTH 0001 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
302 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
303 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
304 |
# ifndef S_IRUSR |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
305 |
# define S_IRUSR 0400 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
306 |
# define S_IRGRP 0040 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
307 |
# define S_IROTH 0004 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
308 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
309 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
310 |
# ifndef S_IWUSR |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
311 |
# define S_IWUSR 0200 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
312 |
# define S_IWGRP 0020 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
313 |
# define S_IWOTH 0002 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
314 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
315 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
316 |
# ifndef MAXPATHLEN |
792 | 317 |
# ifndef MSDOS_LIKE |
318 |
# include <sys/param.h> |
|
319 |
# endif |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
320 |
# ifndef MAXPATHLEN |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
321 |
# ifdef FILENAME_MAX /* i.e. MSDOS_LIKE */ |
792 | 322 |
# define MAXPATHLEN FILENAME_MAX |
323 |
# else |
|
324 |
# define MAXPATHLEN 1024 |
|
325 |
# endif |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
326 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
327 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
328 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
329 |
# if defined(HAS_UNAME) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
330 |
# include <sys/utsname.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
331 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
332 |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
333 |
# if defined(SYSV4) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
334 |
# include <stropts.h> |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
335 |
# endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
336 |
|
763
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
337 |
/* |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
338 |
* sigaction dummies (you won't believe these call themself ``POSIX'' systems ...) |
763
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
339 |
*/ |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
340 |
# ifndef SA_RESTART |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
341 |
# define SA_RESTART 0 |
763
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
342 |
# endif |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
343 |
# ifndef SA_SIGINFO |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
344 |
# define SA_SIGINFO 0 |
763
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
345 |
# endif |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
346 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
347 |
# if defined(HAS_WAITPID) || defined(HAS_WAIT3) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
348 |
# include <sys/wait.h> |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
349 |
# endif |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
350 |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
351 |
#endif /* ! transputer */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
352 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
353 |
/* |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
354 |
* on some systems errno is a macro ... check for it here |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
355 |
*/ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
356 |
#ifndef errno |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
357 |
extern errno; |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
358 |
#endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
359 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
360 |
/* |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
361 |
* some (old ?) systems do not define this ... |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
362 |
*/ |
675 | 363 |
#if !defined(R_OK) && !defined(_AIX) |
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
364 |
# define R_OK 4 /* Test for Read permission */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
365 |
# define W_OK 2 /* Test for Write permission */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
366 |
# define X_OK 1 /* Test for eXecute permission */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
367 |
# define F_OK 0 /* Test for existence of File */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
368 |
#endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
369 |
|
832 | 370 |
#ifdef WIN32 |
371 |
# define SIGHANDLER_ARG int |
|
372 |
#else |
|
373 |
# define SIGHANDLER_ARG |
|
374 |
#endif |
|
375 |
||
437 | 376 |
%} |
377 |
! ! |
|
378 |
||
379 |
!OperatingSystem primitiveFunctions! |
|
380 |
%{ |
|
381 |
||
382 |
/* |
|
383 |
* some systems' system() is broken in that it does not correctly |
|
384 |
* handle EINTR and returns failure even though it actually succeeded. |
|
385 |
* (LINUX is one of them) |
|
386 |
* Here is a fixed version. If you encounter EINTR returns from |
|
387 |
* OperatingSystem>>executeCommand, you ought to define WANT_SYSTEM |
|
388 |
* in the xxxIntern.h file to get this fixed version. |
|
389 |
* |
|
390 |
* As an added BONUS, this system() enables interrupts while waiting |
|
391 |
* for the child which enables other threads to continue. |
|
507
a7780fc27ee9
mad system interuptable (needs WANT_SYSTEM to be defined in xxxIntern.h)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
392 |
* (i.e. it is RT safe) |
437 | 393 |
*/ |
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
394 |
|
433 | 395 |
#if defined(WANT_SYSTEM) |
396 |
||
434 | 397 |
/* # define DPRINTF(x) printf x */ |
398 |
# define DPRINTF(x) /* nothing */ |
|
433 | 399 |
|
437 | 400 |
# ifndef _STDDEF_H_INCLUDED_ |
401 |
# include <stddef.h> |
|
402 |
# define _STDDEF_H_INCLUDED_ |
|
403 |
# endif |
|
404 |
||
405 |
# ifndef _STDLIB_H_INCLUDED_ |
|
406 |
# include <stdlib.h> |
|
407 |
# define _STDLIB_H_INCLUDED_ |
|
408 |
# endif |
|
409 |
||
410 |
# ifndef _UNISTD_H_INCLUDED_ |
|
411 |
# include <unistd.h> |
|
412 |
# define _UNISTD_H_INCLUDED_ |
|
413 |
# endif |
|
414 |
||
415 |
# ifndef _SYS_WAIT_H_INCLUDED |
|
416 |
# include <sys/wait.h> |
|
417 |
# define _SYS_WAIT_H_INCLUDED |
|
418 |
# endif |
|
419 |
||
420 |
# ifndef _SIGNAL_H_INCLUDED_ |
|
421 |
# include <signal.h> |
|
422 |
# define _SIGNAL_H_INCLUDED_ |
|
423 |
# endif |
|
424 |
||
425 |
# ifndef _SYS_TYPES_H_INCLUDED_ |
|
426 |
# include <sys/types.h> |
|
427 |
# define _SYS_TYPES_H_INCLUDED_ |
|
428 |
# endif |
|
433 | 429 |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
430 |
# if (!defined(HAVE_GNU_LD) && !defined (__ELF__)) || !defined(LINUX) |
433 | 431 |
# define __environ environ |
512 | 432 |
# if !defined(LINUX) |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
433 |
# define __sigemptyset sigemptyset |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
434 |
# define __sigaction sigaction |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
435 |
# define __sigaddset sigaddset |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
436 |
# define __sigprocmask sigprocmask |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
437 |
# define __execve execve |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
438 |
# define __wait wait |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
439 |
# define __waitpid waitpid |
674 | 440 |
# if defined(HAS_VFORK) |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
441 |
# define FORK vfork |
514
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
442 |
# else |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
443 |
# define FORK fork |
514
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
444 |
# endif |
512 | 445 |
# endif /* ! LINUX */ |
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
446 |
extern char **environ; |
433 | 447 |
# endif |
448 |
||
449 |
# define SHELL_PATH "/bin/sh" /* Path of the shell. */ |
|
450 |
# define SHELL_NAME "sh" /* Name to give it. */ |
|
451 |
||
452 |
# ifndef FORK |
|
453 |
# define FORK __fork |
|
454 |
# endif |
|
455 |
||
456 |
# ifndef CONST |
|
457 |
# ifdef __GNUC__ |
|
458 |
# define CONST const |
|
459 |
# else |
|
460 |
# define CONST /* nothing */ |
|
461 |
# endif |
|
462 |
# endif |
|
463 |
||
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
464 |
static int |
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
465 |
mySystem(line) |
433 | 466 |
register CONST char *line; |
467 |
{ |
|
468 |
int status, save; |
|
469 |
pid_t pid; |
|
470 |
struct sigaction sa, intr, quit; |
|
471 |
sigset_t block, omask; |
|
472 |
||
473 |
if (line == NULL) |
|
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
474 |
return -1; |
433 | 475 |
|
476 |
sa.sa_handler = SIG_IGN; |
|
477 |
sa.sa_flags = 0; |
|
478 |
__sigemptyset (&sa.sa_mask); |
|
479 |
||
480 |
if (__sigaction (SIGINT, &sa, &intr) < 0) { |
|
481 |
DPRINTF(("1: errno=%d\n", errno)); |
|
482 |
return -1; |
|
483 |
} |
|
484 |
if (__sigaction (SIGQUIT, &sa, &quit) < 0) { |
|
485 |
save = errno; |
|
486 |
(void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL); |
|
487 |
errno = save; |
|
488 |
DPRINTF(("2: errno=%d\n", errno)); |
|
489 |
return -1; |
|
490 |
} |
|
491 |
||
492 |
__sigemptyset (&block); |
|
493 |
__sigaddset (&block, SIGCHLD); |
|
494 |
save = errno; |
|
495 |
if (__sigprocmask(SIG_BLOCK, &block, &omask) < 0) { |
|
496 |
if (errno == ENOSYS) |
|
497 |
errno = save; |
|
498 |
else { |
|
499 |
save = errno; |
|
500 |
(void) __sigaction(SIGINT, &intr, (struct sigaction *) NULL); |
|
501 |
(void) __sigaction(SIGQUIT, &quit, (struct sigaction *) NULL); |
|
502 |
errno = save; |
|
503 |
DPRINTF(("3: errno=%d\n", errno)); |
|
504 |
return -1; |
|
505 |
} |
|
506 |
} |
|
507 |
||
508 |
pid = FORK (); |
|
509 |
if (pid == (pid_t) 0) { |
|
510 |
/* Child side. */ |
|
511 |
CONST char *new_argv[4]; |
|
512 |
new_argv[0] = SHELL_NAME; |
|
513 |
new_argv[1] = "-c"; |
|
514 |
new_argv[2] = line; |
|
515 |
new_argv[3] = NULL; |
|
516 |
||
517 |
/* Restore the signals. */ |
|
518 |
(void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL); |
|
519 |
(void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL); |
|
520 |
(void) __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL); |
|
521 |
||
522 |
/* Exec the shell. */ |
|
523 |
(void) __execve (SHELL_PATH, (char *CONST *) new_argv, __environ); |
|
524 |
_exit (127); |
|
525 |
} else { |
|
526 |
if (pid < (pid_t) 0) { |
|
527 |
/* The fork failed. */ |
|
528 |
DPRINTF(("4: errno=%d\n", errno)); |
|
529 |
status = -1; |
|
530 |
} else { |
|
531 |
/* Parent side. */ |
|
532 |
#ifdef NO_WAITPID |
|
533 |
pid_t child; |
|
534 |
||
535 |
do { |
|
805 | 536 |
__BEGIN_INTERRUPTABLE__ |
433 | 537 |
child = __wait (&status); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
538 |
__END_INTERRUPTABLE__ |
805 | 539 |
if (child < 0 && errno != EINTR) { |
433 | 540 |
DPRINTF(("5: errno=%d\n", errno)); |
541 |
status = -1; |
|
542 |
break; |
|
543 |
} |
|
544 |
} while (child != pid); |
|
545 |
#else |
|
546 |
pid_t child; |
|
547 |
||
548 |
/* claus: the original did not care for EINTR here ... */ |
|
549 |
do { |
|
805 | 550 |
__BEGIN_INTERRUPTABLE__ |
433 | 551 |
child = __waitpid (pid, &status, 0); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
552 |
__END_INTERRUPTABLE__ |
433 | 553 |
} while ((child != pid) && (errno == EINTR)); |
554 |
if (child != pid) { |
|
555 |
DPRINTF(("6: errno=%d\n", errno)); |
|
556 |
status = -1; |
|
557 |
} |
|
558 |
#endif /* NO_WAITPID */ |
|
559 |
} |
|
560 |
} |
|
561 |
save = errno; |
|
562 |
if ((__sigaction (SIGINT, &intr, (struct sigaction *) NULL) |
|
563 |
| __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL) |
|
564 |
| __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL)) != 0) { |
|
565 |
if (errno == ENOSYS) { |
|
566 |
errno = save; |
|
567 |
} else { |
|
568 |
status = -1; |
|
569 |
DPRINTF(("7: errno=%d\n", errno)); |
|
570 |
} |
|
571 |
} |
|
572 |
||
573 |
return status; |
|
574 |
} |
|
575 |
#endif /* WANT_SYSTEM */ |
|
576 |
||
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
577 |
|
433 | 578 |
/* |
579 |
* some systems do not have realpath(); |
|
580 |
* the alternative of reading from a 'pwp'-pipe |
|
581 |
* is way too slow. Here is a realpath for the rest of us. |
|
440 | 582 |
* define WANT_REALPATH in the xxxIntern-file to get it. |
433 | 583 |
*/ |
443 | 584 |
|
440 | 585 |
#if defined(HAS_REALPATH) |
586 |
# undef WANT_REALPATH |
|
587 |
#endif |
|
588 |
#if !defined(HAS_GETWD) && !defined(HAS_GETCWD) |
|
589 |
# undef WANT_REALPATH |
|
590 |
#endif |
|
591 |
||
592 |
#if defined(WANT_REALPATH) |
|
406 | 593 |
|
594 |
# ifndef NULL |
|
595 |
# define NULL (char *)0 |
|
596 |
# endif |
|
597 |
||
439 | 598 |
# define MAX_READLINKS 32 |
599 |
||
600 |
# ifndef MAXPATHLEN |
|
601 |
# define MAXPATHLEN 1024 |
|
602 |
# endif |
|
406 | 603 |
|
604 |
static |
|
605 |
char *realpath(path, resolved_path) |
|
606 |
char *path; |
|
607 |
char resolved_path []; |
|
608 |
{ |
|
609 |
char copy_path[MAXPATHLEN]; |
|
610 |
char link_path[MAXPATHLEN]; |
|
611 |
char *new_path = resolved_path; |
|
612 |
char *max_path; |
|
613 |
int readlinks = 0; |
|
614 |
int n; |
|
615 |
||
616 |
/* Make a copy of the source path since we may need to modify it. */ |
|
617 |
strcpy(copy_path, path); |
|
618 |
path = copy_path; |
|
619 |
max_path = copy_path + MAXPATHLEN - 2; |
|
620 |
/* If it's a relative pathname use getwd for starters. */ |
|
621 |
if (*path != '/') { |
|
622 |
#ifdef HAS_GETCWD |
|
623 |
getcwd(new_path, MAXPATHLEN - 1); |
|
624 |
#else |
|
625 |
getwd(new_path); |
|
626 |
#endif |
|
627 |
new_path += strlen(new_path); |
|
628 |
if (new_path[-1] != '/') |
|
629 |
*new_path++ = '/'; |
|
630 |
} |
|
631 |
else { |
|
632 |
*new_path++ = '/'; |
|
633 |
path++; |
|
634 |
} |
|
635 |
/* Expand each slash-separated pathname component. */ |
|
636 |
while (*path != '\0') { |
|
637 |
/* Ignore stray "/". */ |
|
638 |
if (*path == '/') { |
|
639 |
path++; |
|
640 |
continue; |
|
641 |
} |
|
642 |
if (*path == '.') { |
|
643 |
/* Ignore ".". */ |
|
644 |
if (path[1] == '\0' || path[1] == '/') { |
|
645 |
path++; |
|
646 |
continue; |
|
647 |
} |
|
648 |
if (path[1] == '.') { |
|
649 |
if (path[2] == '\0' || path[2] == '/') { |
|
650 |
path += 2; |
|
651 |
/* Ignore ".." at root. */ |
|
652 |
if (new_path == resolved_path + 1) |
|
653 |
continue; |
|
654 |
/* Handle ".." by backing up. */ |
|
655 |
while ((--new_path)[-1] != '/') |
|
656 |
; |
|
657 |
continue; |
|
658 |
} |
|
659 |
} |
|
660 |
} |
|
661 |
/* Safely copy the next pathname component. */ |
|
662 |
while (*path != '\0' && *path != '/') { |
|
663 |
if (path > max_path) { |
|
664 |
errno = ENAMETOOLONG; |
|
665 |
return NULL; |
|
666 |
} |
|
667 |
*new_path++ = *path++; |
|
668 |
} |
|
669 |
#ifdef S_IFLNK |
|
670 |
/* Protect against infinite loops. */ |
|
671 |
if (readlinks++ > MAX_READLINKS) { |
|
672 |
errno = ELOOP; |
|
673 |
return NULL; |
|
674 |
} |
|
675 |
/* See if latest pathname component is a symlink. */ |
|
676 |
*new_path = '\0'; |
|
677 |
n = readlink(resolved_path, link_path, MAXPATHLEN - 1); |
|
678 |
if (n < 0) { |
|
679 |
/* EINVAL means the file exists but isn't a symlink. */ |
|
680 |
if (errno != EINVAL) |
|
681 |
return NULL; |
|
682 |
} |
|
683 |
else { |
|
684 |
/* Note: readlink doesn't add the null byte. */ |
|
685 |
link_path[n] = '\0'; |
|
686 |
if (*link_path == '/') |
|
687 |
/* Start over for an absolute symlink. */ |
|
688 |
new_path = resolved_path; |
|
689 |
else |
|
690 |
/* Otherwise back up over this component. */ |
|
691 |
while (*(--new_path) != '/') |
|
692 |
; |
|
693 |
/* Safe sex check. */ |
|
694 |
if (strlen(path) + n >= MAXPATHLEN) { |
|
695 |
errno = ENAMETOOLONG; |
|
696 |
return NULL; |
|
697 |
} |
|
698 |
/* Insert symlink contents into path. */ |
|
699 |
strcat(link_path, path); |
|
700 |
strcpy(copy_path, link_path); |
|
701 |
path = copy_path; |
|
702 |
} |
|
703 |
#endif /* S_IFLNK */ |
|
704 |
*new_path++ = '/'; |
|
705 |
} |
|
706 |
/* Delete trailing slash but don't whomp a lone slash. */ |
|
707 |
if (new_path != resolved_path + 1 && new_path[-1] == '/') |
|
708 |
new_path--; |
|
709 |
/* Make sure it's null terminated. */ |
|
710 |
*new_path = '\0'; |
|
711 |
return resolved_path; |
|
712 |
} |
|
713 |
# define HAS_REALPATH |
|
714 |
#endif /* WANT_REALPATH && not HAS_REALPATH */ |
|
715 |
%} |
|
716 |
! ! |
|
717 |
||
2 | 718 |
!OperatingSystem class methodsFor:'documentation'! |
719 |
||
88 | 720 |
copyright |
721 |
" |
|
722 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
185 | 723 |
All Rights Reserved |
88 | 724 |
|
725 |
This software is furnished under a license and may be used |
|
726 |
only in accordance with the terms of that license and with the |
|
727 |
inclusion of the above copyright notice. This software may not |
|
728 |
be provided or otherwise made available to, or used by, any |
|
729 |
other person. No title to or ownership of the software is |
|
730 |
hereby transferred. |
|
731 |
" |
|
732 |
! |
|
733 |
||
2 | 734 |
documentation |
735 |
" |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
736 |
this class realizes access to most (all ?) required operating system services; |
68 | 737 |
some of it is very specific for unix, so do not depend on |
738 |
things available here in your applications - some may not |
|
370 | 739 |
be found in other OS's or be slightly different ... |
68 | 740 |
|
741 |
(On the other hand: I do not want to hide all features |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
742 |
from you - in some situations it MAY be interesting to be |
792 | 743 |
able to get down to a select or fork system call easily (at least on Unix systems). |
68 | 744 |
You decide - portability vs. functionality) |
745 |
||
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
746 |
Currently, there is only this class available - once others than |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
747 |
Unix are supported, the corresponding class will be bound to the |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
748 |
global variable OperatingSystem. |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
749 |
|
68 | 750 |
Class variables: |
751 |
||
185 | 752 |
HostName <String> remembered hostname |
753 |
||
575
4ad726f27891
oops cached HostName was clobbered by a domainName query
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
754 |
DomainName <String> remembered domainname |
4ad726f27891
oops cached HostName was clobbered by a domainName query
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
755 |
|
185 | 756 |
LastErrorNumber <Integer> the last value of errno |
757 |
||
758 |
LastExecStatus <Integer> the returned exec status after |
|
759 |
the last call of system |
|
760 |
||
761 |
OSSignals <Array> Array of signals to be raised for corresponding |
|
762 |
OperatingSystem signals. |
|
308 | 763 |
|
764 |
ForkFailed <Boolean> set if a fork (or popen) has failed; |
|
765 |
ST/X will avoid doing more forks/popens |
|
766 |
if this flag is set, for a slightly |
|
767 |
smoother operation. |
|
768 |
||
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
769 |
SlowFork <Boolean> if set, fork and popen are avoided; |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
770 |
(more or less obsolete now) |
540
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
771 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
772 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
773 |
ErrorSignal <Signal> Parentsignal of all OS error signals. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
774 |
not directly raised. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
775 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
776 |
AccessDeniedErrorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
777 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
778 |
FileNotFoundErrorSignal |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
779 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
780 |
LocaleInfo <Dictionary> if non nil, that is taken instead of the operating |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
781 |
systems locale definitions (allows for overwriting |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
782 |
these, or provide a compatible info on systems which do |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
783 |
not support locales) |
2 | 784 |
" |
785 |
! ! |
|
786 |
||
95 | 787 |
!OperatingSystem class methodsFor:'initialization'! |
788 |
||
789 |
initialize |
|
185 | 790 |
"initialize the class" |
791 |
||
540
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
792 |
ObjectMemory addDependent:self. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
793 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
794 |
ErrorSignal isNil ifTrue:[ |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
795 |
ErrorSignal := Object errorSignal newSignalMayProceed:true.. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
796 |
ErrorSignal nameClass:self message:#errorSignal. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
797 |
ErrorSignal notifierString:'OS error encountered'. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
798 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
799 |
AccessDeniedErrorSignal := ErrorSignal newSignalMayProceed:true. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
800 |
AccessDeniedErrorSignal nameClass:self message:#accessDeniedError. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
801 |
AccessDeniedErrorSignal notifierString:'OS access denied'. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
802 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
803 |
FileNotFoundErrorSignal := ErrorSignal newSignalMayProceed:true. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
804 |
FileNotFoundErrorSignal nameClass:self message:#fileNotFoundErrorSignal. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
805 |
FileNotFoundErrorSignal notifierString:'OS file not found'. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
806 |
] |
95 | 807 |
! |
808 |
||
809 |
update:something |
|
810 |
something == #earlyRestart ifTrue:[ |
|
185 | 811 |
" |
812 |
flush cached data |
|
813 |
" |
|
814 |
HostName := nil. |
|
575
4ad726f27891
oops cached HostName was clobbered by a domainName query
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
815 |
DomainName := nil. |
185 | 816 |
LastErrorNumber := nil. |
817 |
LastExecStatus := nil |
|
95 | 818 |
] |
819 |
! ! |
|
820 |
||
616 | 821 |
!OperatingSystem class methodsFor:'OS signal constants'! |
822 |
||
823 |
sigABRT |
|
824 |
"return the signal number for SIGABRT - 0 if not supported by OS |
|
825 |
(the numeric value is not the same across unix-systems)" |
|
826 |
||
827 |
%{ /* NOCONTEXT */ |
|
828 |
#ifdef SIGABRT |
|
710 | 829 |
RETURN ( _MKSMALLINT(SIGABRT) ); |
616 | 830 |
#else |
710 | 831 |
RETURN ( _MKSMALLINT(0) ); |
616 | 832 |
#endif |
833 |
%} |
|
834 |
! |
|
835 |
||
836 |
sigALRM |
|
837 |
"return the signal number for SIGALRM - 0 if not supported |
|
838 |
(the numeric value is not the same across unix-systems)" |
|
839 |
||
840 |
%{ /* NOCONTEXT */ |
|
841 |
#ifdef SIGALRM |
|
710 | 842 |
RETURN ( _MKSMALLINT(SIGALRM) ); |
616 | 843 |
#else |
710 | 844 |
RETURN ( _MKSMALLINT(0) ); |
616 | 845 |
#endif |
846 |
%} |
|
847 |
! |
|
848 |
||
831 | 849 |
sigBREAK |
850 |
"return the signal number for SIGBREAK - 0 if not supported. |
|
851 |
This is an MSDOS specific signal" |
|
852 |
||
853 |
%{ /* NOCONTEXT */ |
|
854 |
#ifdef SIGBREAK |
|
855 |
RETURN ( _MKSMALLINT(SIGBREAK) ); |
|
856 |
#else |
|
857 |
RETURN ( _MKSMALLINT(0) ); |
|
858 |
#endif |
|
859 |
%} |
|
860 |
! |
|
861 |
||
616 | 862 |
sigBUS |
863 |
"return the signal number for SIGBUS - 0 if not supported |
|
864 |
(the numeric value is not the same across unix-systems)" |
|
865 |
||
866 |
%{ /* NOCONTEXT */ |
|
867 |
#ifdef SIGBUS |
|
710 | 868 |
RETURN ( _MKSMALLINT(SIGBUS) ); |
616 | 869 |
#else |
710 | 870 |
RETURN ( _MKSMALLINT(0) ); |
616 | 871 |
#endif |
872 |
%} |
|
873 |
! |
|
874 |
||
875 |
sigCHLD |
|
876 |
"return the signal number for SIGCHLD - 0 if not supported |
|
877 |
(the numeric value is not the same across unix-systems)" |
|
878 |
||
879 |
%{ /* NOCONTEXT */ |
|
880 |
#if defined(SIGCHLD) |
|
710 | 881 |
RETURN ( _MKSMALLINT(SIGCHLD) ); |
616 | 882 |
#else |
883 |
# if defined(SIGCLD) |
|
710 | 884 |
RETURN ( _MKSMALLINT(SIGCLD) ); |
616 | 885 |
# else |
710 | 886 |
RETURN ( _MKSMALLINT(0) ); |
616 | 887 |
# endif |
888 |
#endif |
|
889 |
%} |
|
890 |
! |
|
891 |
||
892 |
sigCONT |
|
893 |
"return the signal number for SIGCONT - 0 if not supported |
|
894 |
(the numeric value is not the same across unix-systems)" |
|
895 |
||
896 |
%{ /* NOCONTEXT */ |
|
897 |
#if defined(SIGCONT) |
|
710 | 898 |
RETURN ( _MKSMALLINT(SIGCONT) ); |
616 | 899 |
#else |
710 | 900 |
RETURN ( _MKSMALLINT(0) ); |
616 | 901 |
#endif |
902 |
%} |
|
903 |
! |
|
904 |
||
905 |
sigDANGER |
|
906 |
"return the signal number for SIGDANGER - 0 if not supported |
|
907 |
(seems to be an AIX special)" |
|
908 |
||
909 |
%{ /* NOCONTEXT */ |
|
710 | 910 |
#if defined(SIGDANGER) |
911 |
RETURN ( _MKSMALLINT(SIGDANGER) ); |
|
616 | 912 |
#else |
710 | 913 |
RETURN ( _MKSMALLINT(0) ); |
616 | 914 |
#endif |
915 |
%} |
|
916 |
! |
|
917 |
||
918 |
sigEMT |
|
919 |
"return the signal number for SIGEMT - 0 if not supported by OS |
|
920 |
(the numeric value is not the same across unix-systems)" |
|
921 |
||
922 |
%{ /* NOCONTEXT */ |
|
923 |
#ifdef SIGEMT |
|
710 | 924 |
RETURN ( _MKSMALLINT(SIGEMT) ); |
616 | 925 |
#else |
710 | 926 |
RETURN ( _MKSMALLINT(0) ); |
616 | 927 |
#endif |
928 |
%} |
|
929 |
! |
|
930 |
||
931 |
sigFP |
|
932 |
"return the signal number for SIGFP - 0 if not supported by OS |
|
933 |
(the numeric value is not the same across unix-systems)" |
|
934 |
||
935 |
%{ /* NOCONTEXT */ |
|
936 |
#ifdef SIGFPE |
|
710 | 937 |
RETURN ( _MKSMALLINT(SIGFPE) ); |
616 | 938 |
#else |
710 | 939 |
RETURN ( _MKSMALLINT(0) ); |
616 | 940 |
#endif |
941 |
%} |
|
942 |
! |
|
943 |
||
944 |
sigGRANT |
|
945 |
"return the signal number for SIGGRANT - 0 if not supported |
|
946 |
(seems to be an AIX special)" |
|
947 |
||
948 |
%{ /* NOCONTEXT */ |
|
949 |
#if defined(SIGGRANT) |
|
710 | 950 |
RETURN ( _MKSMALLINT(SIGGRANT) ); |
616 | 951 |
#else |
710 | 952 |
RETURN ( _MKSMALLINT(0) ); |
616 | 953 |
#endif |
954 |
%} |
|
955 |
! |
|
956 |
||
957 |
sigHUP |
|
958 |
"return the signal number for SIGHUP |
|
959 |
(the numeric value is not the same across unix-systems)" |
|
960 |
||
961 |
%{ /* NOCONTEXT */ |
|
962 |
#ifdef SIGHUP |
|
710 | 963 |
RETURN ( _MKSMALLINT(SIGHUP) ); |
616 | 964 |
#else |
710 | 965 |
RETURN ( _MKSMALLINT(0) ); |
616 | 966 |
#endif |
967 |
%} |
|
968 |
! |
|
969 |
||
970 |
sigILL |
|
971 |
"return the signal number for SIGILL - 0 if not supported by OS |
|
972 |
(the numeric value is not the same across unix-systems)" |
|
973 |
||
974 |
%{ /* NOCONTEXT */ |
|
975 |
#ifdef SIGILL |
|
710 | 976 |
RETURN ( _MKSMALLINT(SIGILL) ); |
616 | 977 |
#else |
710 | 978 |
RETURN ( _MKSMALLINT(0) ); |
616 | 979 |
#endif |
980 |
%} |
|
981 |
! |
|
982 |
||
983 |
sigINT |
|
984 |
"return the signal number for SIGINT |
|
985 |
(the numeric value is not the same across unix-systems)" |
|
986 |
||
987 |
%{ /* NOCONTEXT */ |
|
988 |
#ifdef SIGINT |
|
710 | 989 |
RETURN ( _MKSMALLINT(SIGINT) ); |
616 | 990 |
#else |
710 | 991 |
RETURN ( _MKSMALLINT(0) ); |
616 | 992 |
#endif |
993 |
%} |
|
994 |
! |
|
995 |
||
996 |
sigIO |
|
997 |
"return the signal number for SIGIO - 0 if not supported |
|
998 |
(the numeric value is not the same across unix-systems)" |
|
999 |
||
1000 |
%{ /* NOCONTEXT */ |
|
1001 |
#if defined(SIGIO) |
|
710 | 1002 |
RETURN ( _MKSMALLINT(SIGIO) ); |
616 | 1003 |
#else |
710 | 1004 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1005 |
#endif |
1006 |
%} |
|
1007 |
! |
|
1008 |
||
1009 |
sigIOT |
|
1010 |
"return the signal number for SIGIOT - 0 if not supported by OS |
|
1011 |
(the numeric value is not the same across unix-systems)" |
|
1012 |
||
1013 |
%{ /* NOCONTEXT */ |
|
1014 |
#ifdef SIGIOT |
|
710 | 1015 |
RETURN ( _MKSMALLINT(SIGIOT) ); |
616 | 1016 |
#else |
710 | 1017 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1018 |
#endif |
1019 |
%} |
|
1020 |
! |
|
1021 |
||
1022 |
sigKILL |
|
1023 |
"return the signal number for SIGKILL |
|
1024 |
(the numeric value is not the same across unix-systems)" |
|
1025 |
||
1026 |
%{ /* NOCONTEXT */ |
|
1027 |
#ifdef SIGKILL |
|
710 | 1028 |
RETURN ( _MKSMALLINT(SIGKILL) ); |
616 | 1029 |
#else |
710 | 1030 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1031 |
#endif |
1032 |
%} |
|
1033 |
! |
|
1034 |
||
1035 |
sigLOST |
|
1036 |
"return the signal number for SIGLOST - 0 if not supported |
|
1037 |
(the numeric value is not the same across unix-systems)" |
|
1038 |
||
1039 |
%{ /* NOCONTEXT */ |
|
1040 |
#if defined(SIGLOST) |
|
710 | 1041 |
RETURN ( _MKSMALLINT(SIGLOST) ); |
616 | 1042 |
#else |
710 | 1043 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1044 |
#endif |
1045 |
%} |
|
1046 |
! |
|
1047 |
||
1048 |
sigMIGRATE |
|
1049 |
"return the signal number for SIGMIGRATE - 0 if not supported |
|
1050 |
(seems to be an AIX special)" |
|
1051 |
||
1052 |
%{ /* NOCONTEXT */ |
|
1053 |
#if defined(SIGMIGRATE) |
|
710 | 1054 |
RETURN ( _MKSMALLINT(SIGMIGRATE) ); |
616 | 1055 |
#else |
710 | 1056 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1057 |
#endif |
1058 |
%} |
|
1059 |
! |
|
1060 |
||
1061 |
sigMSG |
|
1062 |
"return the signal number for SIGMSG - 0 if not supported |
|
1063 |
(seems to be an AIX special)" |
|
1064 |
||
1065 |
%{ /* NOCONTEXT */ |
|
1066 |
#if defined(SIGMSG) |
|
710 | 1067 |
RETURN ( _MKSMALLINT(SIGMSG) ); |
616 | 1068 |
#else |
710 | 1069 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1070 |
#endif |
1071 |
%} |
|
1072 |
! |
|
1073 |
||
1074 |
sigPIPE |
|
1075 |
"return the signal number for SIGPIPE - 0 if not supported |
|
1076 |
(the numeric value is not the same across unix-systems)" |
|
1077 |
||
1078 |
%{ /* NOCONTEXT */ |
|
1079 |
#ifdef SIGPIPE |
|
710 | 1080 |
RETURN ( _MKSMALLINT(SIGPIPE) ); |
616 | 1081 |
#else |
710 | 1082 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1083 |
#endif |
1084 |
%} |
|
1085 |
! |
|
1086 |
||
1087 |
sigPOLL |
|
1088 |
"return the signal number for SIGPOLL - 0 if not supported |
|
1089 |
(the numeric value is not the same across unix-systems)" |
|
1090 |
||
1091 |
%{ /* NOCONTEXT */ |
|
1092 |
#if defined(SIGPOLL) |
|
710 | 1093 |
RETURN ( _MKSMALLINT(SIGPOLL) ); |
616 | 1094 |
#else |
710 | 1095 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1096 |
#endif |
1097 |
%} |
|
1098 |
! |
|
1099 |
||
1100 |
sigPRE |
|
1101 |
"return the signal number for SIGPRE - 0 if not supported |
|
1102 |
(seems to be an AIX special)" |
|
1103 |
||
1104 |
%{ /* NOCONTEXT */ |
|
1105 |
#if defined(SIGPRE) |
|
710 | 1106 |
RETURN ( _MKSMALLINT(SIGPRE) ); |
616 | 1107 |
#else |
710 | 1108 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1109 |
#endif |
1110 |
%} |
|
1111 |
! |
|
1112 |
||
1113 |
sigPROF |
|
1114 |
"return the signal number for SIGPROF - 0 if not supported |
|
1115 |
(the numeric value is not the same across unix-systems)" |
|
1116 |
||
1117 |
%{ /* NOCONTEXT */ |
|
1118 |
#if defined(SIGPROF) |
|
710 | 1119 |
RETURN ( _MKSMALLINT(SIGPROF) ); |
616 | 1120 |
#else |
710 | 1121 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1122 |
#endif |
1123 |
%} |
|
1124 |
! |
|
1125 |
||
1126 |
sigPWR |
|
1127 |
"return the signal number for SIGPWR - 0 if not supported |
|
1128 |
(not available on all systems)" |
|
1129 |
||
1130 |
%{ /* NOCONTEXT */ |
|
1131 |
#if defined(SIGPWR) |
|
710 | 1132 |
RETURN ( _MKSMALLINT(SIGPWR) ); |
616 | 1133 |
#else |
710 | 1134 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1135 |
#endif |
1136 |
%} |
|
1137 |
! |
|
1138 |
||
1139 |
sigQUIT |
|
1140 |
"return the signal number for SIGQUIT |
|
1141 |
(the numeric value is not the same across unix-systems)" |
|
1142 |
||
1143 |
%{ /* NOCONTEXT */ |
|
1144 |
#ifdef SIGQUIT |
|
710 | 1145 |
RETURN ( _MKSMALLINT(SIGQUIT) ); |
616 | 1146 |
#else |
710 | 1147 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1148 |
#endif |
1149 |
%} |
|
1150 |
! |
|
1151 |
||
1152 |
sigRETRACT |
|
1153 |
"return the signal number for SIGRETRACT - 0 if not supported |
|
1154 |
(seems to be an AIX special)" |
|
1155 |
||
1156 |
%{ /* NOCONTEXT */ |
|
1157 |
#if defined(SIGRETRACT) |
|
710 | 1158 |
RETURN ( _MKSMALLINT(SIGRETRACT) ); |
616 | 1159 |
#else |
710 | 1160 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1161 |
#endif |
1162 |
%} |
|
1163 |
! |
|
1164 |
||
1165 |
sigSAK |
|
1166 |
"return the signal number for SIGSAK - 0 if not supported |
|
1167 |
(seems to be an AIX special)" |
|
1168 |
||
1169 |
%{ /* NOCONTEXT */ |
|
1170 |
#if defined(SIGSAK) |
|
710 | 1171 |
RETURN ( _MKSMALLINT(SIGSAK) ); |
616 | 1172 |
#else |
710 | 1173 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1174 |
#endif |
1175 |
%} |
|
1176 |
! |
|
1177 |
||
1178 |
sigSEGV |
|
1179 |
"return the signal number for SIGSEGV - 0 if not supported |
|
1180 |
(the numeric value is not the same across unix-systems)" |
|
1181 |
||
1182 |
%{ /* NOCONTEXT */ |
|
1183 |
#ifdef SIGSEGV |
|
710 | 1184 |
RETURN ( _MKSMALLINT(SIGSEGV) ); |
616 | 1185 |
#else |
710 | 1186 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1187 |
#endif |
1188 |
%} |
|
1189 |
! |
|
1190 |
||
1191 |
sigSOUND |
|
1192 |
"return the signal number for SIGSOUND - 0 if not supported |
|
1193 |
(seems to be an AIX special)" |
|
1194 |
||
1195 |
%{ /* NOCONTEXT */ |
|
1196 |
#if defined(SIGSOUND) |
|
710 | 1197 |
RETURN ( _MKSMALLINT(SIGSOUND) ); |
616 | 1198 |
#else |
710 | 1199 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1200 |
#endif |
1201 |
%} |
|
1202 |
! |
|
1203 |
||
1204 |
sigSTOP |
|
1205 |
"return the signal number for SIGSTOP - 0 if not supported |
|
1206 |
(the numeric value is not the same across unix-systems)" |
|
1207 |
||
1208 |
%{ /* NOCONTEXT */ |
|
1209 |
#if defined(SIGSTOP) |
|
710 | 1210 |
RETURN ( _MKSMALLINT(SIGSTOP) ); |
616 | 1211 |
#else |
710 | 1212 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1213 |
#endif |
1214 |
%} |
|
1215 |
! |
|
1216 |
||
1217 |
sigSYS |
|
1218 |
"return the signal number for SIGSYS - 0 if not supported |
|
1219 |
(the numeric value is not the same across unix-systems)" |
|
1220 |
||
1221 |
%{ /* NOCONTEXT */ |
|
1222 |
#ifdef SIGSYS |
|
710 | 1223 |
RETURN ( _MKSMALLINT(SIGSYS) ); |
616 | 1224 |
#else |
710 | 1225 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1226 |
#endif |
1227 |
%} |
|
1228 |
! |
|
1229 |
||
1230 |
sigTERM |
|
1231 |
"return the signal number for SIGTERM - 0 if not supported |
|
1232 |
(the numeric value is not the same across unix-systems)" |
|
1233 |
||
1234 |
%{ /* NOCONTEXT */ |
|
1235 |
#ifdef SIGTERM |
|
710 | 1236 |
RETURN ( _MKSMALLINT(SIGTERM) ); |
616 | 1237 |
#else |
710 | 1238 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1239 |
#endif |
1240 |
%} |
|
1241 |
! |
|
1242 |
||
1243 |
sigTRAP |
|
1244 |
"return the signal number for SIGTRAP - 0 if not supported by OS |
|
1245 |
(the numeric value is not the same across unix-systems)" |
|
1246 |
||
1247 |
%{ /* NOCONTEXT */ |
|
1248 |
#ifdef SIGTRAP |
|
710 | 1249 |
RETURN ( _MKSMALLINT(SIGTRAP) ); |
616 | 1250 |
#else |
710 | 1251 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1252 |
#endif |
1253 |
%} |
|
1254 |
! |
|
1255 |
||
1256 |
sigTSTP |
|
1257 |
"return the signal number for SIGTSTP - 0 if not supported |
|
1258 |
(the numeric value is not the same across unix-systems)" |
|
1259 |
||
1260 |
%{ /* NOCONTEXT */ |
|
1261 |
#if defined(SIGTSTP) |
|
710 | 1262 |
RETURN ( _MKSMALLINT(SIGTSTP) ); |
616 | 1263 |
#else |
710 | 1264 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1265 |
#endif |
1266 |
%} |
|
1267 |
! |
|
1268 |
||
1269 |
sigTTIN |
|
1270 |
"return the signal number for SIGTTIN - 0 if not supported |
|
1271 |
(the numeric value is not the same across unix-systems)" |
|
1272 |
||
1273 |
%{ /* NOCONTEXT */ |
|
1274 |
#if defined(SIGTTIN) |
|
710 | 1275 |
RETURN ( _MKSMALLINT(SIGTTIN) ); |
616 | 1276 |
#else |
710 | 1277 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1278 |
#endif |
1279 |
%} |
|
1280 |
! |
|
1281 |
||
1282 |
sigTTOU |
|
1283 |
"return the signal number for SIGTTOU - 0 if not supported |
|
1284 |
(the numeric value is not the same across unix-systems)" |
|
1285 |
||
1286 |
%{ /* NOCONTEXT */ |
|
1287 |
#if defined(SIGTTOU) |
|
710 | 1288 |
RETURN ( _MKSMALLINT(SIGTTOU) ); |
616 | 1289 |
#else |
710 | 1290 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1291 |
#endif |
1292 |
%} |
|
1293 |
! |
|
1294 |
||
1295 |
sigURG |
|
1296 |
"return the signal number for SIGURG - 0 if not supported |
|
1297 |
(the numeric value is not the same across unix-systems)" |
|
1298 |
||
1299 |
%{ /* NOCONTEXT */ |
|
1300 |
#if defined(SIGURG) |
|
710 | 1301 |
RETURN ( _MKSMALLINT(SIGURG) ); |
616 | 1302 |
#else |
710 | 1303 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1304 |
#endif |
1305 |
%} |
|
1306 |
! |
|
1307 |
||
1308 |
sigUSR1 |
|
1309 |
"return the signal number for SIGUSR1 - 0 if not supported |
|
1310 |
(the numeric value is not the same across unix-systems)" |
|
1311 |
||
1312 |
%{ /* NOCONTEXT */ |
|
1313 |
#if defined(SIGUSR1) |
|
710 | 1314 |
RETURN ( _MKSMALLINT(SIGUSR1) ); |
616 | 1315 |
#else |
710 | 1316 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1317 |
#endif |
1318 |
%} |
|
1319 |
! |
|
1320 |
||
1321 |
sigUSR2 |
|
1322 |
"return the signal number for SIGUSR2 - 0 if not supported |
|
1323 |
(the numeric value is not the same across unix-systems)" |
|
1324 |
||
1325 |
%{ /* NOCONTEXT */ |
|
1326 |
#if defined(SIGUSR2) |
|
710 | 1327 |
RETURN ( _MKSMALLINT(SIGUSR2) ); |
616 | 1328 |
#else |
710 | 1329 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1330 |
#endif |
1331 |
%} |
|
1332 |
! |
|
1333 |
||
1334 |
sigVTALRM |
|
1335 |
"return the signal number for SIGVTALRM - 0 if not supported |
|
1336 |
(the numeric value is not the same across unix-systems)" |
|
1337 |
||
1338 |
%{ /* NOCONTEXT */ |
|
1339 |
#if defined(SIGVTALRM) |
|
710 | 1340 |
RETURN ( _MKSMALLINT(SIGVTALRM) ); |
616 | 1341 |
#else |
710 | 1342 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1343 |
#endif |
1344 |
%} |
|
1345 |
! |
|
1346 |
||
1347 |
sigWINCH |
|
1348 |
"return the signal number for SIGWINCH - 0 if not supported |
|
1349 |
(the numeric value is not the same across unix-systems)" |
|
1350 |
||
1351 |
%{ /* NOCONTEXT */ |
|
1352 |
#if defined(SIGWINCH) |
|
710 | 1353 |
RETURN ( _MKSMALLINT(SIGWINCH) ); |
616 | 1354 |
#else |
710 | 1355 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1356 |
#endif |
1357 |
%} |
|
1358 |
! |
|
1359 |
||
1360 |
sigXCPU |
|
1361 |
"return the signal number for SIGXCPU - 0 if not supported |
|
1362 |
(the numeric value is not the same across unix-systems)" |
|
1363 |
||
1364 |
%{ /* NOCONTEXT */ |
|
1365 |
#if defined(SIGXCPU) |
|
710 | 1366 |
RETURN ( _MKSMALLINT(SIGXCPU) ); |
616 | 1367 |
#else |
710 | 1368 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1369 |
#endif |
1370 |
%} |
|
1371 |
! |
|
1372 |
||
1373 |
sigXFSZ |
|
1374 |
"return the signal number for SIGXFSZ - 0 if not supported |
|
1375 |
(the numeric value is not the same across unix-systems)" |
|
1376 |
||
1377 |
%{ /* NOCONTEXT */ |
|
1378 |
#if defined(SIGXFSZ) |
|
710 | 1379 |
RETURN ( _MKSMALLINT(SIGXFSZ) ); |
616 | 1380 |
#else |
710 | 1381 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1382 |
#endif |
1383 |
%} |
|
1384 |
! ! |
|
1385 |
||
540
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1386 |
!OperatingSystem class methodsFor:'Signal constants'! |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1387 |
|
616 | 1388 |
accessDeniedErrorSignal |
1389 |
"return the signal raised when a (file-) access is denied." |
|
1390 |
||
1391 |
^ AccessDeniedErrorSignal |
|
1392 |
! |
|
1393 |
||
540
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1394 |
errorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1395 |
"return the OS signals parent signal." |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1396 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1397 |
^ ErrorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1398 |
! |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1399 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1400 |
fileNotFoundErrorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1401 |
"return the signal raised when a file was not found." |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1402 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1403 |
^ FileNotFoundErrorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1404 |
! ! |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1405 |
|
1 | 1406 |
!OperatingSystem class methodsFor:'error messages'! |
1407 |
||
85 | 1408 |
currentErrorNumber |
68 | 1409 |
"returns the OS's last error nr (i.e. the value of errno). |
1410 |
Notice, that the value of this flag is only valid immediately |
|
1411 |
after the error occurred - it gets updated with every other |
|
85 | 1412 |
request to the OS. |
1413 |
Use lastErrorNumber - currentErrorNumber is invalidated by |
|
1414 |
many, many internal calls." |
|
68 | 1415 |
|
1416 |
%{ /* NOCONTEXT */ |
|
1417 |
||
1418 |
RETURN ( _MKSMALLINT(errno) ); |
|
1419 |
%} |
|
1420 |
" |
|
85 | 1421 |
OperatingSystem currentErrorNumber |
1422 |
" |
|
1423 |
! |
|
1424 |
||
1 | 1425 |
errorTextForNumber:errNr |
1426 |
"return a message string from a unix errorNumber |
|
68 | 1427 |
(as returned by a system call). |
1428 |
Should be replaced by a resource lookup." |
|
1 | 1429 |
|
77 | 1430 |
%{ |
1431 |
/* claus: |
|
1432 |
* I made this some primitive code, since errnos are not |
|
1433 |
* standard across unixes |
|
1434 |
*/ |
|
1435 |
char *msg = "unknown error"; |
|
1436 |
char buffer[50]; |
|
1437 |
||
252 | 1438 |
if (__isSmallInteger(errNr)) { |
185 | 1439 |
switch (_intVal(errNr)) { |
1440 |
/* |
|
1441 |
* POSIX errnos - these should be defined |
|
1442 |
*/ |
|
443 | 1443 |
#ifdef EPERM |
185 | 1444 |
case EPERM: |
1445 |
msg = "Operation not permitted"; |
|
1446 |
break; |
|
443 | 1447 |
#endif |
1448 |
#ifdef ENOENT |
|
185 | 1449 |
case ENOENT: |
1450 |
msg = "No such file or directory"; |
|
1451 |
break; |
|
443 | 1452 |
#endif |
1453 |
#ifdef ESRCH |
|
185 | 1454 |
case ESRCH: |
1455 |
msg = "No such process"; |
|
1456 |
break; |
|
443 | 1457 |
#endif |
1458 |
#ifdef EINTR |
|
185 | 1459 |
case EINTR: |
1460 |
msg = "Interrupted system call"; |
|
1461 |
break; |
|
443 | 1462 |
#endif |
1463 |
#ifdef EIO |
|
185 | 1464 |
case EIO: |
1465 |
msg = "I/O error"; |
|
1466 |
break; |
|
443 | 1467 |
#endif |
1468 |
#ifdef ENXIO |
|
185 | 1469 |
case ENXIO: |
1470 |
msg = "No such device or address"; |
|
1471 |
break; |
|
443 | 1472 |
#endif |
1473 |
#ifdef E2BIG |
|
185 | 1474 |
case E2BIG: |
1475 |
msg = "Arg list too long"; |
|
1476 |
break; |
|
443 | 1477 |
#endif |
1478 |
#ifdef ENOEXEC |
|
185 | 1479 |
case ENOEXEC: |
1480 |
msg = "Exec format error"; |
|
1481 |
break; |
|
443 | 1482 |
#endif |
1483 |
#ifdef EBADF |
|
185 | 1484 |
case EBADF: |
1485 |
msg = "Bad file number"; |
|
1486 |
break; |
|
443 | 1487 |
#endif |
1488 |
#ifdef ECHILD |
|
185 | 1489 |
case ECHILD: |
1490 |
msg = "No child processes"; |
|
1491 |
break; |
|
443 | 1492 |
#endif |
77 | 1493 |
#if !defined(EWOULDBLOCK) && defined(EAGAIN) && (EWOULDBLOCK != EAGAIN) |
185 | 1494 |
case EAGAIN: |
1495 |
msg = "Try again"; |
|
1496 |
break; |
|
77 | 1497 |
#endif |
443 | 1498 |
#ifdef ENOMEM |
185 | 1499 |
case ENOMEM: |
1500 |
msg = "Out of memory"; |
|
1501 |
break; |
|
443 | 1502 |
#endif |
1503 |
#ifdef EACCES |
|
185 | 1504 |
case EACCES: |
1505 |
msg = "Permission denied"; |
|
1506 |
break; |
|
443 | 1507 |
#endif |
1508 |
#ifdef EFAULT |
|
185 | 1509 |
case EFAULT: |
1510 |
msg = "Bad address"; |
|
1511 |
break; |
|
443 | 1512 |
#endif |
1513 |
#ifdef EBUSY |
|
185 | 1514 |
case EBUSY: |
1515 |
msg = "Device or resource busy"; |
|
1516 |
break; |
|
443 | 1517 |
#endif |
1518 |
#ifdef EEXIST |
|
185 | 1519 |
case EEXIST: |
1520 |
msg = "File exists"; |
|
1521 |
break; |
|
443 | 1522 |
#endif |
1523 |
#ifdef EXDEV |
|
185 | 1524 |
case EXDEV: |
1525 |
msg = "Cross-device link"; |
|
1526 |
break; |
|
443 | 1527 |
#endif |
1528 |
#ifdef ENODEV |
|
185 | 1529 |
case ENODEV: |
1530 |
msg = "No such device"; |
|
1531 |
break; |
|
443 | 1532 |
#endif |
1533 |
#ifdef ENOTDIR |
|
185 | 1534 |
case ENOTDIR: |
1535 |
msg = "Not a directory"; |
|
1536 |
break; |
|
443 | 1537 |
#endif |
1538 |
#ifdef EISDIR |
|
185 | 1539 |
case EISDIR: |
1540 |
msg = "Is a directory"; |
|
1541 |
break; |
|
443 | 1542 |
#endif |
1543 |
#ifdef EINVAL |
|
185 | 1544 |
case EINVAL: |
1545 |
msg = "Invalid argument"; |
|
1546 |
break; |
|
443 | 1547 |
#endif |
1548 |
#ifdef ENFILE |
|
185 | 1549 |
case ENFILE: |
1550 |
msg = "File table overflow"; |
|
1551 |
break; |
|
443 | 1552 |
#endif |
1553 |
#ifdef EMFILE |
|
185 | 1554 |
case EMFILE: |
1555 |
msg = "Too many open files"; |
|
1556 |
break; |
|
443 | 1557 |
#endif |
1558 |
#ifdef ENOTTY |
|
185 | 1559 |
case ENOTTY: |
1560 |
msg = "Not a typewriter"; |
|
1561 |
break; |
|
443 | 1562 |
#endif |
1563 |
#ifdef EFBIG |
|
185 | 1564 |
case EFBIG: |
1565 |
msg = "File too large"; |
|
1566 |
break; |
|
443 | 1567 |
#endif |
1568 |
#ifdef ENOSPC |
|
185 | 1569 |
case ENOSPC: |
1570 |
msg = "No space left on device"; |
|
1571 |
break; |
|
443 | 1572 |
#endif |
1573 |
#ifdef ESPIPE |
|
185 | 1574 |
case ESPIPE: |
1575 |
msg = "Illegal seek"; |
|
1576 |
break; |
|
443 | 1577 |
#endif |
1578 |
#ifdef EROFS |
|
185 | 1579 |
case EROFS: |
1580 |
msg = "Read-only file system"; |
|
1581 |
break; |
|
443 | 1582 |
#endif |
1583 |
#ifdef EMLINK |
|
185 | 1584 |
case EMLINK: |
1585 |
msg = "Too many links"; |
|
1586 |
break; |
|
443 | 1587 |
#endif |
1588 |
#ifdef EPIPE |
|
185 | 1589 |
case EPIPE: |
1590 |
msg = "Broken pipe"; |
|
1591 |
break; |
|
443 | 1592 |
#endif |
1593 |
#ifdef EDOM |
|
185 | 1594 |
case EDOM: |
1595 |
msg = "Math argument out of domain"; |
|
1596 |
break; |
|
443 | 1597 |
#endif |
1598 |
#ifdef ERANGE |
|
185 | 1599 |
case ERANGE: |
1600 |
msg = "Math result not representable"; |
|
1601 |
break; |
|
443 | 1602 |
#endif |
77 | 1603 |
#ifdef EDEADLK |
308 | 1604 |
# if EDEADLK != EWOULDBLOCK |
185 | 1605 |
case EDEADLK: |
1606 |
msg = "Resource deadlock would occur"; |
|
1607 |
break; |
|
308 | 1608 |
# endif |
77 | 1609 |
#endif |
1610 |
#ifdef ENAMETOOLONG |
|
185 | 1611 |
case ENAMETOOLONG: |
1612 |
msg = "File name too long"; |
|
1613 |
break; |
|
77 | 1614 |
#endif |
1615 |
#ifdef ENOLCK |
|
185 | 1616 |
case ENOLCK: |
1617 |
msg = "No record locks available"; |
|
1618 |
break; |
|
77 | 1619 |
#endif |
1620 |
#ifdef ENOSYS |
|
185 | 1621 |
case ENOSYS: |
1622 |
msg = "Function not implemented"; |
|
1623 |
break; |
|
77 | 1624 |
#endif |
359 | 1625 |
#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) |
185 | 1626 |
case ENOTEMPTY: |
1627 |
msg = "Directory not empty"; |
|
1628 |
break; |
|
77 | 1629 |
#endif |
1630 |
#ifdef EILSEQ |
|
185 | 1631 |
case EILSEQ: |
1632 |
msg = "Illegal byte sequence"; |
|
1633 |
break; |
|
77 | 1634 |
#endif |
185 | 1635 |
/* |
1636 |
* XPG3 errnos - defined on most systems |
|
1637 |
*/ |
|
77 | 1638 |
#ifdef ENOTBLK |
185 | 1639 |
case ENOTBLK: |
1640 |
msg = "Block device required"; |
|
1641 |
break; |
|
77 | 1642 |
#endif |
1643 |
#ifdef ETXTBSY |
|
185 | 1644 |
case ETXTBSY: |
1645 |
msg = "Text file busy"; |
|
1646 |
break; |
|
77 | 1647 |
#endif |
185 | 1648 |
/* |
1649 |
* some others |
|
1650 |
*/ |
|
77 | 1651 |
#ifdef EWOULDBLOCK |
185 | 1652 |
case EWOULDBLOCK: |
1653 |
msg = "Operation would block"; |
|
1654 |
break; |
|
77 | 1655 |
#endif |
1656 |
#ifdef ENOMSG |
|
185 | 1657 |
case ENOMSG: |
1658 |
msg = "No message of desired type"; |
|
1659 |
break; |
|
77 | 1660 |
#endif |
1661 |
#ifdef ELOOP |
|
185 | 1662 |
case ELOOP: |
1663 |
msg = "Too many levels of symbolic links"; |
|
1664 |
break; |
|
77 | 1665 |
#endif |
1666 |
||
185 | 1667 |
/* |
1668 |
* some stream errors |
|
1669 |
*/ |
|
77 | 1670 |
#ifdef ETIME |
185 | 1671 |
case ETIME: |
1672 |
msg = "Timer expired"; |
|
1673 |
break; |
|
77 | 1674 |
#endif |
1675 |
#ifdef ENOSR |
|
185 | 1676 |
case ENOSR: |
1677 |
msg = "Out of streams resources"; |
|
1678 |
break; |
|
77 | 1679 |
#endif |
1680 |
#ifdef ENOSTR |
|
185 | 1681 |
case ENOSTR: |
1682 |
msg = "Device not a stream"; |
|
1683 |
break; |
|
77 | 1684 |
#endif |
1685 |
#ifdef ECOMM |
|
185 | 1686 |
case ECOMM: |
1687 |
msg = "Communication error on send"; |
|
1688 |
break; |
|
77 | 1689 |
#endif |
1690 |
#ifdef EPROTO |
|
185 | 1691 |
case EPROTO: |
1692 |
msg = "Protocol error"; |
|
1693 |
break; |
|
77 | 1694 |
#endif |
185 | 1695 |
/* |
1696 |
* nfs errors |
|
1697 |
*/ |
|
77 | 1698 |
#ifdef ESTALE |
185 | 1699 |
case ESTALE: |
1700 |
msg = "Stale NFS file handle"; |
|
1701 |
break; |
|
77 | 1702 |
#endif |
1703 |
#ifdef EREMOTE |
|
185 | 1704 |
case EREMOTE: |
1705 |
msg = "Too many levels of remote in path"; |
|
1706 |
break; |
|
77 | 1707 |
#endif |
185 | 1708 |
/* |
1709 |
* some networking errors |
|
1710 |
*/ |
|
77 | 1711 |
#ifdef EINPROGRESS |
185 | 1712 |
case EINPROGRESS: |
1713 |
msg = "Operation now in progress"; |
|
1714 |
break; |
|
77 | 1715 |
#endif |
1716 |
#ifdef EALREADY |
|
185 | 1717 |
case EALREADY: |
1718 |
msg = "Operation already in progress"; |
|
1719 |
break; |
|
77 | 1720 |
#endif |
1721 |
#ifdef ENOTSOCK |
|
185 | 1722 |
case ENOTSOCK: |
1723 |
msg = "Socket operation on non-socket"; |
|
1724 |
break; |
|
77 | 1725 |
#endif |
1726 |
#ifdef EDESTADDRREQ |
|
185 | 1727 |
case EDESTADDRREQ: |
1728 |
msg = "Destination address required"; |
|
1729 |
break; |
|
77 | 1730 |
#endif |
1731 |
#ifdef EMSGSIZE |
|
185 | 1732 |
case EMSGSIZE: |
1733 |
msg = "Message too long"; |
|
1734 |
break; |
|
77 | 1735 |
#endif |
1736 |
#ifdef EPROTOTYPE |
|
185 | 1737 |
case EPROTOTYPE: |
1738 |
msg = "Protocol wrong type for socket"; |
|
1739 |
break; |
|
77 | 1740 |
#endif |
1741 |
#ifdef ENOPROTOOPT |
|
185 | 1742 |
case ENOPROTOOPT: |
1743 |
msg = "Protocol not available"; |
|
1744 |
break; |
|
77 | 1745 |
#endif |
1746 |
#ifdef EPROTONOSUPPORT |
|
185 | 1747 |
case EPROTONOSUPPORT: |
1748 |
msg = "Protocol not supported"; |
|
1749 |
break; |
|
77 | 1750 |
#endif |
1751 |
#ifdef ESOCKTNOSUPPORT |
|
185 | 1752 |
case ESOCKTNOSUPPORT: |
1753 |
msg = "Socket type not supported"; |
|
1754 |
break; |
|
77 | 1755 |
#endif |
1756 |
#ifdef EOPNOTSUPP |
|
185 | 1757 |
case EOPNOTSUPP: |
1758 |
msg = "Operation not supported on socket"; |
|
1759 |
break; |
|
77 | 1760 |
#endif |
1761 |
#ifdef EPFNOSUPPORT |
|
185 | 1762 |
case EPFNOSUPPORT: |
1763 |
msg = "Protocol family not supported"; |
|
1764 |
break; |
|
77 | 1765 |
#endif |
1766 |
#ifdef EAFNOSUPPORT |
|
185 | 1767 |
case EAFNOSUPPORT: |
1768 |
msg = "Address family not supported by protocol family"; |
|
1769 |
break; |
|
77 | 1770 |
#endif |
1771 |
#ifdef EADDRINUSE |
|
185 | 1772 |
case EADDRINUSE: |
1773 |
msg = "Address already in use"; |
|
1774 |
break; |
|
77 | 1775 |
#endif |
1776 |
#ifdef EADDRNOTAVAIL |
|
185 | 1777 |
case EADDRNOTAVAIL: |
1778 |
msg = "Can\'t assign requested address"; |
|
1779 |
break; |
|
77 | 1780 |
#endif |
1781 |
#ifdef ETIMEDOUT |
|
185 | 1782 |
case ETIMEDOUT: |
1783 |
msg = "Connection timed out"; |
|
1784 |
break; |
|
77 | 1785 |
#endif |
1786 |
#ifdef ECONNREFUSED |
|
185 | 1787 |
case ECONNREFUSED: |
1788 |
msg = "Connection refused"; |
|
1789 |
break; |
|
77 | 1790 |
#endif |
362 | 1791 |
#ifdef ENETDOWN |
1792 |
case ENETDOWN: |
|
1793 |
msg = "Network is down"; |
|
1794 |
break; |
|
1795 |
#endif |
|
1796 |
#ifdef ENETUNREACH |
|
1797 |
case ENETUNREACH: |
|
1798 |
msg = "Network is unreachable"; |
|
1799 |
break; |
|
1800 |
#endif |
|
1801 |
#ifdef ENETRESET |
|
1802 |
case ENETRESET: |
|
1803 |
msg = "Network dropped conn due to reset"; |
|
1804 |
break; |
|
1805 |
#endif |
|
1806 |
#ifdef ECONNABORTED |
|
1807 |
case ECONNABORTED: |
|
1808 |
msg = "Software caused connection abort"; |
|
1809 |
break; |
|
1810 |
#endif |
|
1811 |
#ifdef ECONNRESET |
|
1812 |
case ECONNRESET: |
|
1813 |
msg = "Connection reset by peer"; |
|
1814 |
break; |
|
1815 |
#endif |
|
1816 |
#ifdef EISCONN |
|
1817 |
case EISCONN: |
|
1818 |
msg = "Socket is already connected"; |
|
1819 |
break; |
|
1820 |
#endif |
|
1821 |
#ifdef ENOTCONN |
|
1822 |
case ENOTCONN: |
|
1823 |
msg = "Socket is not connected"; |
|
1824 |
break; |
|
1825 |
#endif |
|
1826 |
#ifdef ESHUTDOWN |
|
1827 |
case ESHUTDOWN: |
|
1828 |
msg = "Can't send after socket shutdown"; |
|
1829 |
break; |
|
1830 |
#endif |
|
1831 |
#ifdef EHOSTDOWN |
|
1832 |
case EHOSTDOWN: |
|
1833 |
msg = "Host is down"; |
|
1834 |
break; |
|
1835 |
#endif |
|
1836 |
#ifdef EHOSTUNREACH |
|
1837 |
case EHOSTUNREACH: |
|
1838 |
msg = "No route to host"; |
|
1839 |
break; |
|
1840 |
#endif |
|
1841 |
||
185 | 1842 |
default: |
368 | 1843 |
{ |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
805
diff
changeset
|
1844 |
__BEGIN_PROTECT_REGISTERS__ |
368 | 1845 |
sprintf(buffer, "ErrorNr: %d", _intVal(errNr)); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
805
diff
changeset
|
1846 |
__END_PROTECT_REGISTERS__ |
368 | 1847 |
} |
185 | 1848 |
msg = buffer; |
1849 |
break; |
|
1850 |
} |
|
77 | 1851 |
} |
830 | 1852 |
RETURN (__MKSTRING(msg COMMA_CON)); |
77 | 1853 |
%} |
616 | 1854 |
! |
1855 |
||
1856 |
lastErrorNumber |
|
1857 |
"return the last error number" |
|
1858 |
||
1859 |
^ LastErrorNumber |
|
1860 |
||
1861 |
" |
|
1862 |
OperatingSystem lastErrorNumber |
|
1863 |
" |
|
1864 |
! |
|
1865 |
||
1866 |
lastErrorString |
|
1867 |
"return a message string describing the last error" |
|
1868 |
||
1869 |
^ self errorTextForNumber:LastErrorNumber |
|
1870 |
||
1871 |
" |
|
1872 |
OperatingSystem lastErrorString |
|
1873 |
" |
|
1874 |
! |
|
1875 |
||
1876 |
lastExecStatus |
|
1877 |
"return the last execution status" |
|
1878 |
||
1879 |
^ LastExecStatus |
|
1880 |
||
1881 |
" |
|
1882 |
OperatingSystem lastExecStatus |
|
1883 |
" |
|
1 | 1884 |
! ! |
1885 |
||
616 | 1886 |
!OperatingSystem class methodsFor:'executing commands'! |
1887 |
||
1888 |
canExecuteCommand:aCommandString |
|
1889 |
"return true, if the OS can execute aCommand." |
|
1890 |
||
1891 |
|cmd| |
|
1892 |
||
1893 |
cmd := aCommandString asCollectionOfWords first. |
|
1894 |
^ (self pathOfCommand:cmd) notNil |
|
1895 |
||
1896 |
" |
|
1897 |
OperatingSystem canExecuteCommand:'fooBar' |
|
1898 |
OperatingSystem canExecuteCommand:'ls' |
|
1899 |
OperatingSystem canExecuteCommand:'cvs' |
|
1900 |
" |
|
1901 |
||
1902 |
"Created: 4.11.1995 / 19:13:54 / cg" |
|
68 | 1903 |
! |
1904 |
||
616 | 1905 |
exec:aPath withArguments:argArray |
1906 |
"execute the unix command specified by the argument, aPath, with |
|
1907 |
arguments in argArray (no arguments, if nil). |
|
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1908 |
If successful, this method does NOT return and smalltalk is gone. |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1909 |
If not successful, false is returned. Can be used with fork or to transfer |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1910 |
to another program." |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1911 |
|
792 | 1912 |
^ self exec:aPath withArguments:argArray fork:false |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1913 |
! |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1914 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1915 |
exec:aPath withArguments:argArray fileDescriptors:fdArray fork:doFork |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1916 |
"Internal combined fork & exec; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1917 |
If fork is false: |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1918 |
execute the unix command specified by the argument, aPath, with |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1919 |
arguments in argArray (no arguments, if nil). |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1920 |
If successful, this method does not return and smalltalk is gone. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1921 |
If not successful, false is returned. Normal use is with forkForCommand. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1922 |
if its true: |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1923 |
for a child to do the above. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1924 |
The id of the child process is returned; -1 if fork failed. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1925 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1926 |
fdArray contains the filedescriptors, to be used for the child (if fork is true). |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1927 |
fdArray[1] = 15 -> use fd 15 as stdin. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1928 |
If an element of the array is set to nil, the corresponding filedescriptor |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1929 |
will be closed for the child. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1930 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1931 |
Notice: this used to be two separate ST-methods; however, in order to use |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1932 |
vfork on some machines, it had to be merged into one, to avoid write |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1933 |
accesses to ST/X memory from the vforked-child. The code below only does |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1934 |
read accesses." |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1935 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1936 |
%{ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1937 |
#ifndef MSDOS_LIKE |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1938 |
char **argv; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1939 |
int nargs, i, id; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1940 |
OBJ arg; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1941 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1942 |
if (__isString(aPath) && |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1943 |
((argArray == nil) || __isArray(argArray)) && |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1944 |
((fdArray == nil) || __isArray(fdArray)) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1945 |
) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1946 |
nargs = argArray == nil ? 0 : _arraySize(argArray); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1947 |
argv = (char **) malloc(sizeof(char *) * (nargs + 1)); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1948 |
if (argv) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1949 |
for (i=0; i < nargs; i++) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1950 |
arg = _ArrayInstPtr(argArray)->a_element[i]; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1951 |
if (__isString(arg)) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1952 |
argv[i] = (char *) __stringVal(arg); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1953 |
} else { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1954 |
argv[i] = ""; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1955 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1956 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1957 |
argv[i] = NULL; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1958 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1959 |
if (doFork == true) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1960 |
int nfd; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1961 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1962 |
nfd = fdArray == nil ? 0 : _arraySize(fdArray); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1963 |
#ifdef HAS_VFORK |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1964 |
id = vfork(); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1965 |
#else |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1966 |
id = fork(); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1967 |
#endif |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1968 |
if (id == 0) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1969 |
/* |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1970 |
** In child. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1971 |
** first: dup filedescriptors |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1972 |
*/ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1973 |
for (i = 0; i < nfd; i++) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1974 |
if (__isSmallInteger(_ArrayInstPtr(fdArray)->a_element[i]) && |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1975 |
__intVal(_ArrayInstPtr(fdArray)->a_element[i]) != i |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1976 |
) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1977 |
dup2(__intVal(_ArrayInstPtr(fdArray)->a_element[i]), i); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1978 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1979 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1980 |
/* |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1981 |
** second: close unused filedescriptors |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1982 |
*/ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1983 |
for (i = 0; i < nfd; i++) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1984 |
if (_ArrayInstPtr(fdArray)->a_element[i] == nil) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1985 |
close(i); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1986 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1987 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1988 |
execv(_stringVal(aPath), argv); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1989 |
/* should not be reached */ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1990 |
_exit(127); /* POSIX 2 compatible exit value */ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1991 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1992 |
/* |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1993 |
** In parent: succes or failure |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1994 |
*/ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1995 |
free(argv); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1996 |
RETURN (__MKSMALLINT(id)); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1997 |
} else { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1998 |
execv(_stringVal(aPath), argv); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
1999 |
/* |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2000 |
* should not be reached |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2001 |
* (well, it is, if you pass a wrong command-path) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2002 |
*/ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2003 |
free(argv); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2004 |
RETURN ( false ); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2005 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2006 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2007 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2008 |
#endif |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2009 |
%}. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2010 |
" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2011 |
path-argument not string |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2012 |
or argArray not an array/nil |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2013 |
or malloc failed |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2014 |
or not supported by OS |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2015 |
" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2016 |
^ self primitiveFailed |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2017 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2018 |
" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2019 |
|id| |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2020 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2021 |
id := OperatingSystem fork. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2022 |
id == 0 ifTrue:[ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2023 |
"I am the child" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2024 |
OperatingSystem exec:'/bin/ls' withArguments:#('ls' '/tmp'). |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2025 |
"not reached" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2026 |
] |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2027 |
" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2028 |
" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2029 |
|id| |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2030 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2031 |
id := OperatingSystem fork. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2032 |
id == 0 ifTrue:[ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2033 |
"I am the child" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2034 |
OperatingSystem exec:'/bin/sh' withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2'). |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2035 |
"not reached" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2036 |
]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2037 |
id printNL. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2038 |
(Delay forSeconds:3.5) wait. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2039 |
'killing ...' printNL. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2040 |
OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2041 |
OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2042 |
" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2043 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2044 |
|
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2045 |
exec:aPath withArguments:argArray fork:doFork |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2046 |
"Internal combined fork & exec; |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2047 |
If fork is false: |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2048 |
execute the unix command specified by the argument, aPath, with |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2049 |
arguments in argArray (no arguments, if nil). |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2050 |
If successful, this method does not return and smalltalk is gone. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2051 |
If not successful, false is returned. Normal use is with forkForCommand. |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2052 |
if its true: |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2053 |
for a child to do the above. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2054 |
The id of the child process is returned; -1 if fork failed. |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2055 |
|
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2056 |
Notice: this used to be two separate ST-methods; however, in order to use |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2057 |
vfork on some machines, it had to be merged into one, to avoid write |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2058 |
accesses to ST/X memory from the vforked-child. The code below only does |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2059 |
read accesses." |
616 | 2060 |
|
2061 |
%{ |
|
792 | 2062 |
#ifndef MSDOS_LIKE |
616 | 2063 |
char **argv; |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2064 |
int nargs, i, id; |
616 | 2065 |
OBJ arg; |
2066 |
||
2067 |
if (__isString(aPath) && ((argArray == nil) || __isArray(argArray))) { |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2068 |
nargs = argArray == nil ? 0 : _arraySize(argArray); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2069 |
argv = (char **) malloc(sizeof(char *) * (nargs + 1)); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2070 |
if (argv) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2071 |
for (i=0; i < nargs; i++) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2072 |
arg = _ArrayInstPtr(argArray)->a_element[i]; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2073 |
if (__isString(arg)) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2074 |
argv[i] = (char *) __stringVal(arg); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2075 |
} else { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2076 |
argv[i] = ""; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2077 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2078 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2079 |
argv[i] = NULL; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2080 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2081 |
if (doFork == true) { |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2082 |
#ifdef HAS_VFORK |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2083 |
id = vfork(); |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2084 |
#else |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2085 |
id = fork(); |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2086 |
#endif |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2087 |
if (id == 0) { |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2088 |
execv(_stringVal(aPath), argv); |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2089 |
/* should not be reached */ |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2090 |
_exit(127); /* POSIX-2 compatible exit value */ |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2091 |
} |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2092 |
free(argv); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2093 |
RETURN (__MKSMALLINT(id)); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2094 |
} else { |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2095 |
execv(_stringVal(aPath), argv); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2096 |
/* |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2097 |
* should not be reached |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2098 |
* (well, it is, if you pass a wrong command-path) |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2099 |
*/ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2100 |
free(argv); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
2101 |
RETURN ( false ); |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2102 |
} |
616 | 2103 |
} |
2104 |
} |
|
792 | 2105 |
#endif |
616 | 2106 |
%}. |
2107 |
" |
|
792 | 2108 |
path-argument not string |
2109 |
or argArray not an array/nil |
|
2110 |
or malloc failed |
|
2111 |
or not supported by OS |
|
616 | 2112 |
" |
2113 |
^ self primitiveFailed |
|
2114 |
||
2115 |
" |
|
2116 |
|id| |
|
2117 |
||
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2118 |
id := OperatingSystem fork. |
616 | 2119 |
id == 0 ifTrue:[ |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2120 |
"I am the child" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2121 |
OperatingSystem exec:'/bin/ls' withArguments:#('ls' '/tmp'). |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2122 |
"not reached" |
616 | 2123 |
] |
2124 |
" |
|
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2125 |
" |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2126 |
|id| |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2127 |
|
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2128 |
id := OperatingSystem fork. |
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2129 |
id == 0 ifTrue:[ |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2130 |
"I am the child" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2131 |
OperatingSystem exec:'/bin/sh' withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2'). |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2132 |
"not reached" |
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2133 |
]. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2134 |
id printNL. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2135 |
(Delay forSeconds:3.5) wait. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2136 |
'killing ...' printNL. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2137 |
OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2138 |
OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2139 |
" |
616 | 2140 |
! |
2141 |
||
2142 |
executeCommand:aCommandString |
|
2143 |
"execute the unix command specified by the argument, aCommandString. |
|
676 | 2144 |
The commandString is passed to a shell for execution - see the description of |
2145 |
'sh -c' in your UNIX manual. |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2146 |
Return true if successful, false otherwise." |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2147 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2148 |
" when all machines have been checked, this will be defined as: |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2149 |
^ self executeCommand:aCommandString onError:[:status| false] |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2150 |
until then:" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2151 |
|
616 | 2152 |
%{ |
2153 |
int status; |
|
2154 |
||
2155 |
if (__isString(aCommandString)) { |
|
2156 |
/* |
|
2157 |
* ST/X provides a modified (fixed) implementation of the |
|
2158 |
* system() libc-function, which is interruptable ... |
|
2159 |
*/ |
|
2160 |
# ifdef WANT_SYSTEM |
|
2161 |
status = mySystem((char *) _stringVal(aCommandString)); |
|
2162 |
# else |
|
2163 |
status = system((char *) _stringVal(aCommandString)); |
|
2164 |
# endif |
|
2165 |
OperatingSystem_LastExecStatus = _MKSMALLINT(status); |
|
2166 |
if (status == 0) { |
|
2167 |
RETURN ( true ); |
|
2168 |
} |
|
2169 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2170 |
RETURN ( false ); |
|
2171 |
} |
|
2172 |
%}. |
|
792 | 2173 |
"/ |
2174 |
"/ invalid argument (non-string) |
|
2175 |
"/ |
|
2176 |
^ self primitiveFailed |
|
616 | 2177 |
|
2178 |
" |
|
805 | 2179 |
OperatingSystem executeCommand:'sleep 30'. |
616 | 2180 |
OperatingSystem executeCommand:'pwd'. |
2181 |
OperatingSystem executeCommand:'ls -l'. |
|
2182 |
OperatingSystem executeCommand:'invalidCommand'. |
|
2183 |
OperatingSystem executeCommand:'rm /tmp/foofoofoofoo'. |
|
2184 |
" |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2185 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2186 |
"Modified: 27.12.1995 / 23:40:35 / stefan" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2187 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2188 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2189 |
executeCommand:aCommandString onError:aBlock |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2190 |
"execute the unix command specified by the argument, aCommandString. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2191 |
The commandString is passed to a shell for execution - see the description of |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2192 |
'sh -c' in your UNIX manual. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2193 |
Return true if successful. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2194 |
If not successfull, aBlock is called with a Dictionary containing the exit status |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2195 |
as argument." |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2196 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2197 |
|blocked pid exitStatus sema| |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2198 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2199 |
sema := Semaphore new. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2200 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2201 |
blocked := OperatingSystem blockInterrupts. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2202 |
pid := self startProcess:aCommandString. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2203 |
pid > 0 ifTrue:[ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2204 |
Processor monitorPid:pid action:[ :stat | |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2205 |
stat stillAlive ifFalse:[ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2206 |
exitStatus := stat. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2207 |
sema signal |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2208 |
]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2209 |
]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2210 |
sema wait. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2211 |
] ifFalse:[ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2212 |
exitStatus := OSProcessStatus processCreationFailure. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2213 |
]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2214 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2215 |
blocked ifFalse:[ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2216 |
OperatingSystem unblockInterrupts |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2217 |
]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2218 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2219 |
exitStatus success ifFalse:[ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2220 |
^ aBlock value:exitStatus |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2221 |
]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2222 |
^ true. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2223 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2224 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2225 |
" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2226 |
OperatingSystem executeCommand:'sleep 30' onError:[]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2227 |
OperatingSystem executeCommand:'pwd' onError:[:status|status inspect]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2228 |
OperatingSystem executeCommand:'ls -l' onError:[]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2229 |
OperatingSystem executeCommand:'invalidCommand' onError:[:status| status inspect]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2230 |
OperatingSystem executeCommand:'rm /tmp/foofoofoofoo'onError:[:status | status inspect]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2231 |
" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2232 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2233 |
"Created: 22.12.1995 / 14:49:59 / stefan" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2234 |
"Modified: 28.12.1995 / 15:25:48 / stefan" |
616 | 2235 |
! |
2236 |
||
2237 |
fork |
|
2238 |
"fork a new (HEAVY-weight) unix process. |
|
2239 |
Dont confuse this with Block>>fork, which creates |
|
2240 |
lightweight smalltalk processes. This method will return |
|
676 | 2241 |
0 to the child process, and a non-zero number (which is the childs |
2242 |
unix-process-id) to the parent (original) process. |
|
764
eadba1b6a721
vfork interface (for poor BSD ultrix) - without it, it takes 20 seconds
Claus Gittinger <cg@exept.de>
parents:
763
diff
changeset
|
2243 |
|
676 | 2244 |
In normal situations, you dont need to use this low level entry; see |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2245 |
#startProcess: and #executCommand: for higher level interfaces." |
68 | 2246 |
|
2247 |
%{ /* NOCONTEXT */ |
|
792 | 2248 |
#ifndef MSDOS_LIKE |
616 | 2249 |
|
2250 |
int pid; |
|
2251 |
||
2252 |
pid = fork(); |
|
2253 |
RETURN ( _MKSMALLINT(pid) ); |
|
792 | 2254 |
#endif |
2255 |
%}. |
|
2256 |
"/ |
|
2257 |
"/ not supported by OS |
|
2258 |
"/ |
|
2259 |
^ self primitiveFailed |
|
2260 |
||
616 | 2261 |
" |
2262 |
|id| |
|
2263 |
||
2264 |
id := OperatingSystem fork. |
|
2265 |
id == 0 ifTrue:[ |
|
2266 |
OperatingSystem exit |
|
2267 |
] |
|
2268 |
" |
|
68 | 2269 |
! |
2270 |
||
616 | 2271 |
pathOfCommand:aCommand |
2272 |
"find where aCommand's executable file is" |
|
2273 |
||
2274 |
|path f| |
|
2275 |
||
2276 |
path := self getEnvironment:'PATH'. |
|
2277 |
path notNil ifTrue:[ |
|
2278 |
(path asCollectionOfSubstringsSeparatedBy:$:) do:[:path | |
|
2279 |
(f := (path asFilename construct:aCommand)) isExecutable ifTrue:[ |
|
2280 |
^ f pathName |
|
2281 |
] |
|
2282 |
]. |
|
2283 |
]. |
|
2284 |
^ nil |
|
2285 |
||
2286 |
" |
|
2287 |
OperatingSystem pathOfCommand:'fooBar' |
|
2288 |
OperatingSystem pathOfCommand:'ls' |
|
2289 |
OperatingSystem pathOfCommand:'cvs' |
|
2290 |
" |
|
704 | 2291 |
! |
2292 |
||
2293 |
startProcess:aCommandString |
|
2294 |
"start executing the unix command as specified by the argument, aCommandString |
|
714 | 2295 |
as a separate process; do not wait for the command to finish. |
704 | 2296 |
The commandString is passed to a shell for execution - see the description of |
2297 |
'sh -c' in your UNIX manual. |
|
2298 |
Return the processId if successful, nil otherwise. |
|
714 | 2299 |
Use #waitForProcess: for synchronization and exec status return, |
2300 |
or #killProcess: to stop it." |
|
704 | 2301 |
|
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2302 |
^ self |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2303 |
exec:'/bin/sh' |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2304 |
withArguments:(Array with:'sh' with:'-c' with:aCommandString) |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2305 |
fork:true. |
704 | 2306 |
|
2307 |
" |
|
2308 |
|pid| |
|
2309 |
||
2310 |
pid := OperatingSystem startProcess:'sleep 2; echo 1; sleep 2; echo 2'. |
|
2311 |
(Delay forSeconds:3) wait. |
|
2312 |
OperatingSystem killProcess:pid. |
|
2313 |
" |
|
616 | 2314 |
! ! |
2315 |
||
2316 |
!OperatingSystem class methodsFor:'file access'! |
|
2317 |
||
2318 |
accessMaskFor:aSymbol |
|
2319 |
"return the access bits mask for numbers as returned by |
|
2320 |
OperatingSystem>>accessModeOf: |
|
2321 |
and expected by OperatingSystem>>changeAccessModeOf:to:. |
|
2322 |
Since these numbers are OS dependent, always use the mask |
|
2323 |
(never hardcode 8rxxx into your code)." |
|
68 | 2324 |
|
2325 |
%{ /* NOCONTEXT */ |
|
616 | 2326 |
# ifndef S_IRUSR |
2327 |
/* posix systems should define these ... */ |
|
2328 |
# define S_IRUSR 0400 |
|
2329 |
# define S_IWUSR 0200 |
|
2330 |
# define S_IXUSR 0100 |
|
2331 |
# define S_IRGRP 0040 |
|
2332 |
# define S_IWGRP 0020 |
|
2333 |
# define S_IXGRP 0010 |
|
2334 |
# define S_IROTH 0004 |
|
2335 |
# define S_IWOTH 0002 |
|
2336 |
# define S_IXOTH 0001 |
|
2337 |
||
2338 |
# endif |
|
2339 |
||
2340 |
if (aSymbol == @symbol(readUser)) { |
|
710 | 2341 |
RETURN ( _MKSMALLINT(S_IRUSR) ); |
616 | 2342 |
} |
2343 |
if (aSymbol == @symbol(writeUser)) { |
|
710 | 2344 |
RETURN ( _MKSMALLINT(S_IWUSR) ); |
616 | 2345 |
} |
2346 |
if (aSymbol == @symbol(executeUser)) { |
|
710 | 2347 |
RETURN ( _MKSMALLINT(S_IXUSR) ); |
616 | 2348 |
} |
2349 |
if (aSymbol == @symbol(readGroup)) { |
|
710 | 2350 |
RETURN ( _MKSMALLINT(S_IRGRP) ); |
616 | 2351 |
} |
2352 |
if (aSymbol == @symbol(writeGroup)) { |
|
710 | 2353 |
RETURN ( _MKSMALLINT(S_IWGRP) ); |
616 | 2354 |
} |
2355 |
if (aSymbol == @symbol(executeGroup)) { |
|
710 | 2356 |
RETURN ( _MKSMALLINT(S_IXGRP) ); |
616 | 2357 |
} |
2358 |
if (aSymbol == @symbol(readOthers)) { |
|
710 | 2359 |
RETURN ( _MKSMALLINT(S_IROTH) ); |
616 | 2360 |
} |
2361 |
if (aSymbol == @symbol(writeOthers)) { |
|
710 | 2362 |
RETURN ( _MKSMALLINT(S_IWOTH) ); |
616 | 2363 |
} |
2364 |
if (aSymbol == @symbol(executeOthers)) { |
|
710 | 2365 |
RETURN ( _MKSMALLINT(S_IXOTH) ); |
616 | 2366 |
} |
2367 |
%}. |
|
792 | 2368 |
^ self primitiveFailed |
616 | 2369 |
|
2370 |
" |
|
2371 |
OperatingSystem accessMaskFor:#readUser |
|
2372 |
" |
|
68 | 2373 |
! |
2374 |
||
616 | 2375 |
accessModeOf:aPathName |
2376 |
"return a number representing access rights rwxrwxrwx for owner, |
|
2377 |
group and others. Return nil if such a file does not exist. |
|
2378 |
Notice that the returned number is OS dependent - use the |
|
2379 |
modeMasks as returned by OperatingSystem>>accessMaskFor:" |
|
2380 |
||
2381 |
" |
|
2382 |
this could have been implemented as: |
|
2383 |
(self infoOf:aPathName) at:#mode |
|
2384 |
but for huge directory searches the code below is faster |
|
2385 |
" |
|
345 | 2386 |
|
2387 |
%{ /* NOCONTEXT */ |
|
616 | 2388 |
|
2389 |
struct stat buf; |
|
2390 |
int ret; |
|
2391 |
||
2392 |
if (__isString(aPathName)) { |
|
2393 |
__BEGIN_INTERRUPTABLE__ |
|
2394 |
do { |
|
2395 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2396 |
} while ((ret < 0) && (errno == EINTR)); |
|
2397 |
__END_INTERRUPTABLE__ |
|
2398 |
||
2399 |
if (ret < 0) { |
|
2400 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2401 |
RETURN ( nil ); |
|
2402 |
} |
|
2403 |
RETURN ( _MKSMALLINT(buf.st_mode & 0777) ); |
|
2404 |
} |
|
2405 |
%}. |
|
792 | 2406 |
^ self primitiveFailed |
616 | 2407 |
|
2408 |
" |
|
2409 |
(OperatingSystem accessModeOf:'/') printStringRadix:8 |
|
2410 |
" |
|
345 | 2411 |
! |
2412 |
||
616 | 2413 |
baseNameOf:aPathString |
2414 |
"return the baseName of the argument, aPathString |
|
2415 |
- thats the file/directory name without leading parent-dirs |
|
2416 |
(i.e. OperatingSystem baseNameOf:'/usr/lib/st/file' -> 'file' |
|
2417 |
and OperatingSystem baseNameOf:'/usr/lib' -> lib). |
|
2418 |
This method does not check if the path is valid |
|
2419 |
(i.e. if these directories really exist & is readable)." |
|
2420 |
||
2421 |
|prev index sep| |
|
2422 |
||
2423 |
sep := self fileSeparator. |
|
2424 |
((aPathString size == 1) and:[(aPathString at:1) == sep]) ifTrue:[ |
|
2425 |
^ aPathString |
|
2426 |
]. |
|
2427 |
prev := 1. |
|
2428 |
[true] whileTrue:[ |
|
2429 |
index := aPathString indexOf:sep startingAt:prev. |
|
2430 |
index == 0 ifTrue:[ |
|
2431 |
^ aPathString copyFrom:prev |
|
2432 |
]. |
|
2433 |
prev := index + 1 |
|
2434 |
] |
|
2435 |
||
2436 |
" |
|
2437 |
OperatingSystem baseNameOf:'/fee/foo/bar' |
|
2438 |
OperatingSystem baseNameOf:'foo/bar' |
|
2439 |
OperatingSystem baseNameOf:'../../foo/bar' |
|
2440 |
OperatingSystem baseNameOf:'hello' |
|
2441 |
" |
|
2442 |
! |
|
2443 |
||
2444 |
caseSensitiveFilenames |
|
2445 |
"return true, if the OS has caseSensitive file naming. |
|
2446 |
On MSDOS, this will return false. Since this is for Unix, we |
|
2447 |
return true." |
|
2448 |
||
2449 |
^ true |
|
2450 |
! |
|
2451 |
||
2452 |
changeAccessModeOf:aPathName to:modeBits |
|
2453 |
"change the access rights of aPathName to the OS dependent modeBits. |
|
2454 |
You should construct this mask using accessMaskFor, to be OS |
|
2455 |
independent. Return true if changed, |
|
2456 |
false if such a file does not exist or change was not allowd." |
|
68 | 2457 |
|
2458 |
%{ /* NOCONTEXT */ |
|
616 | 2459 |
int ret; |
2460 |
||
2461 |
if (__isString(aPathName) && __isSmallInteger(modeBits)) { |
|
2462 |
__BEGIN_INTERRUPTABLE__ |
|
2463 |
do { |
|
2464 |
ret = chmod((char *)_stringVal(aPathName), _intVal(modeBits)); |
|
2465 |
} while (ret < 0 && errno == EINTR); |
|
2466 |
__END_INTERRUPTABLE__ |
|
2467 |
if (ret < 0) { |
|
2468 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2469 |
RETURN ( false ); |
|
2470 |
} |
|
2471 |
RETURN ( true ); |
|
2472 |
} |
|
2473 |
%}. |
|
792 | 2474 |
^ self primitiveFailed |
616 | 2475 |
! |
2476 |
||
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2477 |
closeFd:anInteger |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2478 |
"low level close of a filedescriptor" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2479 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2480 |
%{ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2481 |
#if !defined(transputer) && !defined(MSDOS_LIKE) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2482 |
if (__isSmallInteger(anInteger)) { |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2483 |
close(__intVal(anInteger)); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2484 |
RETURN(self); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2485 |
} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2486 |
#endif |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2487 |
%}. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2488 |
^ self primitiveFailed. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2489 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2490 |
|
616 | 2491 |
compressPath:pathName |
2492 |
"return the pathName compressed - that is, remove all ..-entries |
|
2493 |
and . entries. This does not always (in case of symbolic links) |
|
2494 |
return the true pathName and is therefore used as a fallback |
|
2495 |
if realPath and popen failed." |
|
2496 |
||
2497 |
|names| |
|
2498 |
||
2499 |
names := pathName |
|
2500 |
asCollectionOfSubstringsSeparatedBy:self fileSeparator. |
|
2501 |
names := names asOrderedCollection. |
|
2502 |
" |
|
2503 |
cut off initial double-slashes |
|
2504 |
" |
|
2505 |
[names startsWith:#('' '')] whileTrue:[ |
|
2506 |
names removeFirst. |
|
2507 |
]. |
|
2508 |
" |
|
2509 |
cut off double-slashes at end |
|
2510 |
" |
|
2511 |
[names endsWith:#('')] whileTrue:[ |
|
2512 |
names removeLast. |
|
2513 |
]. |
|
2514 |
" |
|
2515 |
cut off current-dir at beginning |
|
2516 |
" |
|
2517 |
[(names size >= 2) and:[names startsWith:#('.')]] whileTrue:[ |
|
2518 |
names removeFirst. |
|
2519 |
]. |
|
2520 |
||
2521 |
" |
|
2522 |
cut off parent-dirs at end |
|
2523 |
" |
|
2524 |
[(names size > 2) |
|
2525 |
and:[(names endsWith:#('..')) |
|
2526 |
and:[((names at:(names size - 1)) startsWith:'.') not ]]] whileTrue:[ |
|
2527 |
names removeLast; removeLast |
|
2528 |
]. |
|
2529 |
||
2530 |
^ names asStringWith:self fileSeparator |
|
2531 |
from:1 |
|
2532 |
to:names size |
|
2533 |
compressTabs:false final:nil |
|
2534 |
||
2535 |
" |
|
2536 |
OperatingSystem compressPath:'./..' |
|
2537 |
OperatingSystem compressPath:'/foo/bar/baz/..' |
|
2538 |
OperatingSystem compressPath:'foo/bar/baz/..' |
|
2539 |
OperatingSystem compressPath:'foo/bar/baz/../' |
|
2540 |
OperatingSystem compressPath:'foo/bar/baz/..///' |
|
2541 |
OperatingSystem compressPath:'///foo/bar/baz/..///' |
|
2542 |
" |
|
68 | 2543 |
! |
2544 |
||
616 | 2545 |
createDirectory:newPathName |
2546 |
"create a new directory with name 'newPathName'. |
|
2547 |
Return true if successful, false if failed." |
|
2548 |
||
2549 |
"since createDirectory is not used too often, |
|
2550 |
you'll forgive me using mkdir ..." |
|
2551 |
||
798
90a518c71a7f
recursiveRemoveDirectory does not print garbage to stderr any longer; computeDateAndTimeFrom: now returns the utcOffset
Stefan Vogel <sv@exept.de>
parents:
792
diff
changeset
|
2552 |
^ self executeCommand:('mkdir 2>/dev/null ', newPathName) |
616 | 2553 |
|
2554 |
"OperatingSystem createDirectory:'foo'" |
|
798
90a518c71a7f
recursiveRemoveDirectory does not print garbage to stderr any longer; computeDateAndTimeFrom: now returns the utcOffset
Stefan Vogel <sv@exept.de>
parents:
792
diff
changeset
|
2555 |
|
90a518c71a7f
recursiveRemoveDirectory does not print garbage to stderr any longer; computeDateAndTimeFrom: now returns the utcOffset
Stefan Vogel <sv@exept.de>
parents:
792
diff
changeset
|
2556 |
"Modified: 20.12.1995 / 11:24:13 / stefan" |
616 | 2557 |
! |
2558 |
||
2559 |
directoryNameOf:aPathString |
|
2560 |
"return the directoryName of the argument, aPath |
|
2561 |
- thats the name of the directory where aPath is |
|
2562 |
(i.e. OperatingSystem directoryNameOf:'/usr/lib/st/file' -> '/usr/lib/st' |
|
2563 |
and OperatingSystem directoryNameOf:'/usr/lib' -> /usr'). |
|
2564 |
This method does not check if the path is valid |
|
2565 |
(i.e. if these directories really exist & are readable)." |
|
2566 |
||
2567 |
|last index sep sepString| |
|
2568 |
||
2569 |
sep := self fileSeparator. |
|
2570 |
sepString := sep asString. |
|
2571 |
(aPathString = sepString) ifTrue:[ |
|
2572 |
" |
|
2573 |
the trivial '/' case |
|
2574 |
" |
|
2575 |
^ aPathString |
|
2576 |
]. |
|
2577 |
(aPathString startsWith:sepString) ifFalse:[ |
|
2578 |
(aPathString endsWith:sepString) ifTrue:[ |
|
2579 |
^ aPathString copyTo:(aPathString size - 1) |
|
2580 |
]. |
|
2581 |
]. |
|
2582 |
last := 1. |
|
2583 |
[true] whileTrue:[ |
|
2584 |
index := aPathString indexOf:sep startingAt:(last + 1). |
|
2585 |
index == 0 ifTrue:[ |
|
2586 |
(last == 1) ifTrue:[ |
|
2587 |
(aPathString startsWith:sepString) ifTrue:[ |
|
2588 |
^ sepString |
|
2589 |
]. |
|
2590 |
^ '.' |
|
2591 |
]. |
|
2592 |
" |
|
2593 |
(aPathString startsWith:sepString) ifFalse:[ |
|
2594 |
(aPathString startsWith:('..' , sepString)) ifFalse:[ |
|
2595 |
^ './' , (aPathString copyTo:(last - 1)) |
|
2596 |
] |
|
2597 |
]. |
|
2598 |
" |
|
2599 |
^ aPathString copyTo:(last - 1) |
|
2600 |
]. |
|
2601 |
last := index. |
|
2602 |
] |
|
2603 |
||
2604 |
" |
|
2605 |
OperatingSystem directoryNameOf:'/fee/foo/bar' |
|
2606 |
OperatingSystem directoryNameOf:'foo/bar' |
|
2607 |
OperatingSystem directoryNameOf:'../../foo/bar' |
|
2608 |
OperatingSystem directoryNameOf:'bar' |
|
2609 |
OperatingSystem directoryNameOf:'/bar' |
|
2610 |
" |
|
2611 |
! |
|
2612 |
||
2613 |
fileSeparator |
|
2614 |
"return the character used to separate names in a path. |
|
2615 |
This character differs for MSDOS and other systems, |
|
2616 |
(but those are currently not supported - so this is some |
|
2617 |
preparation for the future)" |
|
2618 |
||
2619 |
^ $/ |
|
2620 |
! |
|
2621 |
||
2622 |
getCharacter |
|
2623 |
"read a character from keyboard - |
|
2624 |
this is a blocking low-level read, provided for debugger |
|
2625 |
and fatal conditions. Use Stdin or (even better) the event |
|
2626 |
mechanisms provided." |
|
68 | 2627 |
|
2628 |
%{ /* NOCONTEXT */ |
|
616 | 2629 |
|
2630 |
RETURN ( _MKSMALLINT(getchar()) ); |
|
68 | 2631 |
%} |
2632 |
! |
|
2633 |
||
616 | 2634 |
idOf:aPathName |
2635 |
"return the fileNumber (i.e. inode number) of a file" |
|
2636 |
||
2637 |
" |
|
2638 |
this could have been implemented as: |
|
2639 |
(self infoOf:aPathName) at:#id |
|
2640 |
but for huge directory searches the code below is faster |
|
2641 |
" |
|
68 | 2642 |
|
2643 |
%{ /* NOCONTEXT */ |
|
616 | 2644 |
|
2645 |
struct stat buf; |
|
2646 |
int ret; |
|
2647 |
||
2648 |
if (__isString(aPathName)) { |
|
2649 |
__BEGIN_INTERRUPTABLE__ |
|
2650 |
do { |
|
2651 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2652 |
} while (ret < 0 && errno == EINTR); |
|
2653 |
__END_INTERRUPTABLE__ |
|
2654 |
if (ret >= 0) { |
|
2655 |
RETURN (_MKSMALLINT(buf.st_ino)); |
|
2656 |
} |
|
2657 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2658 |
RETURN (nil); |
|
2659 |
} |
|
68 | 2660 |
%} |
616 | 2661 |
. |
792 | 2662 |
^ self primitiveFailed |
616 | 2663 |
|
2664 |
"OperatingSystem idOf:'/'" |
|
68 | 2665 |
! |
2666 |
||
616 | 2667 |
infoOf:aPathName |
2668 |
"return a dictionary filled with info for the file 'aPathName'; |
|
2669 |
info is: (type->t mode->n uid->u gid->g size->s id->ino). |
|
2670 |
return nil if such a file does not exist. A dictionary is returned, |
|
2671 |
since we might need to add more info in the future without affecting |
|
2672 |
existing applications." |
|
2673 |
||
2674 |
|info type mode uid gid size id |
|
2675 |
atimeLow atimeHi mtimeLow mtimeHi ctimeLow ctimeHi| |
|
2676 |
||
2677 |
%{ |
|
2678 |
struct stat buf; |
|
2679 |
int ret; |
|
2680 |
||
2681 |
if (__isString(aPathName)) { |
|
2682 |
__BEGIN_INTERRUPTABLE__ |
|
2683 |
do { |
|
2684 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2685 |
} while ((ret < 0) && (errno == EINTR)); |
|
2686 |
__END_INTERRUPTABLE__ |
|
2687 |
||
2688 |
if (ret < 0) { |
|
2689 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2690 |
RETURN ( nil ); |
|
2691 |
} |
|
2692 |
switch (buf.st_mode & S_IFMT) { |
|
2693 |
case S_IFDIR: |
|
2694 |
type = @symbol(directory); |
|
2695 |
break; |
|
2696 |
case S_IFREG: |
|
2697 |
type = @symbol(regular); |
|
2698 |
break; |
|
2699 |
#ifdef S_IFCHR |
|
2700 |
case S_IFCHR: |
|
2701 |
type = @symbol(characterSpecial); |
|
2702 |
break; |
|
2703 |
#endif |
|
2704 |
#ifdef S_IFBLK |
|
2705 |
case S_IFBLK: |
|
2706 |
type = @symbol(blockSpecial); |
|
2707 |
break; |
|
2708 |
#endif |
|
2709 |
#ifdef S_IFLNK |
|
2710 |
case S_IFLNK: |
|
2711 |
type = @symbol(symbolicLink); |
|
2712 |
break; |
|
2713 |
#endif |
|
2714 |
#ifdef S_IFSOCK |
|
2715 |
case S_IFSOCK: |
|
2716 |
type = @symbol(socket); |
|
2717 |
break; |
|
2718 |
#endif |
|
2719 |
#ifdef S_IFIFO |
|
2720 |
case S_IFIFO: |
|
2721 |
type = @symbol(fifo); |
|
2722 |
break; |
|
2723 |
#endif |
|
2724 |
default: |
|
2725 |
type = @symbol(unknown); |
|
2726 |
break; |
|
2727 |
} |
|
2728 |
mode = _MKSMALLINT(buf.st_mode & 0777); |
|
2729 |
uid = _MKSMALLINT(buf.st_uid); |
|
2730 |
gid = _MKSMALLINT(buf.st_gid); |
|
2731 |
size = _MKSMALLINT(buf.st_size); |
|
2732 |
id = _MKSMALLINT(buf.st_ino); |
|
2733 |
atimeLow = _MKSMALLINT(buf.st_atime & 0xFFFF); |
|
2734 |
atimeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF); |
|
2735 |
mtimeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF); |
|
2736 |
mtimeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF); |
|
2737 |
ctimeLow = _MKSMALLINT(buf.st_ctime & 0xFFFF); |
|
2738 |
ctimeHi = _MKSMALLINT((buf.st_ctime >> 16) & 0xFFFF); |
|
2739 |
} |
|
2740 |
%}. |
|
2741 |
mode notNil ifTrue:[ |
|
2742 |
info := IdentityDictionary new. |
|
2743 |
info at:#type put:type. |
|
2744 |
info at:#mode put:mode. |
|
2745 |
info at:#uid put:uid. |
|
2746 |
info at:#gid put:gid. |
|
2747 |
info at:#size put:size. |
|
2748 |
info at:#id put:id. |
|
2749 |
info at:#accessed put:(AbsoluteTime fromOSTimeLow:atimeLow and:atimeHi). |
|
2750 |
info at:#modified put:(AbsoluteTime fromOSTimeLow:mtimeLow and:mtimeHi). |
|
2751 |
info at:#statusChanged put:(AbsoluteTime fromOSTimeLow:ctimeLow and:ctimeHi). |
|
2752 |
^ info |
|
2753 |
]. |
|
792 | 2754 |
^ self primitiveFailed |
616 | 2755 |
|
2756 |
" |
|
2757 |
OperatingSystem infoOf:'/' |
|
2758 |
(OperatingSystem infoOf:'/') at:#uid |
|
2759 |
(OperatingSystem infoOf:'/') at:#accessed |
|
2760 |
" |
|
68 | 2761 |
! |
2762 |
||
616 | 2763 |
isDirectory:aPathName |
2764 |
"return true, if 'aPathName' is a valid directory path name. |
|
2765 |
(i.e. exists and is a directory)" |
|
68 | 2766 |
|
2767 |
%{ /* NOCONTEXT */ |
|
616 | 2768 |
|
2769 |
struct stat buf; |
|
2770 |
int ret; |
|
2771 |
||
2772 |
if (__isString(aPathName)) { |
|
2773 |
__BEGIN_INTERRUPTABLE__ |
|
2774 |
do { |
|
2775 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2776 |
} while ((ret < 0) && (errno == EINTR)); |
|
2777 |
__END_INTERRUPTABLE__ |
|
2778 |
if (ret < 0) { |
|
2779 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2780 |
RETURN ( false ); |
|
2781 |
} |
|
2782 |
RETURN ( ((buf.st_mode & S_IFMT) == S_IFDIR) ? true : false); |
|
2783 |
} |
|
2784 |
%}. |
|
792 | 2785 |
^ self primitiveFailed |
616 | 2786 |
|
2787 |
"an alternative implementation would be: |
|
2788 |
^ (self infoOf:aPathName) at:#type == #directory |
|
2789 |
" |
|
68 | 2790 |
! |
2791 |
||
616 | 2792 |
isExecutable:aPathName |
2793 |
"return true, if the given file is executable" |
|
68 | 2794 |
|
2795 |
%{ /* NOCONTEXT */ |
|
616 | 2796 |
int ret; |
2797 |
||
2798 |
if (__isString(aPathName)) { |
|
2799 |
__BEGIN_INTERRUPTABLE__ |
|
2800 |
do { |
|
2801 |
ret = access(_stringVal(aPathName), X_OK); |
|
2802 |
} while ((ret < 0) && (errno == EINTR)); |
|
2803 |
__END_INTERRUPTABLE__ |
|
2804 |
if (ret < 0) { |
|
2805 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2806 |
} |
|
710 | 2807 |
RETURN ( ((ret == 0) ? true : false) ); |
616 | 2808 |
} |
2809 |
%}. |
|
792 | 2810 |
^ self primitiveFailed |
68 | 2811 |
! |
2812 |
||
616 | 2813 |
isReadable:aPathName |
2814 |
"return true, if the file/dir 'aPathName' is readable." |
|
68 | 2815 |
|
2816 |
%{ /* NOCONTEXT */ |
|
616 | 2817 |
int ret; |
2818 |
||
2819 |
if (__isString(aPathName)) { |
|
2820 |
__BEGIN_INTERRUPTABLE__ |
|
2821 |
do { |
|
2822 |
ret = access(_stringVal(aPathName), R_OK); |
|
2823 |
} while ((ret < 0) && (errno == EINTR)); |
|
2824 |
__END_INTERRUPTABLE__ |
|
2825 |
if (ret < 0) { |
|
2826 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2827 |
} |
|
710 | 2828 |
RETURN ( ((ret == 0) ? true : false) ); |
616 | 2829 |
} |
2830 |
%}. |
|
792 | 2831 |
^ self primitiveFailed |
68 | 2832 |
! |
2833 |
||
616 | 2834 |
isSymbolicLink:aPathName |
2835 |
"return true, if the given file is a symbolic link" |
|
2836 |
||
2837 |
^ (self linkInfoOf:aPathName) notNil |
|
2838 |
||
2839 |
" |
|
2840 |
OperatingSystem isSymbolicLink:'Make.proto' |
|
2841 |
OperatingSystem isSymbolicLink:'Makefile' |
|
2842 |
" |
|
2843 |
! |
|
2844 |
||
2845 |
isValidPath:aPathName |
|
2846 |
"return true, if 'aPathName' is a valid path name |
|
2847 |
(i.e. the file or directory exists)" |
|
68 | 2848 |
|
2849 |
%{ /* NOCONTEXT */ |
|
616 | 2850 |
|
2851 |
struct stat buf; |
|
2852 |
int ret; |
|
2853 |
||
2854 |
if (__isString(aPathName) || __isSymbol(aPathName) ) { |
|
2855 |
__BEGIN_INTERRUPTABLE__ |
|
2856 |
do { |
|
2857 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2858 |
} while ((ret < 0) && (errno == EINTR)); |
|
2859 |
__END_INTERRUPTABLE__ |
|
2860 |
if (ret < 0) { |
|
2861 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2862 |
RETURN (false); |
|
2863 |
} |
|
2864 |
RETURN ( ret ? false : true ); |
|
2865 |
} |
|
792 | 2866 |
%}. |
2867 |
^ self primitiveFailed |
|
68 | 2868 |
! |
2869 |
||
616 | 2870 |
isWritable:aPathName |
2871 |
"return true, if the given file is writable" |
|
68 | 2872 |
|
2873 |
%{ /* NOCONTEXT */ |
|
616 | 2874 |
int ret; |
2875 |
||
2876 |
if (__isString(aPathName)) { |
|
2877 |
__BEGIN_INTERRUPTABLE__ |
|
2878 |
do { |
|
2879 |
ret = access(_stringVal(aPathName), W_OK); |
|
2880 |
} while ((ret < 0) && (errno == EINTR)); |
|
2881 |
__END_INTERRUPTABLE__ |
|
2882 |
if (ret < 0) { |
|
2883 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2884 |
} |
|
710 | 2885 |
RETURN ( ((ret == 0) ? true : false) ); |
616 | 2886 |
} |
2887 |
%}. |
|
792 | 2888 |
^ self primitiveFailed |
68 | 2889 |
! |
2890 |
||
616 | 2891 |
linkFile:oldPath to:newPath |
2892 |
"link the file 'oldPath' to 'newPath'. The link will be a hard link. |
|
2893 |
Return true if successful, false if not." |
|
68 | 2894 |
|
2895 |
%{ /* NOCONTEXT */ |
|
792 | 2896 |
#ifndef MSDOS_LIKE |
616 | 2897 |
int ret; |
2898 |
||
2899 |
if (__isString(oldPath) && __isString(newPath)) { |
|
2900 |
__BEGIN_INTERRUPTABLE__ |
|
2901 |
do { |
|
2902 |
ret = link((char *) _stringVal(oldPath), (char *) _stringVal(newPath)); |
|
2903 |
} while (ret < 0 && errno == EINTR); |
|
2904 |
__END_INTERRUPTABLE__ |
|
2905 |
RETURN ( (ret >= 0) ? true : false ); |
|
2906 |
} |
|
792 | 2907 |
#endif |
616 | 2908 |
%}. |
792 | 2909 |
^ self primitiveFailed |
616 | 2910 |
|
2911 |
"OperatingSystem linkFile:'foo' to:'bar'" |
|
68 | 2912 |
! |
2913 |
||
616 | 2914 |
linkInfoOf:aPathName |
2915 |
"return a dictionary filled with info for the file 'aPathName', |
|
2916 |
IFF aPathName is a symbolic link. If not, return nil. |
|
2917 |
The contents of the dictionary gives info about the link itself, |
|
2918 |
on contrast to #infoOf:, which returns the info of the pointed to file |
|
2919 |
in case of a symbolic link." |
|
2920 |
||
2921 |
|info type mode uid gid size id atimeLow atimeHi mtimeLow mtimeHi ctimeLow ctimeHi |
|
2922 |
path| |
|
2923 |
||
2924 |
%{ /* STACK: 1200 */ |
|
792 | 2925 |
#ifdef S_IFLNK |
616 | 2926 |
struct stat buf; |
2927 |
int ret; |
|
2928 |
char pathBuffer[1024]; |
|
2929 |
||
2930 |
if (__isString(aPathName)) { |
|
2931 |
__BEGIN_INTERRUPTABLE__ |
|
2932 |
do { |
|
2933 |
ret = lstat((char *) _stringVal(aPathName), &buf); |
|
2934 |
} while ((ret < 0) && (errno == EINTR)); |
|
2935 |
__END_INTERRUPTABLE__ |
|
2936 |
||
2937 |
if (ret < 0) { |
|
2938 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2939 |
RETURN ( nil ); |
|
2940 |
} |
|
2941 |
switch (buf.st_mode & S_IFMT) { |
|
2942 |
default: |
|
2943 |
RETURN ( nil ); /* not a symbolic link */ |
|
2944 |
||
2945 |
case S_IFLNK: |
|
2946 |
type = @symbol(symbolicLink); |
|
2947 |
break; |
|
2948 |
} |
|
2949 |
||
2950 |
mode = _MKSMALLINT(buf.st_mode & 0777); |
|
2951 |
uid = _MKSMALLINT(buf.st_uid); |
|
2952 |
gid = _MKSMALLINT(buf.st_gid); |
|
2953 |
size = _MKSMALLINT(buf.st_size); |
|
2954 |
id = _MKSMALLINT(buf.st_ino); |
|
2955 |
atimeLow = _MKSMALLINT(buf.st_atime & 0xFFFF); |
|
2956 |
atimeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF); |
|
2957 |
mtimeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF); |
|
2958 |
mtimeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF); |
|
2959 |
ctimeLow = _MKSMALLINT(buf.st_ctime & 0xFFFF); |
|
2960 |
ctimeHi = _MKSMALLINT((buf.st_ctime >> 16) & 0xFFFF); |
|
2961 |
if ((ret = readlink((char *) _stringVal(aPathName), pathBuffer, sizeof(pathBuffer))) < 0) { |
|
2962 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2963 |
RETURN ( nil ); |
|
2964 |
} |
|
2965 |
pathBuffer[ret] = '\0'; /* readlink does not 0-terminate */ |
|
830 | 2966 |
path = __MKSTRING(pathBuffer COMMA_CON); |
616 | 2967 |
} |
792 | 2968 |
#else |
2969 |
RETURN ( nil ); |
|
2970 |
#endif |
|
616 | 2971 |
%}. |
2972 |
mode notNil ifTrue:[ |
|
2973 |
info := IdentityDictionary new. |
|
2974 |
info at:#type put:type. |
|
2975 |
info at:#mode put:mode. |
|
2976 |
info at:#uid put:uid. |
|
2977 |
info at:#gid put:gid. |
|
2978 |
info at:#size put:size. |
|
2979 |
info at:#id put:id. |
|
2980 |
info at:#path put:path. |
|
2981 |
info at:#accessed put:(AbsoluteTime fromOSTimeLow:atimeLow and:atimeHi). |
|
2982 |
info at:#modified put:(AbsoluteTime fromOSTimeLow:mtimeLow and:mtimeHi). |
|
2983 |
info at:#statusChanged put:(AbsoluteTime fromOSTimeLow:ctimeLow and:ctimeHi). |
|
2984 |
^ info |
|
2985 |
]. |
|
792 | 2986 |
^ self primitiveFailed |
616 | 2987 |
|
2988 |
" |
|
2989 |
OperatingSystem infoOf:'Make.proto' |
|
2990 |
OperatingSystem linkInfoOf:'Make.proto' |
|
2991 |
" |
|
2992 |
! |
|
2993 |
||
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2994 |
makePipe |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2995 |
"make a pipe, return array with two filedescriptors on success, |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2996 |
nil on failure" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2997 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2998 |
|fd1 fd2| |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
2999 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3000 |
%{ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3001 |
int fds[2]; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3002 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3003 |
if (pipe(fds) < 0) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3004 |
RETURN(nil); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3005 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3006 |
fd1 = __MKSMALLINT(fds[0]); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3007 |
fd2 = __MKSMALLINT(fds[1]); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3008 |
%}. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3009 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3010 |
^ Array with:fd1 with:fd2. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3011 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3012 |
|
616 | 3013 |
parentDirectoryName |
3014 |
"return the name used to refer to parent directories. |
|
3015 |
In MSDOS, Unix and other systems this is '..', but maybe different |
|
3016 |
for other systems. |
|
3017 |
(but those are currently not supported - so this is some |
|
3018 |
preparation for the future)" |
|
3019 |
||
3020 |
^ '..' |
|
68 | 3021 |
! |
3022 |
||
616 | 3023 |
pathNameOf:pathName |
3024 |
"return the pathName of the argument, aPathString, |
|
3025 |
- thats the full pathname of the directory, starting at '/'. |
|
3026 |
This method needs the path to be valid |
|
3027 |
(i.e. all directories must exist, be readable and executable). |
|
3028 |
Notice: if symbolic links are involved, the result may look different |
|
3029 |
from what you expect." |
|
3030 |
||
3031 |
|p path command| |
|
3032 |
||
3033 |
"some systems have a convenient function for this ..." |
|
3034 |
path := self primPathNameOf:pathName. |
|
3035 |
||
3036 |
path isNil ifTrue:[ |
|
3037 |
(self isValidPath:pathName) ifFalse:[^ pathName]. |
|
3038 |
||
3039 |
(SlowFork==true or:[ForkFailed]) ifFalse:[ |
|
3040 |
PipeStream openErrorSignal handle:[:ex | |
|
3041 |
ForkFailed := true. |
|
3042 |
'OS: cannot fork/popen' errorPrintNL. |
|
3043 |
ex return. |
|
3044 |
] do:[ |
|
3045 |
"have to fall back ..." |
|
3046 |
command := 'cd ' , pathName , '; pwd'. |
|
3047 |
p := PipeStream readingFrom:command. |
|
3048 |
]. |
|
3049 |
||
3050 |
(p isNil or:[p atEnd]) ifTrue:[ |
|
3051 |
('OS: PipeStream for <' , command , '> failed') errorPrintNL. |
|
3052 |
] ifFalse:[ |
|
3053 |
path := p nextLine. |
|
3054 |
p close. |
|
3055 |
]. |
|
3056 |
]. |
|
3057 |
path isNil ifTrue:[ |
|
3058 |
path := pathName |
|
3059 |
]. |
|
3060 |
(SlowFork==true or:[ForkFailed]) ifTrue:[ |
|
3061 |
path := self compressPath:path |
|
3062 |
] |
|
3063 |
]. |
|
3064 |
^ path. |
|
3065 |
||
3066 |
" |
|
3067 |
OperatingSystem pathNameOf:'.' |
|
3068 |
OperatingSystem pathNameOf:'../smalltalk/../smalltalk' |
|
3069 |
OperatingSystem pathNameOf:'../../..' |
|
3070 |
OperatingSystem pathNameOf:'..' |
|
3071 |
" |
|
359 | 3072 |
! |
3073 |
||
616 | 3074 |
primPathNameOf:pathName |
3075 |
"return the pathName of the argument, aPathString, |
|
3076 |
- thats the full pathname of the directory, starting at '/'. |
|
3077 |
This method here returns nil, if the OS does not provide a |
|
3078 |
realPath library function. |
|
3079 |
Notice: if symbolic links are involved, the result may look different |
|
3080 |
from what you expect." |
|
3081 |
||
3082 |
|path| |
|
3083 |
||
3084 |
"some systems have a convenient function for this ..." |
|
3085 |
%{ /* STACK: 16000 */ |
|
3086 |
#ifdef HAS_REALPATH |
|
3087 |
char nameBuffer[MAXPATHLEN + 1]; |
|
3088 |
||
3089 |
if (__isString(pathName)) { |
|
3090 |
if (realpath(_stringVal(pathName), nameBuffer)) { |
|
830 | 3091 |
RETURN ( __MKSTRING(nameBuffer COMMA_CON) ); |
616 | 3092 |
} |
3093 |
} |
|
3094 |
#endif |
|
3095 |
%}. |
|
3096 |
^ nil |
|
359 | 3097 |
! |
3098 |
||
616 | 3099 |
recursiveCreateDirectory:dirName |
3100 |
"create a directory - with all parent dirs if needed. |
|
3101 |
Return true if successful, false otherwise. If false |
|
3102 |
is returned, a partial created tree may be left, |
|
3103 |
which is not cleaned-up here." |
|
3104 |
||
3105 |
self createDirectory:dirName. |
|
3106 |
(self isDirectory:dirName) ifFalse:[ |
|
3107 |
(self recursiveCreateDirectory:(self directoryNameOf:dirName)) ifFalse:[^ false]. |
|
3108 |
^ self createDirectory:dirName |
|
3109 |
]. |
|
3110 |
^ true |
|
3111 |
||
3112 |
"OperatingSystem recursiveCreateDirectory:'foo/bar/baz'" |
|
359 | 3113 |
! |
3114 |
||
616 | 3115 |
recursiveRemoveDirectory:fullPathName |
3116 |
"remove the directory named 'fullPathName' and all contained files/directories. |
|
3117 |
Return true if successful." |
|
3118 |
||
3119 |
^ self executeCommand:('rm -rf ' , fullPathName) |
|
3120 |
! |
|
3121 |
||
3122 |
removeDirectory:fullPathName |
|
3123 |
"remove the directory named 'fullPathName'. |
|
3124 |
Return true if successful, false if directory is not empty or no permission" |
|
359 | 3125 |
|
3126 |
%{ /* NOCONTEXT */ |
|
616 | 3127 |
int ret; |
3128 |
||
3129 |
if (__isString(fullPathName)) { |
|
3130 |
__BEGIN_INTERRUPTABLE__ |
|
3131 |
do { |
|
3132 |
ret = rmdir((char *) _stringVal(fullPathName)); |
|
3133 |
} while (ret < 0 && errno == EINTR); |
|
3134 |
__END_INTERRUPTABLE__ |
|
3135 |
RETURN ( (ret >= 0) ? true : false ); |
|
3136 |
} |
|
3137 |
%}. |
|
792 | 3138 |
^ self primitiveFailed |
359 | 3139 |
! |
3140 |
||
616 | 3141 |
removeFile:fullPathName |
3142 |
"remove the file named 'fullPathName'; return true if successful" |
|
359 | 3143 |
|
3144 |
%{ /* NOCONTEXT */ |
|
616 | 3145 |
int ret; |
3146 |
||
3147 |
if (__isString(fullPathName)) { |
|
3148 |
__BEGIN_INTERRUPTABLE__ |
|
3149 |
do { |
|
3150 |
ret = unlink((char *) _stringVal(fullPathName)); |
|
3151 |
} while (ret < 0 && errno == EINTR); |
|
3152 |
__END_INTERRUPTABLE__ |
|
3153 |
RETURN ( (ret >= 0) ? true : false ); |
|
3154 |
} |
|
3155 |
%}. |
|
792 | 3156 |
^ self primitiveFailed |
359 | 3157 |
! |
3158 |
||
616 | 3159 |
renameFile:oldPath to:newPath |
3160 |
"rename the file 'oldPath' to 'newPath'. |
|
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
3161 |
Return true if successful, false if not" |
359 | 3162 |
|
3163 |
%{ /* NOCONTEXT */ |
|
616 | 3164 |
int ret; |
3165 |
||
3166 |
if (__isString(oldPath) && __isString(newPath)) { |
|
3167 |
#if defined(HAS_RENAME) |
|
3168 |
__BEGIN_INTERRUPTABLE__ |
|
3169 |
do { |
|
3170 |
ret = rename((char *) _stringVal(oldPath), (char *) _stringVal(newPath)); |
|
3171 |
} while (ret < 0 && errno == EINTR); |
|
3172 |
__END_INTERRUPTABLE__ |
|
3173 |
RETURN ( (ret >= 0) ? true : false ); |
|
359 | 3174 |
#else |
792 | 3175 |
# ifndef MSDOS_LIKE |
616 | 3176 |
if (link((char *) _stringVal(oldPath), (char *) _stringVal(newPath)) >= 0) { |
3177 |
if (unlink((char *) _stringVal(oldPath)) >= 0) { |
|
3178 |
RETURN ( true ); |
|
3179 |
} |
|
3180 |
unlink((char *) _stringVal(newPath)); |
|
3181 |
} |
|
792 | 3182 |
# endif |
616 | 3183 |
#endif |
3184 |
RETURN ( false ); |
|
3185 |
} |
|
792 | 3186 |
%}. |
3187 |
^ self primitiveFailed |
|
616 | 3188 |
|
3189 |
"OperatingSystem renameFile:'foo' to:'bar'" |
|
3190 |
! |
|
3191 |
||
3192 |
timeOfLastAccess:aPathName |
|
3193 |
"return the time, when the file was last accessed. |
|
3194 |
For nonexistent files, nil is returned." |
|
3195 |
||
3196 |
"could be implemented as: |
|
3197 |
(self infoOf:aPathName) at:#accessed |
|
3198 |
" |
|
3199 |
|timeLow timeHi| |
|
3200 |
%{ |
|
3201 |
struct stat buf; |
|
3202 |
time_t mtime; |
|
3203 |
int ret; |
|
3204 |
||
3205 |
if (__isString(aPathName)) { |
|
3206 |
__BEGIN_INTERRUPTABLE__ |
|
3207 |
do { |
|
3208 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
3209 |
} while (ret < 0 && errno == EINTR); |
|
3210 |
__END_INTERRUPTABLE__ |
|
3211 |
if (ret < 0) { |
|
3212 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
3213 |
RETURN (nil); |
|
3214 |
} |
|
3215 |
timeLow = _MKSMALLINT(buf.st_atime & 0xFFFF); |
|
3216 |
timeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF); |
|
3217 |
} |
|
792 | 3218 |
%}. |
616 | 3219 |
timeLow notNil ifTrue:[^ AbsoluteTime fromOSTimeLow:timeLow and:timeHi]. |
792 | 3220 |
^ self primitiveFailed |
616 | 3221 |
|
3222 |
" |
|
3223 |
OperatingSystem timeOfLastAccess:'/' |
|
3224 |
" |
|
359 | 3225 |
! |
3226 |
||
616 | 3227 |
timeOfLastChange:aPathName |
3228 |
"return the time, when the file was last changed. |
|
3229 |
For nonexistent files, nil is returned." |
|
3230 |
||
3231 |
"could be implemented as: |
|
3232 |
(self infoOf:aPathName) at:#modified |
|
3233 |
" |
|
3234 |
||
3235 |
|timeLow timeHi| |
|
3236 |
%{ |
|
3237 |
struct stat buf; |
|
3238 |
int ret; |
|
3239 |
time_t mtime; |
|
3240 |
||
3241 |
if (__isString(aPathName)) { |
|
3242 |
__BEGIN_INTERRUPTABLE__ |
|
3243 |
do { |
|
3244 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
3245 |
} while (ret < 0 && errno == EINTR); |
|
3246 |
__END_INTERRUPTABLE__ |
|
3247 |
if (ret < 0) { |
|
3248 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
3249 |
RETURN ( nil ); |
|
3250 |
} |
|
3251 |
timeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF); |
|
3252 |
timeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF); |
|
3253 |
} |
|
792 | 3254 |
%}. |
616 | 3255 |
timeLow notNil ifTrue:[^ AbsoluteTime fromOSTimeLow:timeLow and:timeHi]. |
792 | 3256 |
^ self primitiveFailed |
616 | 3257 |
|
3258 |
" |
|
3259 |
OperatingSystem timeOfLastChange:'/' |
|
3260 |
" |
|
3261 |
! |
|
3262 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3263 |
truncateFile:aPathName to:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3264 |
"change a files size return true on success, false on failure. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3265 |
This may not be supported on all architectures." |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3266 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3267 |
%{ /* NOCONTEXT */ |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3268 |
#ifdef HAS_FTRUNCATE |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3269 |
int ret; |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3270 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3271 |
if (__isString(aPathName) |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3272 |
&& __isSmallInteger(newSize)) { |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3273 |
__BEGIN_INTERRUPTABLE__ |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3274 |
do { |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3275 |
ret = truncate((char *) _stringVal(aPathName), __intVal(newSize)); |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3276 |
} while (ret < 0 && errno == EINTR); |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3277 |
__END_INTERRUPTABLE__ |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3278 |
if (ret < 0) { |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3279 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3280 |
RETURN ( false ); |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3281 |
} |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3282 |
RETURN (true); |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3283 |
} |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3284 |
#endif |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3285 |
%}. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3286 |
^ self primitiveFailed |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3287 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
3288 |
|
616 | 3289 |
typeOf:aPathName |
3290 |
"return the type of a file as a symbol" |
|
3291 |
||
3292 |
" |
|
3293 |
this could have been implemented as: |
|
3294 |
(self infoOf:aPathName) at:#type |
|
3295 |
but for huge directory searches the code below is faster |
|
3296 |
" |
|
359 | 3297 |
|
3298 |
%{ /* NOCONTEXT */ |
|
616 | 3299 |
|
3300 |
struct stat buf; |
|
3301 |
int ret; |
|
3302 |
||
3303 |
if (__isString(aPathName)) { |
|
3304 |
__BEGIN_INTERRUPTABLE__ |
|
3305 |
do { |
|
3306 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
3307 |
} while (ret < 0 && errno == EINTR); |
|
3308 |
__END_INTERRUPTABLE__ |
|
3309 |
if (ret < 0) { |
|
3310 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
3311 |
RETURN ( nil ); |
|
3312 |
} |
|
3313 |
switch (buf.st_mode & S_IFMT) { |
|
3314 |
case S_IFDIR: |
|
3315 |
RETURN ( @symbol(directory) ); |
|
3316 |
case S_IFREG: |
|
3317 |
RETURN ( @symbol(regular) ); |
|
3318 |
#ifdef S_IFCHR |
|
3319 |
case S_IFCHR: |
|
3320 |
RETURN ( @symbol(characterSpecial) ); |
|
3321 |
#endif |
|
3322 |
#ifdef S_IFBLK |
|
3323 |
case S_IFBLK: |
|
3324 |
RETURN ( @symbol(blockSpecial) ); |
|
3325 |
#endif |
|
3326 |
#ifdef S_IFLNK |
|
3327 |
case S_IFLNK: |
|
3328 |
RETURN ( @symbol(symbolicLink) ); |
|
3329 |
#endif |
|
3330 |
#ifdef S_IFSOCK |
|
3331 |
case S_IFSOCK: |
|
3332 |
RETURN ( @symbol(socket) ); |
|
3333 |
#endif |
|
3334 |
#ifdef S_IFIFO |
|
3335 |
case S_IFIFO: |
|
3336 |
RETURN ( @symbol(fifo) ); |
|
3337 |
#endif |
|
3338 |
default: |
|
3339 |
RETURN ( @symbol(unknown) ); |
|
3340 |
} |
|
3341 |
} |
|
3342 |
%}. |
|
792 | 3343 |
^ self primitiveFailed |
616 | 3344 |
|
3345 |
" |
|
3346 |
OperatingSystem typeOf:'/' |
|
3347 |
OperatingSystem typeOf:'.' |
|
3348 |
OperatingSystem typeOf:'Make.proto' |
|
3349 |
" |
|
68 | 3350 |
! ! |
3351 |
||
63 | 3352 |
!OperatingSystem class methodsFor:'interrupts & signals'! |
3353 |
||
10 | 3354 |
blockInterrupts |
95 | 3355 |
"disable interrupt processing - if disabled, incoming |
3356 |
interrupts will be registered and handled as soon as |
|
3357 |
interrupts are reenabled by OperatingSystemclass>>unblockInterrupts. |
|
3358 |
Returns the previous blocking status i.e. true if interrupts |
|
3359 |
where already blocked. You need this information for proper |
|
3360 |
unblocking, in case of nested block/unblock calls." |
|
3361 |
||
3362 |
%{ /* NOCONTEXT */ |
|
710 | 3363 |
RETURN ( __BLOCKINTERRUPTS() ); |
10 | 3364 |
%} |
3365 |
! |
|
3366 |
||
616 | 3367 |
defaultSignal:signalNumber |
3368 |
"revert to the default action on arrival of a (Unix-)signal. |
|
3369 |
Dont confuse Unix signals with smalltalk signals. |
|
3370 |
WARNING: for some signals, it is no good idea to revert to default; |
|
3371 |
for example, the default for SIGINT (i.e. ^C) is to exit; while the |
|
3372 |
default for SIGQUIT (^ \) is to dump core. |
|
3373 |
Also, NOTICE that signal numbers are not portable between unix |
|
3374 |
systems - use OperatingSystem sigXXX to get the numeric value for |
|
3375 |
a signal." |
|
3376 |
||
3377 |
%{ /* NOCONTEXT */ |
|
3378 |
||
3379 |
if (__isSmallInteger(signalNumber)) { |
|
831 | 3380 |
#ifdef SIG_DFL |
616 | 3381 |
signal(_intVal(signalNumber), SIG_DFL); |
3382 |
RETURN (self); |
|
831 | 3383 |
#endif |
616 | 3384 |
} |
3385 |
%}. |
|
3386 |
" |
|
3387 |
this error is triggered on non-integer argument |
|
3388 |
" |
|
792 | 3389 |
^ self primitiveFailed |
616 | 3390 |
|
3391 |
"you better save a snapshot image before trying this ..." |
|
3392 |
" |
|
3393 |
'if you hit ^C now, Smalltalk will exit immediately' printNewline. |
|
3394 |
OperatingSystem defaultSignal:(OperatingSystem sigINT). |
|
3395 |
1 to:1000000 do:[:i| ]. |
|
3396 |
OperatingSystem enableSignal:(OperatingSystem sigINT). |
|
3397 |
'normal ^C handling again.' printNewline |
|
3398 |
" |
|
3399 |
! |
|
3400 |
||
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3401 |
disableChildSignalInterrupts |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3402 |
"disable childSignal interrupts |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3403 |
(SIGCHLD, if the architecture supports it). |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3404 |
We have to set the signal back to default, because ignoring |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3405 |
SIGCHLD breaks wait & co" |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3406 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3407 |
^ self defaultSignal:(self sigCHLD) |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3408 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3409 |
"Created: 5.1.1996 / 15:45:28 / stefan" |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3410 |
! |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
3411 |
|
616 | 3412 |
disableIOInterruptsOn:fd |
3413 |
"turn off IO interrupts for a filedescriptor" |
|
3414 |
||
3415 |
%{ /* NOCONTEXT */ |
|
3416 |
||
3417 |
int ret, flags, f; |
|
3418 |
||
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3419 |
#if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4) |
616 | 3420 |
if (__isSmallInteger(fd)) { |
3421 |
f = _intVal(fd); |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3422 |
# if defined(SYSV4) |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
3423 |
ret = ioctl(f, I_SETSIG, 0); |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3424 |
# else /*! SYSV4*/ |
616 | 3425 |
flags = fcntl(f, F_GETFL, 0); |
3426 |
/* |
|
3427 |
* if already clear, there is no need for this syscall ... |
|
3428 |
*/ |
|
3429 |
if (flags & FASYNC) { |
|
3430 |
ret = fcntl(f, F_SETFL, flags & ~FASYNC); |
|
3431 |
if (ret >= 0) ret = flags; |
|
3432 |
} else { |
|
3433 |
ret = flags; |
|
3434 |
} |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3435 |
# endif /* !SYSV4 */ |
616 | 3436 |
RETURN ( _MKSMALLINT(ret) ); |
3437 |
} |
|
3438 |
#endif |
|
3439 |
%}. |
|
3440 |
" |
|
3441 |
this error is triggered on non-integer argument |
|
3442 |
or if the OS does not support IO interrupts. |
|
3443 |
" |
|
792 | 3444 |
^ self primitiveFailed |
10 | 3445 |
! |
3446 |
||
63 | 3447 |
disableSignal:signalNumber |
95 | 3448 |
"disable (Unix-) signal processing for signalNumber. |
3449 |
Dont confuse Unix signals with smalltalk signals. |
|
63 | 3450 |
WARNING: for some signals, it is no good idea to disable |
95 | 3451 |
them; for example, disabling the SIGINT signal turns off ^C |
63 | 3452 |
handling. |
68 | 3453 |
Also, NOTICE that signal numbers are not portable between unix |
3454 |
systems - use OperatingSystem sigXXX to get the numeric value for |
|
3455 |
a signal. |
|
63 | 3456 |
Use only for fully debugged stand alone applications." |
3457 |
||
3458 |
%{ /* NOCONTEXT */ |
|
3459 |
||
252 | 3460 |
if (__isSmallInteger(signalNumber)) { |
831 | 3461 |
int sigNo = __intVal(signalNumber); |
3462 |
||
3463 |
if (sigNo == 0) { |
|
3464 |
RETURN (self); |
|
3465 |
} |
|
3466 |
#ifdef SIG_IGN |
|
3467 |
signal(sigNo, SIG_IGN); |
|
185 | 3468 |
RETURN (self); |
831 | 3469 |
#endif |
63 | 3470 |
} |
68 | 3471 |
%}. |
3472 |
" |
|
3473 |
this error is triggered on non-integer argument |
|
3474 |
" |
|
792 | 3475 |
^ self primitiveFailed |
68 | 3476 |
|
3477 |
" |
|
3478 |
'now, ^C is totally ignored ...' printNewline. |
|
3479 |
OperatingSystem disableSignal:(OperatingSystem sigINT). |
|
3480 |
1 to:1000000 do:[:i| ]. |
|
3481 |
OperatingSystem enableSignal:(OperatingSystem sigINT). |
|
3482 |
'^C handled again.' printNewline |
|
3483 |
" |
|
3484 |
! |
|
3485 |
||
616 | 3486 |
disableTimer |
831 | 3487 |
"disable timer interrupts. |
3488 |
WARNING: |
|
3489 |
the system will not operate correctly with timer interrupts |
|
3490 |
disabled, because no scheduling or timeouts are possible." |
|
616 | 3491 |
|
3492 |
%{ /* NOCONTEXT */ |
|
3493 |
||
3494 |
#if defined(ITIMER_REAL) |
|
3495 |
struct itimerval dt; |
|
3496 |
||
3497 |
dt.it_interval.tv_sec = 0; |
|
3498 |
dt.it_interval.tv_usec = 0; |
|
3499 |
dt.it_value.tv_sec = 0; |
|
3500 |
dt.it_value.tv_usec = 0; |
|
3501 |
setitimer(ITIMER_REAL, &dt, 0); |
|
3502 |
RETURN (true); |
|
831 | 3503 |
#endif /* ITIMER_REAL */ |
616 | 3504 |
%} |
3505 |
. |
|
3506 |
^ false |
|
3507 |
! |
|
3508 |
||
3509 |
disableUserInterrupts |
|
3510 |
"disable userInterrupt processing; |
|
3511 |
when disabled, no ^C processing takes place. |
|
831 | 3512 |
WARNING: |
3513 |
If at all, use this only for debugged stand-alone applications, since |
|
3514 |
no exit to the debugger is possible with user interrupts disabled. |
|
3515 |
We recommend setting up a handler for the signal instead of disabling it." |
|
3516 |
||
3517 |
self disableSignal:(self sigBREAK). |
|
3518 |
self disableSignal:(self sigINT). |
|
616 | 3519 |
! |
3520 |
||
3521 |
enableAbortInterrupts |
|
3522 |
"enable abort signalhandling, and make it a regular signalInterrupt. |
|
3523 |
(the default will dump core and exit - which is not a good idea for |
|
3524 |
end-user applications ...). |
|
3525 |
This is especially useful, if linked-in C-libraries call abort() ..." |
|
3526 |
||
831 | 3527 |
self enableSignal:(self sigABRT) |
616 | 3528 |
! |
3529 |
||
3530 |
enableChildSignalInterrupts |
|
3531 |
"enable childSignal interrupts |
|
3532 |
(SIGCHLD, if the architecture supports it). |
|
831 | 3533 |
After enabling, these signals will send the message |
616 | 3534 |
'childSignalInterrupt' to the ChildSignalInterruptHandler object." |
3535 |
||
831 | 3536 |
self enableSignal:(self sigCHLD) |
616 | 3537 |
! |
3538 |
||
3539 |
enableFpExceptionInterrupts |
|
3540 |
"enable floating point exception interrupts (if the |
|
3541 |
architecture supports it). |
|
831 | 3542 |
After enabling, fpu-exceptions will send the message |
616 | 3543 |
'fpuExceptionInterrupt' to the FPUExceptionInterruptHandler object." |
3544 |
||
831 | 3545 |
self enableSignal:(self sigFP) |
616 | 3546 |
! |
3547 |
||
3548 |
enableHardSignalInterrupts |
|
3549 |
"enable hard signal exception interrupts (trap, buserror & segm. violation). |
|
831 | 3550 |
After enabling, these exceptions will send the message |
616 | 3551 |
'signalInterrupt' to the SignalInterruptHandler object." |
68 | 3552 |
|
855
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
3553 |
"/ leads to trouble ... |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
3554 |
"/ self enableSignal:(self sigPIPE). |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
3555 |
|
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
3556 |
"/ ... better to ignore them, and let it be handled as a writeErrorSignal. |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
3557 |
self disableSignal:(self sigPIPE). |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
3558 |
|
640
be94dfc60eaa
Anforderung von SA_SIGINFO in sigaction.
Stefan Vogel <sv@exept.de>
parents:
630
diff
changeset
|
3559 |
self enableSignal:(self sigBUS). |
be94dfc60eaa
Anforderung von SA_SIGINFO in sigaction.
Stefan Vogel <sv@exept.de>
parents:
630
diff
changeset
|
3560 |
self enableSignal:(self sigSEGV) |
616 | 3561 |
! |
3562 |
||
3563 |
enableIOInterruptsOn:fd |
|
3564 |
"turn on IO interrupts for a filedescriptor" |
|
3565 |
||
3566 |
%{ /* NOCONTEXT */ |
|
3567 |
||
3568 |
int ret, flags, f; |
|
3569 |
extern void __signalIoInterrupt(); |
|
3570 |
static int firstCall = 1; |
|
3571 |
||
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3572 |
#if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3573 |
/* |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3574 |
* SIGIO/SIGPOLL - data available for I/O |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3575 |
* (used to wake up waiting processes) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3576 |
*/ |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3577 |
#ifdef SIGIO |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3578 |
# define THESIGNAL SIGIO |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3579 |
#else |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3580 |
# ifdef SIGPOLL |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3581 |
# define THESIGNAL SIGPOLL |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3582 |
# else |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3583 |
# ifdef SIGURG |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3584 |
# define THESIGNAL SIGURG |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3585 |
# endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3586 |
# endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3587 |
#endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3588 |
|
616 | 3589 |
if (__isSmallInteger(fd)) { |
3590 |
if (firstCall) { |
|
762
cea705669628
ok, stefan was right: HAS_SIGACTION works
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
3591 |
#ifdef HAS_SIGACTION |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3592 |
struct sigaction act; |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3593 |
|
763
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
3594 |
act.sa_flags = SA_RESTART | SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3595 |
sigemptyset(&act.sa_mask); |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3596 |
act.sa_handler = __signalIoInterrupt; |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3597 |
sigaction(THESIGNAL, &act, 0); |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3598 |
#else |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3599 |
# ifdef HAS_SIGVEC |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3600 |
struct sigvec vec; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3601 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3602 |
vec.sv_flags = 0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3603 |
sigemptyset(&vec.sv_mask); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3604 |
vec.sv_handler = __signalIoInterrupt; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3605 |
sigvec(THESIGNAL, &vec, NULL); |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3606 |
# else |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3607 |
signal(THESIGNAL, __signalIoInterrupt); |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3608 |
# endif |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3609 |
#endif |
616 | 3610 |
firstCall = 0; |
3611 |
} |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3612 |
#undef THESIGNAL |
616 | 3613 |
|
3614 |
f = _intVal(fd); |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3615 |
# if defined(SYSV4) |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
3616 |
ret = ioctl(f, I_SETSIG, S_INPUT | S_HIPRI | S_ERROR | S_RDNORM | S_RDBAND | S_MSG | S_HANGUP); |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3617 |
# else /*! SYSV4*/ |
616 | 3618 |
flags = fcntl(f, F_GETFL, 0); |
3619 |
/* |
|
3620 |
* if already set, there is no need for this syscall ... |
|
3621 |
*/ |
|
3622 |
if (flags & FASYNC) { |
|
3623 |
ret = flags; |
|
3624 |
} else { |
|
3625 |
ret = fcntl(f, F_SETFL, flags | FASYNC); |
|
3626 |
if (ret >= 0) ret = flags; |
|
3627 |
} |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3628 |
# endif /*!SYSV4*/ |
616 | 3629 |
RETURN ( _MKSMALLINT(ret) ); |
68 | 3630 |
} |
616 | 3631 |
#endif |
68 | 3632 |
%}. |
3633 |
" |
|
3634 |
this error is triggered on non-integer argument |
|
616 | 3635 |
or if the system does not support SIGIO |
68 | 3636 |
" |
792 | 3637 |
^ self primitiveFailed |
616 | 3638 |
! |
3639 |
||
3640 |
enableQuitInterrupts |
|
3641 |
"enable quitInterrupt (usually ^\) handling, and make it a userInterrupt. |
|
3642 |
(the default will dump core and exit - which is not a good idea for |
|
3643 |
end-user applications ...)" |
|
3644 |
||
831 | 3645 |
self enableSignal:(self sigQUIT) |
68 | 3646 |
! |
3647 |
||
3648 |
enableSignal:signalNumber |
|
95 | 3649 |
"enable (Unix-)signal processing for signalNumber. |
3650 |
Dont confuse Unix signals with smalltalk signals. |
|
68 | 3651 |
The signal will be delivered to one of the standard handlers |
3652 |
(SIGINT, SIGQUIT, etc) or to a general handler, which |
|
3653 |
sends #signalInterrupt:. |
|
3654 |
||
3655 |
NOTICE that signal numbers are not portable between unix |
|
3656 |
systems - use OperatingSystem sigXXX to get the numeric value for |
|
3657 |
a signal." |
|
3658 |
||
3659 |
%{ /* NOCONTEXT */ |
|
3660 |
||
3661 |
#ifdef NSIG |
|
3662 |
# define SIG_LIMIT NSIG |
|
3663 |
#else |
|
3664 |
# ifdef SIGUSR2 |
|
3665 |
# define SIG_LIMIT SIGUSR2 |
|
3666 |
# else |
|
3667 |
# ifdef SIGUSR |
|
3668 |
# define SIG_LIMIT SIGUSR |
|
3669 |
# endif |
|
3670 |
# endif |
|
3671 |
#endif |
|
3672 |
||
3673 |
#if defined(SIGPOLL) && !defined(SIGIO) |
|
3674 |
# define SIGIO SIGPOLL |
|
3675 |
#endif |
|
3676 |
||
3677 |
#ifdef SIGCHLD |
|
3678 |
# define CHILD_SIGNAL SIGCHLD |
|
3679 |
#else |
|
3680 |
# ifdef SIGCLD |
|
3681 |
# define CHILD_SIGNAL SIGCLD |
|
3682 |
# endif |
|
3683 |
#endif |
|
3684 |
||
3685 |
int sigNr; |
|
443 | 3686 |
#if defined(SIGINT) || defined(SIGQUIT) |
831 | 3687 |
extern void __signalUserInterrupt(SIGHANDLER_ARG); |
443 | 3688 |
#endif |
3689 |
#ifdef SIGFPE |
|
831 | 3690 |
extern void __signalFpExceptionInterrupt(SIGHANDLER_ARG); |
443 | 3691 |
#endif |
3692 |
#ifdef SIGIO |
|
831 | 3693 |
extern void __signalIoInterrupt(SIGHANDLER_ARG); |
443 | 3694 |
#endif |
68 | 3695 |
#ifdef CHILD_SIGNAL |
831 | 3696 |
extern void __signalChildInterrupt(SIGHANDLER_ARG); |
68 | 3697 |
#endif |
443 | 3698 |
#ifdef SIGPIPE |
831 | 3699 |
extern void __signalPIPEInterrupt(SIGHANDLER_ARG); |
443 | 3700 |
#endif |
3701 |
#ifdef SIGBUS |
|
831 | 3702 |
extern void __signalBUSInterrupt(SIGHANDLER_ARG); |
443 | 3703 |
#endif |
3704 |
#ifdef SIGSEGV |
|
831 | 3705 |
extern void __signalSEGVInterrupt(SIGHANDLER_ARG); |
443 | 3706 |
#endif |
3707 |
#ifdef SIGALRM |
|
831 | 3708 |
# ifndef WIN32 |
3709 |
extern void __signalTimerInterrupt(SIGHANDLER_ARG); |
|
3710 |
# endif |
|
3711 |
#endif |
|
3712 |
extern void __signalInterrupt(SIGHANDLER_ARG); |
|
3713 |
void (*handler)(SIGHANDLER_ARG); |
|
68 | 3714 |
|
252 | 3715 |
if (__isSmallInteger(signalNumber) |
831 | 3716 |
&& ((sigNr = _intVal(signalNumber)) >= 0) |
3717 |
#ifdef SIG_LIMIT |
|
3718 |
&& (sigNr <= SIG_LIMIT) |
|
3719 |
#endif |
|
3720 |
) { |
|
185 | 3721 |
/* |
3722 |
* standard signals are forced into standard handlers |
|
3723 |
* - all others go into general signalInterrupt |
|
3724 |
*/ |
|
68 | 3725 |
#if defined(SIGPOLL) && defined(SIGIO) |
185 | 3726 |
if (sigNr == SIGPOLL) |
3727 |
sigNr = SIGIO; |
|
68 | 3728 |
#endif |
185 | 3729 |
switch (sigNr) { |
831 | 3730 |
case 0: |
3731 |
/* enabling a non-supported signal */ |
|
3732 |
RETURN (self); |
|
3733 |
||
3734 |
#ifdef SIGBREAK |
|
3735 |
case SIGBREAK: |
|
3736 |
#endif |
|
443 | 3737 |
#ifdef SIGINT |
185 | 3738 |
case SIGINT: |
443 | 3739 |
#endif |
3740 |
#ifdef SIGQUIT |
|
185 | 3741 |
case SIGQUIT: |
443 | 3742 |
#endif |
831 | 3743 |
#if defined(SIGINT) || defined(SIGQUIT) || defined(SIGBREAK) |
329 | 3744 |
handler = __signalUserInterrupt; |
185 | 3745 |
break; |
443 | 3746 |
#endif |
3747 |
||
3748 |
#ifdef SIGFPE |
|
185 | 3749 |
case SIGFPE: |
329 | 3750 |
handler = __signalFpExceptionInterrupt; |
185 | 3751 |
break; |
443 | 3752 |
#endif |
3753 |
||
3754 |
#ifdef SIGPIPE |
|
185 | 3755 |
case SIGPIPE: |
329 | 3756 |
handler = __signalPIPEInterrupt; |
185 | 3757 |
break; |
443 | 3758 |
#endif |
68 | 3759 |
#ifdef SIGBUS |
185 | 3760 |
case SIGBUS: |
329 | 3761 |
handler = __signalBUSInterrupt; |
185 | 3762 |
break; |
68 | 3763 |
#endif |
443 | 3764 |
#ifdef SIGSEGV |
185 | 3765 |
case SIGSEGV: |
329 | 3766 |
handler = __signalSEGVInterrupt; |
185 | 3767 |
break; |
443 | 3768 |
#endif |
68 | 3769 |
#ifdef SIGIO |
185 | 3770 |
case SIGIO: |
329 | 3771 |
handler = __signalIoInterrupt; |
185 | 3772 |
break; |
68 | 3773 |
#endif |
3774 |
||
3775 |
#ifdef CHILD_SIGNAL |
|
185 | 3776 |
case CHILD_SIGNAL: |
329 | 3777 |
handler = __signalChildInterrupt; |
185 | 3778 |
break; |
68 | 3779 |
#endif |
443 | 3780 |
#ifdef SIGALRM |
831 | 3781 |
# ifndef WIN32 |
185 | 3782 |
case SIGALRM: |
329 | 3783 |
handler = __signalTimerInterrupt; |
185 | 3784 |
break; |
831 | 3785 |
# endif |
443 | 3786 |
#endif |
185 | 3787 |
|
3788 |
default: |
|
329 | 3789 |
handler = __signalInterrupt; |
185 | 3790 |
break; |
3791 |
} |
|
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3792 |
|
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3793 |
{ |
762
cea705669628
ok, stefan was right: HAS_SIGACTION works
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
3794 |
#ifdef HAS_SIGACTION |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3795 |
struct sigaction act; |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3796 |
|
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3797 |
act.sa_flags = SA_RESTART | SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3798 |
sigemptyset(&act.sa_mask); |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3799 |
act.sa_handler = handler; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3800 |
sigaction(sigNr, &act, 0); |
213 | 3801 |
#else |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3802 |
# ifdef HAS_SIGVEC |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3803 |
struct sigvec vec; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3804 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3805 |
vec.sv_flags = 0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3806 |
sigemptyset(&vec.sv_mask); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3807 |
vec.sv_handler = handler; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
3808 |
sigvec(sigNr, &vec, NULL); |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3809 |
# else |
831 | 3810 |
(void) signal(sigNr, handler); |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3811 |
# endif |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3812 |
#endif |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3813 |
} |
213 | 3814 |
|
185 | 3815 |
/* |
3816 |
* maybe, we should return the old enable-status |
|
3817 |
* as boolean here ... |
|
3818 |
*/ |
|
3819 |
RETURN (self); |
|
68 | 3820 |
} |
3821 |
%}. |
|
3822 |
||
3823 |
" |
|
3824 |
this error is triggered on non-integer argument, or |
|
3825 |
if the signal number is not in the valid range (1..NSIG) |
|
3826 |
" |
|
792 | 3827 |
^ self primitiveFailed |
63 | 3828 |
! |
3829 |
||
831 | 3830 |
enableTimer:milliSeconds |
616 | 3831 |
"trigger a timerInterrupt, to be signalled after some (real) time." |
3832 |
||
3833 |
%{ /* NOCONTEXT */ |
|
831 | 3834 |
int millis; |
3835 |
||
3836 |
millis = __intVal(milliSeconds); |
|
616 | 3837 |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3838 |
#if defined(ITIMER_REAL) |
831 | 3839 |
{ |
3840 |
static int firstCall = 1; |
|
3841 |
struct itimerval dt; |
|
832 | 3842 |
extern void __signalTimerInterrupt(SIGHANDLER_ARG); |
831 | 3843 |
|
3844 |
if (firstCall) { |
|
3845 |
# ifdef HAS_SIGACTION |
|
3846 |
struct sigaction act; |
|
3847 |
||
3848 |
act.sa_flags = SA_RESTART | SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
|
3849 |
sigemptyset(&act.sa_mask); |
|
3850 |
act.sa_handler = __signalTimerInterrupt; |
|
3851 |
sigaction(SIGALRM, &act, 0); |
|
3852 |
# else |
|
3853 |
# ifdef HAS_SIGVEC |
|
3854 |
struct sigvec vec; |
|
3855 |
||
3856 |
vec.sv_flags = 0; |
|
3857 |
sigemptyset(&vec.sv_mask); |
|
3858 |
vec.sv_handler = __signalTimerInterrupt; |
|
3859 |
sigvec(SIGALRM, &vec, NULL); |
|
3860 |
# else |
|
3861 |
signal(SIGALRM, __signalTimerInterrupt); |
|
3862 |
# endif |
|
3863 |
# endif |
|
3864 |
firstCall = 0; |
|
3865 |
} |
|
3866 |
||
3867 |
dt.it_interval.tv_sec = 0; |
|
3868 |
dt.it_interval.tv_usec = 0; |
|
3869 |
dt.it_value.tv_sec = millis / 1000; |
|
3870 |
dt.it_value.tv_usec = (millis % 1000) * 1000; |
|
3871 |
setitimer(ITIMER_REAL, &dt, 0); |
|
3872 |
RETURN (true); |
|
3873 |
} |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3874 |
#else |
831 | 3875 |
# ifdef WIN32 |
3876 |
{ |
|
3877 |
/* |
|
3878 |
* two mechanisms - which one to use ? |
|
3879 |
*/ |
|
3880 |
# define USE_TimerProc |
|
3881 |
# ifdef USE_TimerProc |
|
3882 |
||
3883 |
extern VOID CALLBACK __win32TimerProc(HWND, UINT, UINT, DWORD); |
|
3884 |
SetTimer(NULL, 0, millis, __win32TimerProc); |
|
3885 |
||
3886 |
# else /* USE_TimeProc */ |
|
3887 |
||
3888 |
extern void CALLBACK __win32TimeProc(UINT, UINT, DWORD, DWORD, DWORD, DWORD); |
|
3889 |
timeSetEvent(millis, 5, __win32TimeProc, 0, TIME_ONESHOT); |
|
3890 |
# endif |
|
640
be94dfc60eaa
Anforderung von SA_SIGINFO in sigaction.
Stefan Vogel <sv@exept.de>
parents:
630
diff
changeset
|
3891 |
} |
831 | 3892 |
# endif /* WIN32 */ |
3893 |
#endif /* ITIMER_REAL */ |
|
3894 |
%}. |
|
616 | 3895 |
^ false |
3896 |
! |
|
3897 |
||
1 | 3898 |
enableUserInterrupts |
3899 |
"enable userInterrupt (^C) handling; |
|
95 | 3900 |
when enabled, ^C in the terminal window will send the message |
3901 |
'userInterrupt' to the UserInterruptHandler object." |
|
1 | 3902 |
|
831 | 3903 |
self enableSignal:(self sigINT). |
3904 |
self enableSignal:(self sigBREAK). |
|
63 | 3905 |
! |
3906 |
||
616 | 3907 |
interruptPending |
3908 |
"return true, if an interrupt is pending. The returned value is |
|
3909 |
invalid if interrupts are not currently blocked, since otherwise |
|
3910 |
the interrupt is usually already handled before arriving here, |
|
3911 |
or may be served while returning from here." |
|
3912 |
||
3913 |
%{ /* NOCONTEXT */ |
|
3914 |
extern OBJ __INTERRUPTPENDING(); |
|
3915 |
||
3916 |
RETURN ( __INTERRUPTPENDING() ); |
|
3917 |
%} |
|
1 | 3918 |
! |
3919 |
||
704 | 3920 |
killProcess:processId |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3921 |
"kill a unix process. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3922 |
The process terminates immediately and has no chance to perform any cleanup actions" |
704 | 3923 |
|
3924 |
self sendSignal:(self sigKILL) to:processId. |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3925 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
3926 |
"Modified: 28.12.1995 / 15:06:18 / stefan" |
704 | 3927 |
! |
3928 |
||
616 | 3929 |
nameForSignal:aSignalNumber |
3930 |
"for a given Unix signalnumber, return a descriptive string" |
|
3931 |
||
3932 |
aSignalNumber == self sigHUP ifTrue:[^ 'hangup']. |
|
3933 |
aSignalNumber == self sigINT ifTrue:[^ 'interrupt']. |
|
3934 |
aSignalNumber == self sigKILL ifTrue:[^ 'kill']. |
|
3935 |
aSignalNumber == self sigQUIT ifTrue:[^ 'quit']. |
|
3936 |
aSignalNumber == self sigILL ifTrue:[^ 'illegal instruction']. |
|
3937 |
aSignalNumber == self sigTRAP ifTrue:[^ 'trap']. |
|
3938 |
aSignalNumber == self sigABRT ifTrue:[^ 'abort']. |
|
3939 |
aSignalNumber == self sigIOT ifTrue:[^ 'iot trap']. |
|
3940 |
aSignalNumber == self sigEMT ifTrue:[^ 'emt trap']. |
|
3941 |
aSignalNumber == self sigFP ifTrue:[^ 'fp exception']. |
|
3942 |
aSignalNumber == self sigBUS ifTrue:[^ 'bus error']. |
|
3943 |
aSignalNumber == self sigSEGV ifTrue:[^ 'segmentation violation']. |
|
3944 |
aSignalNumber == self sigSYS ifTrue:[^ 'bad system call']. |
|
3945 |
aSignalNumber == self sigPIPE ifTrue:[^ 'broken pipe']. |
|
3946 |
aSignalNumber == self sigALRM ifTrue:[^ 'alarm timer']. |
|
3947 |
aSignalNumber == self sigTERM ifTrue:[^ 'termination']. |
|
3948 |
aSignalNumber == self sigSTOP ifTrue:[^ 'stop']. |
|
3949 |
aSignalNumber == self sigTSTP ifTrue:[^ 'tty stop']. |
|
3950 |
aSignalNumber == self sigCONT ifTrue:[^ 'continue']. |
|
3951 |
aSignalNumber == self sigCHLD ifTrue:[^ 'child death']. |
|
3952 |
aSignalNumber == self sigTTIN ifTrue:[^ 'background tty input']. |
|
3953 |
aSignalNumber == self sigTTOU ifTrue:[^ 'background tty output']. |
|
3954 |
aSignalNumber == self sigIO ifTrue:[^ 'io available']. |
|
3955 |
aSignalNumber == self sigXCPU ifTrue:[^ 'cpu time expired']. |
|
3956 |
aSignalNumber == self sigXFSZ ifTrue:[^ 'file size limit']. |
|
3957 |
aSignalNumber == self sigVTALRM ifTrue:[^ 'virtual alarm timer']. |
|
3958 |
aSignalNumber == self sigPROF ifTrue:[^ 'profiling timer']. |
|
3959 |
aSignalNumber == self sigWINCH ifTrue:[^ 'winsize changed']. |
|
3960 |
aSignalNumber == self sigLOST ifTrue:[^ 'resource lost']. |
|
3961 |
aSignalNumber == self sigUSR1 ifTrue:[^ 'user signal 1']. |
|
3962 |
aSignalNumber == self sigUSR2 ifTrue:[^ 'user signal 2']. |
|
3963 |
aSignalNumber == self sigMSG ifTrue:[^ 'HFT message']. |
|
3964 |
aSignalNumber == self sigPWR ifTrue:[^ 'power-fail']. |
|
3965 |
aSignalNumber == self sigPRE ifTrue:[^ 'programming exception']. |
|
3966 |
aSignalNumber == self sigGRANT ifTrue:[^ 'HFT access wanted']. |
|
3967 |
aSignalNumber == self sigRETRACT ifTrue:[^ 'HFT access relinquish']. |
|
3968 |
aSignalNumber == self sigSOUND ifTrue:[^ 'HFT sound complete']. |
|
3969 |
aSignalNumber == self sigDANGER ifTrue:[^ 'low on paging space']. |
|
3970 |
||
3971 |
"notice: many systems map SIGPOLL and/or SIGUSR onto SIGIO |
|
3972 |
therefore, keep SIGIO always above the two below" |
|
3973 |
aSignalNumber == self sigPOLL ifTrue:[^ 'io available']. |
|
3974 |
aSignalNumber == self sigURG ifTrue:[^ 'urgent']. |
|
3975 |
||
3976 |
^ 'unknown signal' |
|
3977 |
||
68 | 3978 |
" |
616 | 3979 |
OperatingSystem nameForSignal:9 |
3980 |
OperatingSystem nameForSignal:(OperatingSystem sigPOLL) |
|
68 | 3981 |
" |
616 | 3982 |
! |
3983 |
||
3984 |
operatingSystemSignal:signalNumber |
|
3985 |
"return the signal to be raised when an |
|
3986 |
operatingSystem-signal occurs, or nil" |
|
3987 |
||
3988 |
OSSignals notNil ifTrue:[ |
|
3989 |
^ OSSignals at:signalNumber ifAbsent:[nil] |
|
3990 |
]. |
|
3991 |
^ nil |
|
10 | 3992 |
! |
3993 |
||
616 | 3994 |
operatingSystemSignal:signalNumber install:aSignal |
3995 |
"install a signal to be raised when an operatingSystem-signal occurs" |
|
3996 |
||
3997 |
OSSignals isNil ifTrue:[ |
|
3998 |
OSSignals := Array new:32 |
|
3999 |
]. |
|
4000 |
OSSignals at:signalNumber put:aSignal |
|
4001 |
! |
|
4002 |
||
4003 |
sendSignal:signalNumber to:processId |
|
4004 |
"send a unix signal to some process (maybe myself). |
|
4005 |
Returns false if any error occurred, true otherwise. |
|
4006 |
||
4007 |
Do not confuse UNIX signals with Smalltalk-Signals." |
|
4008 |
%{ |
|
792 | 4009 |
#ifndef MSDOS_LIKE |
616 | 4010 |
if (__bothSmallInteger(signalNumber, processId)) { |
4011 |
if (kill(__intVal(processId), __intVal(signalNumber)) < 0) { |
|
4012 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
4013 |
RETURN ( false ); |
|
216 | 4014 |
} |
616 | 4015 |
RETURN ( true ); |
10 | 4016 |
} |
792 | 4017 |
#endif |
68 | 4018 |
%}. |
792 | 4019 |
"/ |
4020 |
"/ either invalid argument (non-integers) |
|
4021 |
"/ or not supported by OS |
|
4022 |
"/ |
|
4023 |
^ self primitiveFailed |
|
1 | 4024 |
! |
4025 |
||
4026 |
startSpyTimer |
|
63 | 4027 |
"trigger a spyInterrupt, to be signalled after some short (virtual) time. |
359 | 4028 |
This is used by the old MessageTally for profiling. |
63 | 4029 |
Should be changed to use real profiling timer if available. |
68 | 4030 |
On systems, where no virtual timer is available, use the real timer |
359 | 4031 |
(which is of course less correct). |
4032 |
OBSOLETE: the new messageTally runs as a high prio process, not using |
|
4033 |
spy interrupts." |
|
1 | 4034 |
|
4035 |
%{ /* NOCONTEXT */ |
|
4036 |
||
329 | 4037 |
extern void __spyInterrupt(); |
10 | 4038 |
#if defined(ITIMER_VIRTUAL) |
1 | 4039 |
struct itimerval dt; |
4040 |
||
13 | 4041 |
# ifdef SIGVTALRM |
329 | 4042 |
signal(SIGVTALRM, __spyInterrupt); |
13 | 4043 |
# else |
329 | 4044 |
signal(SIGALRM, __spyInterrupt); |
13 | 4045 |
# endif |
4046 |
||
348 | 4047 |
dt.it_interval.tv_sec = 0; |
4048 |
dt.it_interval.tv_usec = 0; |
|
4049 |
dt.it_value.tv_sec = 0; |
|
4050 |
dt.it_value.tv_usec = 1000; /* 1000 Hz */ |
|
4051 |
setitimer(ITIMER_VIRTUAL, &dt, 0); |
|
4052 |
||
13 | 4053 |
RETURN (true); |
1 | 4054 |
#endif |
4055 |
%} |
|
13 | 4056 |
. |
4057 |
^ false |
|
1 | 4058 |
! |
4059 |
||
4060 |
stopSpyTimer |
|
359 | 4061 |
"stop spy timing - disable spy timer. |
4062 |
OBSOLETE: the new messageTally runs as a high prio process, not using |
|
4063 |
spy interrupts." |
|
1 | 4064 |
|
4065 |
%{ /* NOCONTEXT */ |
|
4066 |
||
10 | 4067 |
#if defined(ITIMER_VIRTUAL) |
1 | 4068 |
struct itimerval dt; |
4069 |
||
4070 |
dt.it_interval.tv_sec = 0; |
|
4071 |
dt.it_interval.tv_usec = 0; |
|
4072 |
dt.it_value.tv_sec = 0; |
|
4073 |
dt.it_value.tv_usec = 0; |
|
4074 |
setitimer(ITIMER_VIRTUAL, &dt, 0); |
|
13 | 4075 |
RETURN (true); |
10 | 4076 |
#endif |
4077 |
%} |
|
13 | 4078 |
. |
4079 |
^ false |
|
10 | 4080 |
! |
4081 |
||
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
4082 |
terminateProcess:processId |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
4083 |
"terminate a unix process. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
4084 |
The process has a chance to do some cleanup." |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
4085 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
4086 |
self sendSignal:(self sigTERM) to:processId. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
4087 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
4088 |
"Modified: 28.12.1995 / 15:05:37 / stefan" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
4089 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
4090 |
|
616 | 4091 |
unblockInterrupts |
4092 |
"enable interrupt processing - if any interrupts are pending, |
|
4093 |
these will be handled immediately. |
|
4094 |
When unblocking interrupts, take care of nested block/unblock |
|
4095 |
calls - you must only unblock after a blockcall if they where |
|
4096 |
really not blocked before. See OperatingSystemclass>>blockInterrupts." |
|
4097 |
%{ |
|
4098 |
__UNBLOCKINTERRUPTS(); |
|
4099 |
%} |
|
4100 |
! ! |
|
4101 |
||
4102 |
!OperatingSystem class methodsFor:'misc'! |
|
4103 |
||
4104 |
exit |
|
710 | 4105 |
"shutdown smalltalk immediately - this method does not return. |
4106 |
Return 'good'-status (0) to the parent unix process." |
|
616 | 4107 |
|
4108 |
%{ /* NOCONTEXT */ |
|
4109 |
__mainExit(0); |
|
4110 |
%} |
|
4111 |
"OperatingSystem exit - dont evaluate this" |
|
4112 |
! |
|
4113 |
||
4114 |
exit:exitCode |
|
4115 |
"shutdown smalltalk immediately - |
|
4116 |
returning an exit-code to the parent unix process." |
|
4117 |
||
4118 |
%{ /* NOCONTEXT */ |
|
4119 |
int code = 1; |
|
4120 |
||
4121 |
if (__isSmallInteger(exitCode)) { |
|
4122 |
code = _intVal(exitCode); |
|
4123 |
} |
|
4124 |
__mainExit(code); |
|
4125 |
%} |
|
4126 |
"OperatingSystem exit:1 - dont evaluate this" |
|
4127 |
! |
|
4128 |
||
4129 |
exitWithCoreDump |
|
4130 |
"shutdown smalltalk immediately - dumping core. |
|
4131 |
This always returns 'bad'-status to the parent unix process. |
|
4132 |
Notice, that no cleanup is performed at all - you may have to |
|
4133 |
manually remove any tempfiles. |
|
4134 |
Use this only for debugging ST/X itself" |
|
4135 |
||
4136 |
%{ /* NOCONTEXT */ |
|
4137 |
abort(); |
|
4138 |
%} |
|
831 | 4139 |
" |
4140 |
OperatingSystem exitWithCoreDump - dont evaluate this |
|
4141 |
" |
|
616 | 4142 |
! |
4143 |
||
4144 |
slowFork:aBoolean |
|
4145 |
SlowFork := aBoolean |
|
4146 |
! ! |
|
4147 |
||
4148 |
!OperatingSystem class methodsFor:'os queries'! |
|
4149 |
||
4150 |
getCPUDefine |
|
831 | 4151 |
"return a string which was used to identify this CPU type when STX was |
616 | 4152 |
compiled, and which should be passed down when compiling methods. |
831 | 4153 |
For example, on linux, this may be '-Di386'; on a vax, this would be '-Dvax'. |
4154 |
This is normally not of interest to 'normal' users; however, it is passed |
|
4155 |
down to the c-compiler when methods are incrementally compiled to machine code." |
|
616 | 4156 |
|
4157 |
%{ /* NOCONTEXT */ |
|
831 | 4158 |
# ifndef CPU_DEFINE |
4159 |
# define CPU_DEFINE "-DunknownCPU" |
|
4160 |
# endif |
|
4161 |
||
616 | 4162 |
RETURN ( __MKSTRING(CPU_DEFINE COMMA_CON)); |
4163 |
%} |
|
4164 |
" |
|
4165 |
OperatingSystem getCPUDefine |
|
4166 |
" |
|
4167 |
! |
|
4168 |
||
4169 |
getCPUType |
|
4170 |
"return a string giving the type of machine we're running on. |
|
831 | 4171 |
Here, the machine for which ST/X was compiled is returned |
4172 |
(i.e. for all x86's, the same i386 is returned). |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
4173 |
This may normally not be of any interest to you ..." |
616 | 4174 |
|
4175 |
|cpu| |
|
4176 |
||
4177 |
%{ /* NOCONTEXT */ |
|
4178 |
||
4179 |
# ifdef vax |
|
4180 |
# define CPU_STRING "vax" |
|
4181 |
# endif |
|
4182 |
# ifdef mips |
|
4183 |
# define CPU_STRING "mips" |
|
4184 |
# endif |
|
4185 |
# ifdef i386 |
|
4186 |
# define CPU_STRING "i386" |
|
4187 |
# endif |
|
4188 |
# ifdef ns32k |
|
4189 |
# define CPU_STRING "ns32k" |
|
4190 |
# endif |
|
4191 |
# ifdef mc68k |
|
4192 |
# define CPU_STRING "mc68k" |
|
4193 |
# endif |
|
4194 |
# ifdef mc88k |
|
4195 |
# define CPU_STRING "mc88k" |
|
4196 |
# endif |
|
4197 |
# ifdef sparc |
|
4198 |
# define CPU_STRING "sparc" |
|
4199 |
# endif |
|
4200 |
# ifdef hppa |
|
4201 |
# define CPU_STRING "hppa" |
|
4202 |
# endif |
|
4203 |
# ifdef rs6000 |
|
4204 |
# define CPU_STRING "rs6000" |
|
4205 |
# endif |
|
831 | 4206 |
# ifdef powerPC |
4207 |
# define CPU_STRING "powerPC" |
|
4208 |
# endif |
|
616 | 4209 |
# ifdef alpha |
4210 |
# define CPU_STRING "alpha" |
|
4211 |
# endif |
|
4212 |
# ifdef transputer |
|
4213 |
# define CPU_STRING "transputer" |
|
4214 |
# endif |
|
4215 |
# ifdef ibm370 |
|
4216 |
# define CPU_STRING "ibm370" |
|
4217 |
# endif |
|
4218 |
||
4219 |
# ifndef CPU_STRING |
|
4220 |
# define CPU_STRING "unknown" |
|
4221 |
# endif |
|
4222 |
||
830 | 4223 |
cpu = __MKSTRING(CPU_STRING COMMA_CON); |
616 | 4224 |
# undef CPU_STRING |
831 | 4225 |
%}. |
616 | 4226 |
^ cpu |
4227 |
||
4228 |
" |
|
4229 |
OperatingSystem getCPUType |
|
4230 |
" |
|
4231 |
||
4232 |
"examples: are we running on a ss-10/solaris ?" |
|
4233 |
" |
|
4234 |
(OperatingSystem getCPUType = 'sparc') |
|
4235 |
and:[OperatingSystem getOSType = 'solaris'] |
|
4236 |
" |
|
4237 |
||
4238 |
"or on a pc/solaris ?" |
|
4239 |
" |
|
4240 |
(OperatingSystem getCPUType = 'i386') |
|
4241 |
and:[OperatingSystem getOSType = 'solaris'] |
|
4242 |
" |
|
4243 |
! |
|
4244 |
||
4245 |
getCommandOutputFrom:aCommand |
|
4246 |
"execute a simple command (such as hostname) and |
|
4247 |
return the commands output as a string" |
|
4248 |
||
4249 |
|p result| |
|
4250 |
||
4251 |
ForkFailed ifFalse:[ |
|
4252 |
PipeStream openErrorSignal handle:[:ex | |
|
4253 |
ForkFailed := true. |
|
4254 |
'OS: cannot fork/popen' errorPrintNL. |
|
4255 |
ex return. |
|
4256 |
] do:[ |
|
4257 |
p := PipeStream readingFrom:aCommand. |
|
4258 |
p notNil ifTrue:[ |
|
4259 |
result := p nextLine. |
|
4260 |
p close |
|
4261 |
] |
|
4262 |
] |
|
4263 |
]. |
|
4264 |
^ result |
|
4265 |
! |
|
4266 |
||
4267 |
getDomainName |
|
4268 |
"return the domain this host is in. |
|
4269 |
Notice: |
|
4270 |
not all systems support this; on some, 'unknown' is returned." |
|
4271 |
||
4272 |
|name| |
|
4273 |
||
4274 |
DomainName notNil ifTrue:[ |
|
4275 |
^ DomainName |
|
4276 |
]. |
|
4277 |
||
4278 |
%{ /* STACK: 2048 */ |
|
4279 |
#if defined(HAS_GETDOMAINNAME) |
|
4280 |
char buffer[128]; |
|
4281 |
||
4282 |
if (getdomainname(buffer, sizeof(buffer)) == 0) { |
|
830 | 4283 |
name = __MKSTRING(buffer COMMA_CON); |
616 | 4284 |
} |
4285 |
#else |
|
4286 |
# if defined(HAS_UNAME) && defined(HAS_UTS_DOMAINNAME) |
|
4287 |
struct utsname ubuff; |
|
4288 |
||
4289 |
if (uname(&ubuff) >= 0) { |
|
830 | 4290 |
name = __MKSTRING(ubuff.domainname COMMA_CON); |
616 | 4291 |
} |
4292 |
# endif |
|
4293 |
#endif |
|
4294 |
%}. |
|
4295 |
name isNil ifTrue:[ |
|
4296 |
name := self getEnvironment:'DOMAIN'. |
|
4297 |
name isNil ifTrue:[ |
|
4298 |
name := self getCommandOutputFrom:'domainname' |
|
4299 |
] |
|
4300 |
]. |
|
4301 |
name isNil ifTrue:[ |
|
4302 |
'OS: cannot find out domainname' errorPrintNL. |
|
4303 |
name := 'unknown'. |
|
4304 |
]. |
|
4305 |
DomainName := name. |
|
4306 |
^ name |
|
4307 |
||
4308 |
" |
|
4309 |
OperatingSystem getDomainName |
|
4310 |
" |
|
4311 |
! |
|
4312 |
||
4313 |
getEnvironment:aStringOrSymbol |
|
4314 |
"get an environment string" |
|
10 | 4315 |
|
4316 |
%{ /* NOCONTEXT */ |
|
4317 |
||
616 | 4318 |
char *env; |
4319 |
||
4320 |
if (__isString(aStringOrSymbol) || __isSymbol(aStringOrSymbol)) { |
|
4321 |
env = (char *)getenv(_stringVal(aStringOrSymbol)); |
|
4322 |
if (env) { |
|
830 | 4323 |
RETURN ( __MKSTRING(env COMMA_CON) ); |
616 | 4324 |
} |
4325 |
} |
|
4326 |
%} |
|
4327 |
. |
|
4328 |
^ nil |
|
4329 |
||
4330 |
" |
|
4331 |
OperatingSystem getEnvironment:'LANG' |
|
4332 |
OperatingSystem getEnvironment:'LOGIN' |
|
4333 |
OperatingSystem getEnvironment:'HOME' |
|
4334 |
OperatingSystem getEnvironment:'NNTPSERVER' |
|
4335 |
OperatingSystem getEnvironment:'MAIL' |
|
4336 |
OperatingSystem getEnvironment:'PATH' |
|
4337 |
" |
|
4338 |
! |
|
4339 |
||
4340 |
getHostName |
|
4341 |
"return the hostname we are running on - if there is |
|
4342 |
a HOST environment variable, we are much faster here ... |
|
4343 |
Notice: |
|
4344 |
not all systems support this; on some, 'unknown' is returned." |
|
4345 |
||
4346 |
|name| |
|
4347 |
||
4348 |
HostName notNil ifTrue:[ |
|
4349 |
^ HostName |
|
4350 |
]. |
|
4351 |
||
4352 |
%{ /* STACK: 2048 */ |
|
4353 |
#if defined(HAS_GETHOSTNAME) |
|
4354 |
char buffer[128]; |
|
4355 |
||
4356 |
if (gethostname(buffer, sizeof(buffer)) == 0) { |
|
830 | 4357 |
name = __MKSTRING(buffer COMMA_CON); |
616 | 4358 |
} |
4359 |
#else |
|
4360 |
# if defined(HAS_UNAME) |
|
4361 |
struct utsname ubuff; |
|
4362 |
||
4363 |
if (uname(&ubuff) >= 0) { |
|
830 | 4364 |
name = __MKSTRING(ubuff.nodename COMMA_CON); |
616 | 4365 |
} |
831 | 4366 |
# else |
4367 |
# ifdef WIN32 |
|
4368 |
char buffer[128]; |
|
4369 |
int buffSize = sizeof(buffer); |
|
4370 |
||
4371 |
if (GetComputerName(buffer, &buffSize) == TRUE) { |
|
4372 |
name = _MKSTRING(buffer COMMA_CON); |
|
4373 |
} |
|
4374 |
# endif |
|
1 | 4375 |
# endif |
616 | 4376 |
#endif |
4377 |
%}. |
|
4378 |
name isNil ifTrue:[ |
|
4379 |
name := self getEnvironment:'HOST'. |
|
4380 |
name isNil ifTrue:[ |
|
4381 |
name := self getCommandOutputFrom:'hostname' |
|
4382 |
] |
|
4383 |
]. |
|
4384 |
name isNil ifTrue:[ |
|
4385 |
'OS: cannot find out hostname' errorPrintNL. |
|
4386 |
name := 'unknown'. |
|
4387 |
]. |
|
4388 |
HostName := name. |
|
4389 |
^ name |
|
4390 |
||
4391 |
" |
|
4392 |
OperatingSystem getHostName |
|
4393 |
" |
|
4394 |
! |
|
4395 |
||
4396 |
getOSDefine |
|
4397 |
"return a string which was used to identify this machine when stx was |
|
4398 |
compiled, and which should be passed down when compiling methods. |
|
4399 |
For example, on linux, this is '-DLINUX'." |
|
4400 |
||
4401 |
%{ /* NOCONTEXT */ |
|
831 | 4402 |
#ifdef WIN32 |
4403 |
# ifndef OS_DEFINE |
|
4404 |
# define OS_DEFINE "-DWIN32" |
|
4405 |
# endif |
|
4406 |
#endif |
|
4407 |
||
616 | 4408 |
#ifndef OS_DEFINE |
4409 |
# define OS_DEFINE "-DunknownOS" |
|
4410 |
#endif |
|
831 | 4411 |
|
616 | 4412 |
RETURN ( __MKSTRING(OS_DEFINE COMMA_CON)); |
4413 |
%} |
|
4414 |
" |
|
4415 |
OperatingSystem getOSDefine |
|
4416 |
" |
|
4417 |
! |
|
4418 |
||
4419 |
getOSType |
|
4420 |
"return a string giving the type of OS we're running on. |
|
4421 |
This can be used to adapt programs to certain environment |
|
4422 |
differences (for example: mail-lock strategy ...)" |
|
4423 |
||
4424 |
|os| |
|
4425 |
||
4426 |
%{ /* NOCONTEXT */ |
|
4427 |
||
4428 |
# ifdef MSDOS |
|
4429 |
# define OS_STRING "msdos" |
|
4430 |
# endif |
|
4431 |
||
831 | 4432 |
# ifdef WIN32 |
4433 |
char *OS_STRING = "win32"; |
|
4434 |
||
4435 |
# endif |
|
4436 |
||
616 | 4437 |
# ifdef MSWINDOWS |
4438 |
# define OS_STRING "mswindows" |
|
4439 |
# endif |
|
4440 |
||
4441 |
# ifdef NT |
|
4442 |
# define OS_STRING "nt" |
|
4443 |
# endif |
|
4444 |
||
4445 |
# ifdef VMS |
|
4446 |
# define OS_STRING "vms" |
|
4447 |
# endif |
|
4448 |
||
4449 |
# ifdef MVS |
|
4450 |
# define OS_STRING "mvs" |
|
4451 |
# endif |
|
4452 |
||
4453 |
# ifdef OS2 |
|
4454 |
# define OS_STRING "os2" |
|
4455 |
# endif |
|
4456 |
||
4457 |
# ifdef sinix |
|
4458 |
# define OS_STRING "sinix" |
|
4459 |
# endif |
|
4460 |
||
4461 |
# ifdef ultrix |
|
4462 |
# define OS_STRING "ultrix" |
|
4463 |
# endif |
|
4464 |
||
4465 |
# ifdef sco |
|
4466 |
# define OS_STRING "sco" |
|
4467 |
# endif |
|
4468 |
||
4469 |
# ifdef hpux |
|
4470 |
# define OS_STRING "hpux" |
|
4471 |
# endif |
|
4472 |
||
4473 |
# ifdef LINUX |
|
4474 |
# define OS_STRING "linux" |
|
4475 |
# endif |
|
4476 |
||
4477 |
# ifdef sunos |
|
4478 |
# define OS_STRING "sunos" |
|
4479 |
# endif |
|
4480 |
||
4481 |
# ifdef solaris |
|
4482 |
# define OS_STRING "solaris" |
|
4483 |
# endif |
|
4484 |
||
4485 |
# ifdef IRIS |
|
4486 |
# define OS_STRING "irix" |
|
4487 |
# endif |
|
4488 |
||
4489 |
# ifdef aix |
|
4490 |
# define OS_STRING "aix" |
|
4491 |
# endif |
|
4492 |
||
4493 |
# ifdef realIX |
|
4494 |
# define OS_STRING "realIX" |
|
4495 |
# endif |
|
4496 |
||
4497 |
/* |
|
4498 |
* no concrete info; become somewhat vague ... |
|
4499 |
*/ |
|
4500 |
# ifndef OS_STRING |
|
4501 |
# ifdef MACH |
|
4502 |
# define OS_STRING "mach" |
|
4503 |
# endif |
|
4504 |
# endif |
|
4505 |
||
4506 |
# ifndef OS_STRING |
|
4507 |
# ifdef BSD |
|
4508 |
# define OS_STRING "bsd" |
|
4509 |
# endif |
|
4510 |
||
4511 |
# ifdef SYSV |
|
4512 |
# ifdef SYSV3 |
|
4513 |
# define OS_STRING "sys5_3" |
|
4514 |
# else |
|
4515 |
# ifdef SYSV4 |
|
4516 |
# define OS_STRING "sys5_4" |
|
4517 |
# else |
|
4518 |
# define OS_STRING "sys5" |
|
4519 |
# endif |
|
4520 |
# endif |
|
4521 |
# endif |
|
4522 |
# endif |
|
4523 |
||
4524 |
/* |
|
4525 |
* become very vague ... |
|
4526 |
*/ |
|
4527 |
# ifndef OS_STRING |
|
4528 |
# ifdef POSIX |
|
4529 |
# define OS_STRING "posix" |
|
4530 |
# endif |
|
4531 |
# endif |
|
4532 |
# ifndef OS_STRING |
|
4533 |
# ifdef UNIX |
|
4534 |
# define OS_STRING "unix" |
|
4535 |
# endif |
|
4536 |
# endif |
|
4537 |
||
4538 |
# ifndef OS_STRING |
|
4539 |
# define OS_STRING "unknown" |
|
4540 |
# endif |
|
4541 |
||
830 | 4542 |
os = __MKSTRING(OS_STRING COMMA_CON); |
616 | 4543 |
# undef OS_STRING |
831 | 4544 |
%}. |
616 | 4545 |
^ os |
4546 |
||
4547 |
"OperatingSystem getOSType" |
|
4548 |
! |
|
4549 |
||
4550 |
getProcessId |
|
4551 |
"return the (unix-)processId" |
|
4552 |
||
4553 |
%{ /* NOCONTEXT */ |
|
4554 |
||
4555 |
int pid = 0; |
|
4556 |
#ifdef UNIX_LIKE |
|
4557 |
pid = getpid(); |
|
4558 |
#endif |
|
4559 |
RETURN ( _MKSMALLINT(pid) ); |
|
4560 |
%} |
|
4561 |
" |
|
4562 |
OperatingSystem getProcessId |
|
4563 |
" |
|
4564 |
! |
|
4565 |
||
4566 |
getSystemID |
|
4567 |
"if supported by the OS, return the systemID; |
|
4568 |
a unique per machine identification. |
|
4569 |
WARNING: |
|
4570 |
not all systems support this; on some, 'unknown' is returned." |
|
4571 |
||
4572 |
%{ /* NO_CONTEXT */ |
|
4573 |
#if defined(IRIX5) && !defined(HAS_GETHOSTID) |
|
4574 |
char idBuffer[MAXSYSIDSIZE]; |
|
4575 |
int retVal; |
|
4576 |
OBJ arr; |
|
4577 |
||
4578 |
if ((retVal = syssgi(SGI_SYSID, idBuffer)) == 0) { |
|
4579 |
arr = __BYTEARRAY_UNINITIALIZED_NEW_INT(MAXSYSIDSIZE); |
|
4580 |
bcopy(idBuffer, __ByteArrayInstPtr(arr)->ba_element, MAXSYSIDSIZE); |
|
4581 |
RETURN (arr); |
|
4582 |
} |
|
4583 |
#endif |
|
4584 |
#if defined(HAS_GETHOSTID) |
|
4585 |
int runningId; |
|
4586 |
OBJ arr; |
|
4587 |
||
4588 |
runningId = gethostid(); |
|
4589 |
arr = __BYTEARRAY_UNINITIALIZED_NEW_INT(4); |
|
4590 |
*(int *)(__ByteArrayInstPtr(arr)->ba_element) = runningId; |
|
4591 |
RETURN (arr); |
|
4592 |
#endif |
|
4593 |
%}. |
|
4594 |
^ 'unknown' |
|
4595 |
||
4596 |
" |
|
4597 |
OperatingSystem getSystemID |
|
4598 |
" |
|
4599 |
! |
|
4600 |
||
4601 |
getSystemInfo |
|
831 | 4602 |
"return info on the system weare running on. |
4603 |
If the system supports the uname system call, that info is returned; |
|
616 | 4604 |
otherwise, some simulated info is returned. |
831 | 4605 |
|
616 | 4606 |
WARNING: |
831 | 4607 |
Do not depend on the amount and contents of the returned information, some |
4608 |
systems may return more/less than others. Also, the contents depends on the |
|
4609 |
OS, for example, linux returns 'ix86', while WIN32 returns 'x86'. |
|
4610 |
||
4611 |
This method is mainly provided to augment error reports with some system |
|
4612 |
information. |
|
4613 |
(in case of system/version specific OS errors, conditional workarounds and patches |
|
4614 |
may be based upon this info) |
|
616 | 4615 |
|
4616 |
The returned info may (or may not) contain: |
|
831 | 4617 |
#system -> some operating system identification (irix, Linux, nt, win32s ...) |
4618 |
#version -> OS version (some os version identification) |
|
4619 |
#release -> OS release (3.5, 1.2.1 ...) |
|
4620 |
#node -> some host identification (hostname) |
|
4621 |
#domain -> domain name (hosts domain) |
|
4622 |
#machine -> type of machine (i586, mips ...) |
|
616 | 4623 |
" |
4624 |
||
4625 |
|sys node rel ver mach dom mtyp brel info| |
|
4626 |
||
4627 |
%{ /* STACK: 2048 */ |
|
4628 |
#if defined(HAS_UNAME) |
|
4629 |
struct utsname ubuff; |
|
4630 |
||
4631 |
if (uname(&ubuff) >= 0) { |
|
830 | 4632 |
sys = __MKSTRING(ubuff.sysname COMMA_CON); |
4633 |
node = __MKSTRING(ubuff.nodename COMMA_CON); |
|
4634 |
rel = __MKSTRING(ubuff.release COMMA_CON); |
|
4635 |
ver = __MKSTRING(ubuff.version COMMA_CON); |
|
4636 |
mach = __MKSTRING(ubuff.machine COMMA_CON); |
|
616 | 4637 |
# ifdef HAS_UTS_DOMAINNAME |
830 | 4638 |
dom = __MKSTRING(ubuff.domainname COMMA_CON); |
616 | 4639 |
# endif |
4640 |
} |
|
831 | 4641 |
#else /* no uname */ |
4642 |
# ifdef WIN32 |
|
4643 |
||
4644 |
char vsnBuffer[32]; |
|
4645 |
char *s; |
|
4646 |
int winVer; |
|
4647 |
DWORD vsn; |
|
4648 |
SYSTEM_INFO sysInfo; |
|
4649 |
||
4650 |
vsn = GetVersion(); |
|
4651 |
||
4652 |
if (HIWORD(vsn) & 0x8000) { |
|
4653 |
s = "win32s"; |
|
4654 |
} else { |
|
4655 |
s = "nt"; |
|
4656 |
} |
|
4657 |
sys = __MKSTRING(s COMMA_CON); |
|
4658 |
winVer = LOWORD(vsn); |
|
4659 |
sprintf(vsnBuffer, "%d.%d", LOBYTE(winVer), HIBYTE(winVer)); |
|
4660 |
rel = __MKSTRING(vsnBuffer COMMA_CON); |
|
4661 |
||
4662 |
GetSystemInfo(&sysInfo); |
|
4663 |
if (sysInfo.dwProcessorType) { |
|
4664 |
sprintf(vsnBuffer, "%d", sysInfo.dwProcessorType); |
|
4665 |
mach = __MKSTRING(vsnBuffer COMMA_CON); |
|
4666 |
} |
|
4667 |
||
4668 |
# endif /* WIN32 */ |
|
4669 |
#endif /* no uname */ |
|
616 | 4670 |
%}. |
4671 |
sys isNil ifTrue:[ |
|
4672 |
sys := self getSystemType. |
|
4673 |
]. |
|
4674 |
node isNil ifTrue:[ |
|
4675 |
node := self getHostName |
|
4676 |
]. |
|
4677 |
dom isNil ifTrue:[ |
|
4678 |
dom := self getDomainName |
|
4679 |
]. |
|
831 | 4680 |
mach isNil ifTrue:[ |
4681 |
mach := self getCPUType |
|
4682 |
]. |
|
616 | 4683 |
|
4684 |
info := IdentityDictionary new. |
|
4685 |
info at:#system put:sys. |
|
4686 |
info at:#node put:node. |
|
4687 |
rel notNil ifTrue:[info at:#release put:rel]. |
|
4688 |
ver notNil ifTrue:[info at:#version put:ver]. |
|
4689 |
mach notNil ifTrue:[info at:#machine put:mach]. |
|
4690 |
dom notNil ifTrue:[info at:#domain put:dom]. |
|
4691 |
^ info |
|
4692 |
||
4693 |
" |
|
4694 |
OperatingSystem getSystemInfo |
|
4695 |
" |
|
4696 |
! |
|
4697 |
||
4698 |
getSystemType |
|
4699 |
"return a string giving the type of system we're running on. |
|
4700 |
This is almost the same as getOSType, but the returned string |
|
4701 |
is slightly different for some systems (i.e. iris vs. irix). |
|
4702 |
Dont depend on this - use getOSType. I dont really see a point |
|
831 | 4703 |
here ... |
4704 |
(except for slight differences between next/mach and other machs)" |
|
616 | 4705 |
|
4706 |
|sys| |
|
4707 |
||
4708 |
%{ |
|
4709 |
# ifdef NEXT |
|
4710 |
# define SYS_STRING "next" |
|
4711 |
# endif |
|
4712 |
||
4713 |
# ifdef IRIS |
|
4714 |
# define SYS_STRING "iris" |
|
4715 |
# endif |
|
4716 |
||
831 | 4717 |
# ifdef WIN32 |
4718 |
# define SYS_STRING "win32" |
|
4719 |
# endif |
|
4720 |
||
616 | 4721 |
# ifdef SYS_STRING |
830 | 4722 |
sys = __MKSTRING(SYS_STRING COMMA_CON); |
616 | 4723 |
# undef SYS_STRING |
4724 |
# endif |
|
831 | 4725 |
%}. |
616 | 4726 |
sys isNil ifTrue:[ |
4727 |
^ self getOSType |
|
4728 |
]. |
|
4729 |
^ sys |
|
4730 |
||
4731 |
" |
|
4732 |
OperatingSystem getSystemType |
|
4733 |
" |
|
4734 |
! |
|
4735 |
||
4736 |
isBSDlike |
|
4737 |
"return true, if the OS we're running on is a 'real' unix." |
|
4738 |
||
4739 |
%{ /* NOCONTEXT */ |
|
4740 |
||
4741 |
#if defined(BSD) || defined(MACH) || defined(SYSV4) |
|
4742 |
RETURN ( true ); |
|
13 | 4743 |
#endif |
831 | 4744 |
%}. |
13 | 4745 |
^ false |
10 | 4746 |
! |
4747 |
||
616 | 4748 |
isMSDOSlike |
4749 |
"return true, if the OS we're running on is dos like |
|
4750 |
(in contrast to unix-like)." |
|
4751 |
||
4752 |
%{ /* NOCONTEXT */ |
|
4753 |
||
4754 |
#if defined(MSDOS_LIKE) |
|
4755 |
RETURN ( true ); |
|
4756 |
#endif |
|
831 | 4757 |
%}. |
616 | 4758 |
^ false |
4759 |
! |
|
4760 |
||
4761 |
isUNIXlike |
|
4762 |
"return true, if the OS we're running on is a unix like." |
|
4763 |
||
4764 |
%{ /* NOCONTEXT */ |
|
4765 |
||
831 | 4766 |
#if !defined(UNIX_LIKE) |
616 | 4767 |
RETURN ( false ); |
4768 |
#endif |
|
831 | 4769 |
%}. |
616 | 4770 |
^ true |
4771 |
! |
|
4772 |
||
831 | 4773 |
isMSWINDOWSlike |
4774 |
"return true, if the OS we're running on is MS-Windows like." |
|
4775 |
||
4776 |
%{ /* NOCONTEXT */ |
|
4777 |
||
4778 |
#if defined(WIN32) |
|
4779 |
RETURN ( true ); |
|
4780 |
#endif |
|
4781 |
||
4782 |
%}. |
|
4783 |
^ false |
|
4784 |
! |
|
4785 |
||
4786 |
isOS2like |
|
4787 |
"return true, if the OS we're running on is OS2 like" |
|
4788 |
||
4789 |
%{ /* NOCONTEXT */ |
|
4790 |
||
4791 |
#if defined(OS2) |
|
4792 |
RETURN (true); |
|
4793 |
#endif |
|
4794 |
||
4795 |
%}. |
|
4796 |
^ false |
|
4797 |
! |
|
4798 |
||
616 | 4799 |
maxFileNameLength |
4800 |
"return the max number of characters in a filename. |
|
831 | 4801 |
CAVEAT: |
4802 |
Actually, the following is somewhat wrong - some systems |
|
4803 |
support different sizezs, depending on the volume. |
|
4804 |
We return a somewhat conservative number here." |
|
10 | 4805 |
|
4806 |
%{ /* NOCONTEXT */ |
|
616 | 4807 |
|
4808 |
/* |
|
4809 |
* XXX: newer systems provide a query function for this ... use it |
|
4810 |
*/ |
|
4811 |
# if defined(BSD) || defined(SYSV4) || defined(LONGFILENAMES) |
|
831 | 4812 |
RETURN ( __MKSMALLINT(255) ); |
616 | 4813 |
# endif |
4814 |
||
4815 |
# ifdef realIX |
|
831 | 4816 |
RETURN ( __MKSMALLINT(127) ); |
616 | 4817 |
# endif |
4818 |
||
4819 |
# ifdef SYSV |
|
831 | 4820 |
RETURN ( __MKSMALLINT(14) ); |
616 | 4821 |
# endif |
4822 |
||
4823 |
# ifdef MSDOS |
|
831 | 4824 |
RETURN ( __MKSMALLINT(9) ); |
616 | 4825 |
# endif |
4826 |
||
831 | 4827 |
# ifdef WIN32 |
616 | 4828 |
/* |
4829 |
* mhmh - depends on the filesystem type |
|
4830 |
*/ |
|
831 | 4831 |
RETURN ( __MKSMALLINT(9) ); |
616 | 4832 |
# endif |
4833 |
%}. |
|
4834 |
"unix default" |
|
831 | 4835 |
|
616 | 4836 |
^ 14 |
4837 |
! |
|
4838 |
||
4839 |
supportsIOInterrupts |
|
4840 |
"return true, if the OS supports IO availability interrupts |
|
4841 |
(i.e. SIGPOLL/SIGIO). |
|
4842 |
||
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4843 |
Currently, this mechanism does work for SYSV4 only ..." |
616 | 4844 |
|
4845 |
%{ /* NOCONTEXT */ |
|
765
93bdb4f0e095
no, SIGIO does not work on SGI ...
Claus Gittinger <cg@exept.de>
parents:
764
diff
changeset
|
4846 |
#if defined(SYSV4) && defined(USE_SIGIO) |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4847 |
|
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4848 |
# if defined(SIGPOLL) || defined(SIGIO) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4849 |
# if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4850 |
/* |
765
93bdb4f0e095
no, SIGIO does not work on SGI ...
Claus Gittinger <cg@exept.de>
parents:
764
diff
changeset
|
4851 |
* currently the only system where they work is unixware SYSV4 |
93bdb4f0e095
no, SIGIO does not work on SGI ...
Claus Gittinger <cg@exept.de>
parents:
764
diff
changeset
|
4852 |
* (not even on SGI ...) |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4853 |
*/ |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4854 |
# if !defined(NEXT) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4855 |
RETURN (true); |
616 | 4856 |
# endif |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4857 |
# endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4858 |
# endif |
616 | 4859 |
|
10 | 4860 |
#endif |
831 | 4861 |
%}. |
13 | 4862 |
^ false |
123 | 4863 |
! |
4864 |
||
616 | 4865 |
supportsNonBlockingIO |
4866 |
"return true, if the OS supports nonblocking IO." |
|
4867 |
||
4868 |
%{ /* NOCONTEXT */ |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4869 |
#if defined(F_GETFL) && defined(F_SETFL) && defined(FNDELAY) |
616 | 4870 |
RETURN (true); |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4871 |
#endif |
831 | 4872 |
%}. |
616 | 4873 |
^ false |
123 | 4874 |
! |
4875 |
||
616 | 4876 |
supportsSelect |
4877 |
"return true, if the OS supports selecting on multiple |
|
4878 |
filedescriptors via select." |
|
4879 |
||
4880 |
%{ /* NOCONTEXT */ |
|
831 | 4881 |
#if defined(WIN32) |
4882 |
RETURN (false); |
|
4883 |
#endif |
|
616 | 4884 |
#if defined(sco) |
4885 |
/* |
|
831 | 4886 |
* sco has a select, but its broken: always waiting 1 second |
616 | 4887 |
*/ |
4888 |
RETURN(false); |
|
4889 |
#endif |
|
4890 |
%} |
|
4891 |
. |
|
4892 |
^ true |
|
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4893 |
! |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4894 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4895 |
getLocaleInfo |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4896 |
"return a dictionary filled with values from the locale information; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4897 |
Not all fields may be present, depending on the OS's setup and capabilities. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4898 |
Possible fields are: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4899 |
decimalPoint <String> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4900 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4901 |
thousandsSep <String> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4902 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4903 |
internationalCurrencySymbol <String> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4904 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4905 |
currencySymbol <String> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4906 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4907 |
monetaryDecimalPoint <String> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4908 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4909 |
monetaryThousandsSeparator <String> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4910 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4911 |
positiveSign <String> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4912 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4913 |
negativeSign <String> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4914 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4915 |
internationalFractionalDigits <Integer> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4916 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4917 |
fractionalDigits <Integer> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4918 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4919 |
positiveSignPrecedesCurrencySymbol <Boolean> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4920 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4921 |
negativeSignPrecedesCurrencySymbol <Boolean> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4922 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4923 |
positiveSignSeparatedBySpaceFromCurrencySymbol <Boolean> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4924 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4925 |
negativeSignSeparatedBySpaceFromCurrencySymbol <Boolean> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4926 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4927 |
positiveSignPosition <Symbol> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4928 |
one of: #parenthesesAround, |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4929 |
#signPrecedes, |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4930 |
#signSuceeds, |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4931 |
#signPrecedesCurrencySymbol, |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4932 |
#signSuceedsCurrencySymbol |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4933 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4934 |
negativeSignPosition <like above> |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4935 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4936 |
it is up to the application to deal with undefined values. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4937 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4938 |
Notice, that (for now), the system does not use this information; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4939 |
it should be used by applications as required. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4940 |
" |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4941 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4942 |
|info val| |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4943 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4944 |
LocaleInfo notNil ifTrue:[ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4945 |
"/ return the internal info; useful on systems which do not |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4946 |
"/ support this. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4947 |
^ LocaleInfo |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4948 |
]. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4949 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4950 |
info := IdentityDictionary new. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4951 |
%{ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4952 |
char *decimalPoint; /* something like "." (US) or "," (german) */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4953 |
char *thousandsSep; /* something like "," (US) or "." (german) */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4954 |
char *intCurrencySymbol; /* international currency symbol; something like "USD " "DM " */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4955 |
char *currencySymbol; /* local currency symbol; something like "USD " "DM " */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4956 |
char *monDecimalPoint; /* money: decimal point */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4957 |
char *monThousandsSep; /* money: thousands sep */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4958 |
char *positiveSign; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4959 |
char *negativeSign; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4960 |
int intFractDigits; /* money: international digits after decPoint */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4961 |
int fractDigits; /* money: local digits after decPoint */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4962 |
int csPosPrecedes; /* money: 1 if currency symbol precedes a positive value; 0 if it sceeds */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4963 |
int csNegPrecedes; /* money: 1 if currency symbol precedes a negative value; 0 if it sceeds */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4964 |
int csPosSepBySpace; /* money: 1 if currency symbol should be separated by a space from a positive value; 0 if no space */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4965 |
int csNegSepBySpace; /* money: 1 if currency symbol should be separated by a space from a negative value; 0 if no space */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4966 |
int csPosSignPosition; /* money: 0: ()'s around the value & currency symbol */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4967 |
int csNegSignPosition; /* 1: sign precedes the value & currency symbol */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4968 |
/* 2: sign succeeds the value & currency symbol */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4969 |
/* 3: sign immediately precedes the currency symbol */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4970 |
/* 4: sign immediately suceeds the currency symbol */ |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4971 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4972 |
#if defined(HAS_LOCALECONV) |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4973 |
struct lconv *conf; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4974 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4975 |
conf = localeconv(); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4976 |
if (conf) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4977 |
decimalPoint = conf->decimal_point; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4978 |
thousandsSep = conf->thousands_sep; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4979 |
intCurrencySymbol = conf->int_curr_symbol; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4980 |
currencySymbol = conf->currency_symbol; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4981 |
monDecimalPoint = conf->mon_decimal_point; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4982 |
monThousandsSep = conf->mon_thousands_sep; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4983 |
positiveSign = conf->positive_sign; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4984 |
negativeSign = conf->negative_sign; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4985 |
intFractDigits = conf->int_frac_digits; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4986 |
fractDigits = conf->frac_digits; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4987 |
csPosPrecedes = conf->p_cs_precedes; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4988 |
csNegPrecedes = conf->n_cs_precedes; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4989 |
csPosSepBySpace = conf->p_sep_by_space; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4990 |
csNegSepBySpace = conf->n_sep_by_space; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4991 |
csPosSignPosition = conf->p_sign_posn; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4992 |
csNegSignPosition = conf->n_sign_posn; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4993 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4994 |
#else |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4995 |
decimalPoint = (char *)0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4996 |
thousandsSep = (char *)0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4997 |
intCurrencySymbol = (char *)0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4998 |
currencySymbol = (char *)0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
4999 |
monDecimalPoint = (char *)0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5000 |
monThousandsSep = (char *)0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5001 |
positiveSign = (char *)0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5002 |
negativeSign =(char *)0; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5003 |
intFractDigits = -1; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5004 |
fractDigits = -1; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5005 |
csPosPrecedes = -1; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5006 |
csNegPrecedes = -1; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5007 |
csPosSepBySpace = -1; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5008 |
csNegSepBySpace = -1; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5009 |
csPosSignPosition = -1; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5010 |
csNegSignPosition = -1; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5011 |
#endif |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5012 |
if (decimalPoint) { |
830 | 5013 |
val = __MKSTRING(decimalPoint); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5014 |
__AT_PUT_(info, @symbol(decimalPoint), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5015 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5016 |
if (thousandsSep) { |
830 | 5017 |
val = __MKSTRING(thousandsSep); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5018 |
__AT_PUT_(info, @symbol(thousandsSeparator), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5019 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5020 |
if (intCurrencySymbol) { |
830 | 5021 |
val = __MKSTRING(intCurrencySymbol); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5022 |
__AT_PUT_(info, @symbol(internationCurrencySymbol), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5023 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5024 |
if (currencySymbol) { |
830 | 5025 |
val = __MKSTRING(currencySymbol); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5026 |
__AT_PUT_(info, @symbol(currencySymbol), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5027 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5028 |
if (monDecimalPoint) { |
830 | 5029 |
val = __MKSTRING(monDecimalPoint); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5030 |
__AT_PUT_(info, @symbol(monetaryDecimalPoint), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5031 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5032 |
if (monThousandsSep) { |
830 | 5033 |
val = __MKSTRING(monThousandsSep); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5034 |
__AT_PUT_(info, @symbol(monetaryThousandsSeparator), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5035 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5036 |
if (positiveSign) { |
830 | 5037 |
val = __MKSTRING(positiveSign); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5038 |
__AT_PUT_(info, @symbol(positiveSign), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5039 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5040 |
if (negativeSign) { |
830 | 5041 |
val = __MKSTRING(negativeSign); |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5042 |
__AT_PUT_(info, @symbol(negativeSign), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5043 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5044 |
if (intFractDigits >= 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5045 |
__AT_PUT_(info, @symbol(internationalFractionalDigits), __MKSMALLINT(intFractDigits)); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5046 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5047 |
if (fractDigits >= 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5048 |
__AT_PUT_(info, @symbol(fractionalDigits), __MKSMALLINT(fractDigits)); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5049 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5050 |
if (csPosPrecedes >= 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5051 |
if (csPosPrecedes == 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5052 |
val = false; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5053 |
} else { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5054 |
val = true; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5055 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5056 |
__AT_PUT_(info, @symbol(positiveSignPrecedesCurrencySymbol), val ); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5057 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5058 |
if (csNegPrecedes >= 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5059 |
if (csNegPrecedes == 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5060 |
val = false; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5061 |
} else { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5062 |
val = true; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5063 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5064 |
__AT_PUT_(info, @symbol(negativeSignPrecedesCurrencySymbol), val ); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5065 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5066 |
if (csPosSepBySpace >= 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5067 |
if (csPosSepBySpace == 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5068 |
val = false; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5069 |
} else { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5070 |
val = true; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5071 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5072 |
__AT_PUT_(info, @symbol(positiveSignSeparatedBySpaceFromCurrencySymbol), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5073 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5074 |
if (csNegSepBySpace >= 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5075 |
if (csNegSepBySpace == 0) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5076 |
val = false; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5077 |
} else { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5078 |
val = true; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5079 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5080 |
__AT_PUT_(info, @symbol(negativeSignSeparatedBySpaceFromCurrencySymbol), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5081 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5082 |
switch (csPosSignPosition) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5083 |
case 0: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5084 |
val = @symbol(parenthesesAround); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5085 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5086 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5087 |
case 1: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5088 |
val = @symbol(signPrecedes); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5089 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5090 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5091 |
case 2: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5092 |
val = @symbol(signSuceeds); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5093 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5094 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5095 |
case 3: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5096 |
val = @symbol(signPrecedesCurrencySymbol); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5097 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5098 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5099 |
case 4: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5100 |
val = @symbol(signSuceedsCurrencySymbol); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5101 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5102 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5103 |
default: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5104 |
val = nil; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5105 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5106 |
if (val != nil) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5107 |
__AT_PUT_(info, @symbol(positiveSignPosition), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5108 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5109 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5110 |
switch (csNegSignPosition) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5111 |
case 0: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5112 |
val = @symbol(parenthesesAround); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5113 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5114 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5115 |
case 1: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5116 |
val = @symbol(signPrecedes); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5117 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5118 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5119 |
case 2: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5120 |
val = @symbol(signSuceeds); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5121 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5122 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5123 |
case 3: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5124 |
val = @symbol(signPrecedesCurrencySymbol); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5125 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5126 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5127 |
case 4: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5128 |
val = @symbol(signSuceedsCurrencySymbol); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5129 |
break; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5130 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5131 |
default: |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5132 |
val = nil; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5133 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5134 |
if (val != nil) { |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5135 |
__AT_PUT_(info, @symbol(negativeSignPosition), val); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5136 |
} |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5137 |
%}. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5138 |
^ info |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5139 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5140 |
" |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5141 |
OperatingSystem getLocaleInfo |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5142 |
" |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5143 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5144 |
"Created: 23.12.1995 / 14:19:20 / cg" |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5145 |
! |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5146 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5147 |
setLocaleInfo:anInfoDictionary |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5148 |
"set the locale information; if set, this oerrides the OS's settings. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5149 |
(internal in ST/X only - the OS's settings remain unaffected) |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5150 |
See description of fields in #getLocaleInfo. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5151 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5152 |
Notice, that (for now), the system does not use this information; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5153 |
it should be used by applications as required." |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5154 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5155 |
LocaleInfo := anInfoDictionary |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5156 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5157 |
" |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5158 |
|d| |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5159 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5160 |
d := IdentityDictionary new. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5161 |
d at:#decimalPoint put:'.' . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5162 |
d at:#thousandsSeparator put:',' . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5163 |
d at:#currencySymbol put:'USD' . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5164 |
d at:#monetaryDecimalPoint put:'.' . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5165 |
d at:#monetaryThousandsSeparator put:'.' . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5166 |
d at:#fractionalDigits put:2 . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5167 |
d at:#positiveSign put:'+' . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5168 |
d at:#negativeSign put:'-' . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5169 |
d at:#positiveSignPrecedesCurrencySymbol put:true . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5170 |
d at:#negativeSignPrecedesCurrencySymbol put:false . |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5171 |
OperatingSystem setLocaleInfo:d |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5172 |
" |
616 | 5173 |
! ! |
5174 |
||
5175 |
!OperatingSystem class methodsFor:'shared memory access'! |
|
5176 |
||
5177 |
shmAttach:id address:addr flags:flags |
|
5178 |
%{ /* NOCONTEXT */ |
|
5179 |
#ifdef WANT_SHM |
|
5180 |
void *address, *shmaddr; |
|
5181 |
int shmflg, shmid; |
|
5182 |
||
5183 |
if (__isSmallInteger(addr) |
|
5184 |
&& __bothSmallInteger(flags, id)) { |
|
5185 |
shmaddr = (void *) __intVal(addr); |
|
5186 |
shmflg = __intVal(flags); |
|
5187 |
shmid = __intVal(id); |
|
5188 |
||
5189 |
address = shmat(shmid, shmaddr, shmflg); |
|
5190 |
if (address != (void *)-1) { |
|
5191 |
RETURN (__MKEXTERNALBYTES(addr)); |
|
5192 |
} |
|
5193 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
5194 |
RETURN (nil); |
|
5195 |
} |
|
5196 |
#endif |
|
5197 |
%}. |
|
792 | 5198 |
^ self primitiveFailed |
370 | 5199 |
! |
5200 |
||
616 | 5201 |
shmDetach:addr |
5202 |
%{ /* NOCONTEXT */ |
|
5203 |
#ifdef WANT_SHM |
|
5204 |
void *shmaddr; |
|
5205 |
int rslt; |
|
5206 |
||
5207 |
if (__isSmallInteger(addr)) { |
|
5208 |
shmaddr = (void *) __intVal(addr); |
|
5209 |
||
5210 |
rslt = shmdt(shmaddr); |
|
5211 |
if (rslt != -1) { |
|
5212 |
RETURN (true); |
|
370 | 5213 |
} |
616 | 5214 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
5215 |
RETURN (false); |
|
370 | 5216 |
} |
616 | 5217 |
#endif |
5218 |
%}. |
|
792 | 5219 |
^ self primitiveFailed |
616 | 5220 |
! |
5221 |
||
5222 |
shmGet:key size:size flags:flags |
|
5223 |
"low level entry to shmget system call. |
|
5224 |
This is not for public use |
|
5225 |
- use the provided wrapper class SharedExternalBytes instead." |
|
5226 |
||
5227 |
%{ /* NOCONTEXT */ |
|
5228 |
#ifdef WANT_SHM |
|
5229 |
if (__bothSmallInteger(key, size) |
|
5230 |
&& __isSmallInteger(flags)) { |
|
5231 |
int rslt; |
|
5232 |
||
5233 |
rslt = shmget(__intVal(key), __intVal(size), __intVal(flags)); |
|
5234 |
if (rslt != -1) { |
|
5235 |
RETURN (__MKSMALLINT(rslt)); |
|
5236 |
} |
|
5237 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
5238 |
RETURN (nil); |
|
5239 |
} |
|
5240 |
#endif |
|
370 | 5241 |
%}. |
792 | 5242 |
^ self primitiveFailed |
1 | 5243 |
! ! |
5244 |
||
5245 |
!OperatingSystem class methodsFor:'time and date'! |
|
5246 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5247 |
computeDatePartsOf:osTimeLow and:osTimeHi for:aBlock |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5248 |
"compute year, month and day from the OS time-parts osTimeLow and |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5249 |
osTimeHi and evaluate the argument, a 3-arg block with these. |
241 | 5250 |
Conversion is to localtime including any daylight saving adjustments. |
63 | 5251 |
|
5252 |
This method was added to avoid LargeInteger arithmetic and to be |
|
5253 |
independent of how the OperatingSystem represents time; |
|
5254 |
the time-parts expected are those returned by getTimeParts." |
|
1 | 5255 |
|
5256 |
|year month day| |
|
5257 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5258 |
((osTimeLow isMemberOf:SmallInteger) |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5259 |
and:[osTimeHi isMemberOf:SmallInteger]) ifFalse:[ |
185 | 5260 |
^ self primitiveFailed |
1 | 5261 |
]. |
5262 |
%{ |
|
5263 |
struct tm *tmPtr; |
|
5264 |
long t; |
|
5265 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5266 |
t = (_intVal(osTimeHi) << 16) | _intVal(osTimeLow); |
1 | 5267 |
tmPtr = localtime(&t); |
5268 |
year = _MKSMALLINT(tmPtr->tm_year + 1900); |
|
5269 |
month = _MKSMALLINT(tmPtr->tm_mon + 1); |
|
5270 |
day = _MKSMALLINT(tmPtr->tm_mday); |
|
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5271 |
%}. |
1 | 5272 |
aBlock value:year value:month value:day |
5273 |
! |
|
5274 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5275 |
computeDatePartsOf:osTimeParts for:aBlock |
616 | 5276 |
"compute year, month and day from the ostime in timeParts, |
5277 |
and evaluate the argument, a 3-arg block with these. |
|
5278 |
Conversion is to localtime including any daylight saving adjustments." |
|
5279 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5280 |
^ self |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5281 |
computeDatePartsOf:(osTimeParts at:1) |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5282 |
and:(osTimeParts at:2) |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5283 |
for:aBlock |
1 | 5284 |
! |
5285 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5286 |
computeTimeAndDateFrom:osTimeParts |
63 | 5287 |
"given an Array containing the OS-dependent time, return an Array |
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5288 |
containing year, month, day, hour, minute and seconds, |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5289 |
offset to UTC and a daylight savings time flag. |
241 | 5290 |
Conversion is to localtime including any daylight saving adjustments." |
63 | 5291 |
|
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5292 |
|low hi year month day hours minutes seconds utcOffset dst ret| |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5293 |
|
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5294 |
low := osTimeParts at:1. |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5295 |
hi := osTimeParts at:2. |
63 | 5296 |
%{ |
5297 |
struct tm *tmPtr; |
|
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5298 |
struct tm *gmTmPtr; |
63 | 5299 |
long t; |
5300 |
||
811 | 5301 |
#ifdef ultrix /* mhmh - isnt this ifdef BSD ? */ |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5302 |
# define TIMEZONE tmPtr->tm_gmtoff |
811 | 5303 |
#else |
831 | 5304 |
# ifdef MSDOS_LIKE |
5305 |
define TIMEZONE 0 |
|
5306 |
# else |
|
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5307 |
# define TIMEZONE timezone |
831 | 5308 |
# endif |
811 | 5309 |
#endif |
5310 |
||
252 | 5311 |
if (__bothSmallInteger(low, hi)) { |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5312 |
t = (_intVal(hi) << 16) | _intVal(low); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5313 |
tmPtr = localtime(&t); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5314 |
hours = _MKSMALLINT(tmPtr->tm_hour); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5315 |
minutes = _MKSMALLINT(tmPtr->tm_min); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5316 |
seconds = _MKSMALLINT(tmPtr->tm_sec); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5317 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5318 |
year = _MKSMALLINT(tmPtr->tm_year + 1900); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5319 |
month = _MKSMALLINT(tmPtr->tm_mon + 1); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5320 |
day = _MKSMALLINT(tmPtr->tm_mday); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5321 |
|
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5322 |
if (tmPtr->tm_isdst == 0) { |
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5323 |
dst = false; |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5324 |
utcOffset = _MKSMALLINT(TIMEZONE); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5325 |
} else { |
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5326 |
dst = true; |
800
067094efdaed
use HAS_ALTZONE / HAS_DAYLIGHT
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
5327 |
#ifdef HAS_ALTZONE |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5328 |
utcOffset = _MKSMALLINT(altzone); |
800
067094efdaed
use HAS_ALTZONE / HAS_DAYLIGHT
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
5329 |
#else |
811 | 5330 |
utcOffset = _MKSMALLINT(TIMEZONE) + 3600; |
800
067094efdaed
use HAS_ALTZONE / HAS_DAYLIGHT
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
5331 |
#endif |
067094efdaed
use HAS_ALTZONE / HAS_DAYLIGHT
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
5332 |
} |
63 | 5333 |
} |
241 | 5334 |
%}. |
63 | 5335 |
year notNil ifTrue:[ |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5336 |
"I would love to have SELF-like inline objects ..." |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5337 |
ret := Array new:8. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5338 |
ret at:1 put:year. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5339 |
ret at:2 put:month. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5340 |
ret at:3 put:day. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5341 |
ret at:4 put:hours. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5342 |
ret at:5 put:minutes. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5343 |
ret at:6 put:seconds. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5344 |
ret at:7 put:utcOffset. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5345 |
ret at:8 put:dst. |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
5346 |
^ ret |
63 | 5347 |
]. |
5348 |
^ self primitiveFailed |
|
5349 |
! |
|
5350 |
||
241 | 5351 |
computeTimePartsFromYear:y month:m day:d hour:h minute:min seconds:s |
5352 |
"return an Array containing the OS-dependent time for the given |
|
5353 |
time and day. The arguments are assumed to be in localtime including |
|
5354 |
any daylight saving adjustings." |
|
5355 |
||
5356 |
|low hi| |
|
5357 |
||
5358 |
%{ |
|
5359 |
struct tm tm; |
|
5360 |
long t; |
|
5361 |
||
252 | 5362 |
if (__bothSmallInteger(y, m) |
5363 |
&& __bothSmallInteger(d, h) |
|
5364 |
&& __bothSmallInteger(min, s)) { |
|
5365 |
tm.tm_hour = __intVal(h); |
|
5366 |
tm.tm_min = __intVal(min); |
|
5367 |
tm.tm_sec = __intVal(s); |
|
5368 |
||
5369 |
tm.tm_year = __intVal(y) - 1900; |
|
5370 |
tm.tm_mon = __intVal(m) - 1; |
|
5371 |
tm.tm_mday = __intVal(d); |
|
241 | 5372 |
tm.tm_isdst = -1; |
5373 |
||
5374 |
t = mktime(&tm); |
|
5375 |
low = _MKSMALLINT(t & 0xFFFF); |
|
5376 |
hi = _MKSMALLINT((t >> 16) & 0xFFFF); |
|
5377 |
} |
|
5378 |
%}. |
|
5379 |
low notNil ifTrue:[ |
|
5380 |
^ Array with:low with:hi |
|
5381 |
]. |
|
5382 |
^ self primitiveFailed |
|
5383 |
! |
|
5384 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5385 |
computeTimePartsOf:osTimeLow and:osTimeHi for:aBlock |
616 | 5386 |
"compute hours, minutes and seconds from the time-parts timeLow and |
5387 |
timeHi and evaluate the argument, a 3-arg block with these. |
|
5388 |
Conversion is to localtime including any daylight saving adjustments. |
|
5389 |
||
5390 |
This method was added to avoid LargeInteger arithmetic and to be |
|
5391 |
independent of how the OperatingSystem represents time; |
|
5392 |
the time-parts expected are those returned by getTimeParts." |
|
5393 |
||
5394 |
|hours minutes seconds| |
|
5395 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5396 |
((osTimeLow isMemberOf:SmallInteger) |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5397 |
and:[osTimeHi isMemberOf:SmallInteger]) ifFalse:[ |
616 | 5398 |
^ self primitiveFailed |
5399 |
]. |
|
5400 |
%{ |
|
5401 |
struct tm *tmPtr; |
|
5402 |
long t; |
|
5403 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5404 |
t = (_intVal(osTimeHi) << 16) | _intVal(osTimeLow); |
616 | 5405 |
tmPtr = localtime(&t); |
5406 |
hours = _MKSMALLINT(tmPtr->tm_hour); |
|
5407 |
minutes = _MKSMALLINT(tmPtr->tm_min); |
|
5408 |
seconds = _MKSMALLINT(tmPtr->tm_sec); |
|
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5409 |
%}. |
616 | 5410 |
aBlock value:hours value:minutes value:seconds |
5411 |
! |
|
5412 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5413 |
computeTimePartsOf:osTimeParts for:aBlock |
616 | 5414 |
"compute hour, minute and seconds from the ostime in timeParts, |
5415 |
and evaluate the argument, a 3-arg block with these. |
|
5416 |
Conversion is to localtime including any daylight saving adjustments." |
|
5417 |
||
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5418 |
^ self |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5419 |
computeTimePartsOf:(osTimeParts at:1) |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5420 |
and:(osTimeParts at:2) |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5421 |
for:aBlock |
275 | 5422 |
! |
5423 |
||
1 | 5424 |
getMillisecondTime |
185 | 5425 |
"This returns the millisecond timers value. |
5426 |
The range is limited to 0..1fffffff (i.e. the SmallInteger range) to avoid |
|
5427 |
LargeInteger arithmetic when doing timeouts and delays. |
|
792 | 5428 |
Since this value is wrapping around in regular intervals, this can only be used for |
185 | 5429 |
short relative time deltas. |
5430 |
Use the millisecondTimeXXX:-methods to compare and add time deltas - these know about the wrap. |
|
5431 |
||
5432 |
BAD DESIGN: |
|
5433 |
This should be changed to return some instance of RelativeTime, |
|
5434 |
and these computations moved there. |
|
95 | 5435 |
|
5436 |
Dont use this method in application code since it is an internal (private) |
|
5437 |
interface. For compatibility with ST-80, use Time millisecondClockValue. |
|
5438 |
" |
|
1 | 5439 |
|
5440 |
%{ /* NOCONTEXT */ |
|
5441 |
||
5442 |
long t; |
|
185 | 5443 |
#if !defined(HAS_GETTIMEOFDAY) && defined(SYSV) && defined(HZ) |
5444 |
/* |
|
5445 |
* sys5 time |
|
5446 |
*/ |
|
1 | 5447 |
long ticks; |
5448 |
struct tms tb; |
|
5449 |
||
5450 |
ticks = times(&tb); |
|
5451 |
t = (ticks * 1000) / HZ; |
|
792 | 5452 |
#else |
5453 |
# ifdef MSDOS_LIKE |
|
5454 |
struct _timeb timebuffer; |
|
5455 |
||
5456 |
_ftime(&timebuffer); |
|
5457 |
t = (timebuffer.time * 1000) + timebuffer.millitm; |
|
5458 |
# else /* assume HAS_GETTIMEOFDAY */ |
|
185 | 5459 |
/* |
5460 |
* bsd time |
|
5461 |
*/ |
|
1 | 5462 |
struct timeval tb; |
5463 |
struct timezone tzb; |
|
5464 |
||
5465 |
gettimeofday(&tb, &tzb); |
|
5466 |
t = tb.tv_sec*1000 + tb.tv_usec/1000; |
|
792 | 5467 |
# endif |
68 | 5468 |
#endif |
185 | 5469 |
RETURN ( _MKSMALLINT(t & 0x1FFFFFFF) ); |
1 | 5470 |
%} |
5471 |
! |
|
5472 |
||
616 | 5473 |
getTime |
5474 |
"return current Time in some OS dependent representation. |
|
5475 |
(on unix, its the seconds since 1970). |
|
5476 |
||
831 | 5477 |
WARNING: |
5478 |
this is OperatingSystem dependent |
|
5479 |
- for portable code, use getTimeParts and compute*PartsOf:and:for:. |
|
5480 |
Better yet, use Date>>today or Time>>now for fully ST-80 compatible code." |
|
5481 |
||
5482 |
^ (OperatingSystem getTimeInto:[:low :hi | hi*16r10000 + low]) |
|
616 | 5483 |
|
5484 |
" |
|
5485 |
OperatingSystem getTime |
|
5486 |
" |
|
5487 |
! |
|
5488 |
||
5489 |
getTimeHi |
|
5490 |
"return hi 16 bits of current time. |
|
5491 |
||
5492 |
OBSOLETE: Dont use this method, use getTimeParts. |
|
5493 |
This method will NOT always return the correct time |
|
5494 |
if used together with getTimeHi, since a wrap between |
|
5495 |
the two getTimeXXX sends could occur. |
|
5496 |
WARNING: this method will vanish - dont use it." |
|
5497 |
||
5498 |
%{ /* NOCONTEXT */ |
|
5499 |
||
5500 |
RETURN ( _MKSMALLINT((time(0) >> 16) & 0xFFFF) ); |
|
5501 |
%} |
|
5502 |
||
5503 |
"OperatingSystem getTimeHi" |
|
5504 |
! |
|
5505 |
||
5506 |
getTimeInto:aBlock |
|
5507 |
"evaluate the argument aBlock, passing the time-parts of |
|
5508 |
the current time as arguments. |
|
5509 |
See comment in 'OperatingSystem>>getTimeParts' on what to |
|
5510 |
do with those parts." |
|
5511 |
||
5512 |
|low hi| |
|
5513 |
%{ |
|
5514 |
int now; |
|
5515 |
||
5516 |
now = time(0); |
|
5517 |
hi = _MKSMALLINT((now >> 16) & 0xFFFF); |
|
5518 |
low = _MKSMALLINT(now & 0xFFFF); |
|
831 | 5519 |
%}. |
5520 |
^ aBlock value:low value:hi |
|
5521 |
||
5522 |
" |
|
5523 |
OperatingSystem getTimeInto:[:low :hi | low printNewline. hi printNewline] |
|
5524 |
" |
|
616 | 5525 |
! |
5526 |
||
5527 |
getTimeLow |
|
5528 |
"return low 16 bits of current time. |
|
5529 |
||
5530 |
OBSOLETE: Dont use this method, use getTimeParts. |
|
5531 |
This method will not always return the correct time |
|
5532 |
if used together with getTimeHi, since a wrap between |
|
5533 |
the two getTimeXXX sends could occur. |
|
5534 |
WARNING: this method will vanish - dont use it." |
|
5535 |
||
5536 |
%{ /* NOCONTEXT */ |
|
5537 |
||
5538 |
RETURN ( _MKSMALLINT(time(0) & 0xFFFF) ); |
|
5539 |
%} |
|
5540 |
||
831 | 5541 |
" |
5542 |
OperatingSystem getTimeLow |
|
5543 |
" |
|
616 | 5544 |
! |
5545 |
||
5546 |
getTimeParts |
|
5547 |
"return the current time as an array of 2 integers representing |
|
5548 |
the current time (usually low 16bits / hi 16 bits) in some OS |
|
5549 |
dependent way. |
|
5550 |
||
5551 |
On unix, the values represent the seconds since 1970, on other |
|
5552 |
systems this may be different. |
|
5553 |
WARNING: |
|
5554 |
for portability, never use these values directly, but pass them |
|
5555 |
to #computeTimeParts and/or #computeDatePartsOf:, which know how to |
|
5556 |
interpret them. |
|
5557 |
Better yet, use Date>>today and Time>>now for ST-80 compatibility." |
|
5558 |
||
5559 |
|low hi| |
|
5560 |
%{ |
|
5561 |
int now; |
|
5562 |
||
5563 |
now = time(0); |
|
5564 |
hi = _MKSMALLINT((now >> 16) & 0xFFFF); |
|
5565 |
low = _MKSMALLINT(now & 0xFFFF); |
|
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5566 |
%}. |
616 | 5567 |
^ Array with:low with:hi |
5568 |
||
831 | 5569 |
" |
5570 |
OperatingSystem getTimeParts |
|
5571 |
" |
|
616 | 5572 |
! |
5573 |
||
5574 |
maximumMillisecondTimeDelta |
|
5575 |
"this returns the maximum delta supported by millisecondCounter |
|
5576 |
based methods. The returned value is half the value at which the |
|
5577 |
timer wraps." |
|
5578 |
||
5579 |
%{ /* NOCONTEXT */ |
|
5580 |
RETURN ( _MKSMALLINT(0x0FFFFFFF) ); |
|
5581 |
%} |
|
5582 |
! |
|
5583 |
||
5584 |
millisecondDelay:millis |
|
5585 |
"delay execution for millis milliseconds or until the next event |
|
5586 |
arrives. |
|
5587 |
All lower priority threads will also sleep for the duration, |
|
5588 |
interrupts (and therefore, higher prio processes) are |
|
5589 |
still handled. |
|
5590 |
Better use a Delay, to only delay the calling thread. |
|
5591 |
(however, a delay cannot be used in the event handler or scheduler)" |
|
5592 |
||
5593 |
|now then delta| |
|
5594 |
||
831 | 5595 |
%{ /* NOCONTEXT */ |
5596 |
#ifdef WIN32 |
|
5597 |
int t = __intVal(millis); |
|
5598 |
||
5599 |
if (t) { |
|
5600 |
Sleep(t); |
|
5601 |
} |
|
5602 |
RETURN (self); |
|
5603 |
#endif |
|
5604 |
%}. |
|
5605 |
||
616 | 5606 |
now := OperatingSystem getMillisecondTime. |
5607 |
then := OperatingSystem millisecondTimeAdd:now and:millis. |
|
5608 |
||
5609 |
[OperatingSystem millisecondTime:then isAfter:now] whileTrue:[ |
|
5610 |
delta := OperatingSystem millisecondTimeDeltaBetween:then and:now. |
|
5611 |
self selectOnAnyReadable:nil writable:nil exception:nil withTimeOut:delta. |
|
5612 |
now := OperatingSystem getMillisecondTime. |
|
5613 |
] |
|
5614 |
||
5615 |
" |
|
5616 |
OperatingSystem millisecondDelay:2000 |
|
5617 |
" |
|
5618 |
! |
|
5619 |
||
5620 |
millisecondTime:msTime1 isAfter:msTime2 |
|
5621 |
"return true if msTime1 is after msTime2, false if not. |
|
5622 |
The two arguments are supposed to be millisecond times |
|
5623 |
(such as returned getMillisecondTime) which wrap at 16r1FFFFFFF. |
|
5624 |
||
5625 |
This should really be moved to some RelativeTime class." |
|
5626 |
||
5627 |
(msTime1 > msTime2) ifTrue:[ |
|
5628 |
((msTime1 - msTime2) >= 16r10000000) ifTrue:[ |
|
5629 |
^ false |
|
5630 |
]. |
|
5631 |
^ true |
|
5632 |
]. |
|
5633 |
((msTime2 - msTime1) > 16r10000000) ifTrue:[ |
|
5634 |
^ true |
|
5635 |
]. |
|
5636 |
^ false |
|
5637 |
! |
|
5638 |
||
5639 |
millisecondTimeAdd:msTime1 and:msTime2 |
|
5640 |
"Add two millisecond times (such as returned getMillisecondTime). |
|
5641 |
The returned value is msTime1 + msTime2 where a wrap occurs at:16r1FFFFFFF. |
|
5642 |
||
5643 |
This should really be moved to some RelativeTime class." |
|
5644 |
||
5645 |
|sum| |
|
5646 |
||
5647 |
sum := msTime1 + msTime2. |
|
5648 |
(sum > 16r1FFFFFFF) ifTrue:[^ sum - 16r20000000]. |
|
5649 |
(sum < 0) ifTrue:[^ sum + 16r20000000]. |
|
5650 |
^ sum |
|
5651 |
! |
|
5652 |
||
1 | 5653 |
millisecondTimeDeltaBetween:msTime1 and:msTime2 |
95 | 5654 |
"subtract two millisecond times (such as returned getMillisecondTime) |
185 | 5655 |
and return the difference. Since milli-times wrap (at 16r01FFFFFFF), |
95 | 5656 |
some special handling is built-in here. |
185 | 5657 |
The returned value is msTime1 - msTime2. The returned value is invalid |
5658 |
if the delta is >= 0x10000000. |
|
63 | 5659 |
|
810
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5660 |
This should really be moved to some RelativeTime class; |
9b3676f51220
mhmh - even though ultrix defines daylight,
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5661 |
better yet: create a subclass of Integer named LimitedRangeInteger." |
1 | 5662 |
|
5663 |
(msTime1 > msTime2) ifTrue:[ |
|
185 | 5664 |
^ msTime1 - msTime2 |
1 | 5665 |
]. |
5666 |
^ msTime1 + 16r10000000 - msTime2 |
|
95 | 5667 |
|
5668 |
" |
|
5669 |
OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1 |
|
5670 |
OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:(16 / 3) |
|
5671 |
OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1000 |
|
5672 |
||
5673 |
OperatingSystem millisecondTimeDeltaBetween:0 and:16r0FFFFFFF |
|
5674 |
OperatingSystem millisecondTimeDeltaBetween:(13/3) and:16r0FFFFFFF |
|
5675 |
OperatingSystem millisecondTimeDeltaBetween:999 and:16r0FFFFFFF |
|
5676 |
||
5677 |
OperatingSystem millisecondTime:0 isAfter:16r0FFFFFFF |
|
5678 |
OperatingSystem millisecondTime:(13/3) isAfter:16r0FFFFFFF |
|
5679 |
OperatingSystem millisecondTime:999 isAfter:16r0FFFFFFF |
|
5680 |
||
5681 |
OperatingSystem millisecondTime:0 isAfter:0 |
|
5682 |
OperatingSystem millisecondTime:(13/3) isAfter:0 |
|
5683 |
OperatingSystem millisecondTime:999 isAfter:0 |
|
5684 |
||
5685 |
OperatingSystem millisecondTime:1 isAfter:0 |
|
5686 |
OperatingSystem millisecondTime:(13/3) isAfter:2 |
|
5687 |
OperatingSystem millisecondTime:999 isAfter:900 |
|
5688 |
||
5689 |
|t1 t2| |
|
5690 |
||
5691 |
t1 := Time millisecondClockValue. |
|
5692 |
(Delay forMilliseconds:1) wait. |
|
5693 |
t2 := Time millisecondClockValue. |
|
5694 |
OperatingSystem millisecondTimeDeltaBetween:t2 and:t1 |
|
5695 |
" |
|
1 | 5696 |
! |
5697 |
||
5698 |
sleep:numberOfSeconds |
|
308 | 5699 |
"cease ANY action for some time. This suspends the whole smalltalk |
5700 |
(unix-) process for some time. |
|
1 | 5701 |
Not really useful since not even low-prio processes and interrupt |
95 | 5702 |
handling will run during the sleep. |
5703 |
Use either OperatingSystem>>millisecondDelay: (which makes all |
|
5704 |
threads sleep, but handles interrupts) or use a Delay (which makes |
|
5705 |
only the calling thread sleep)." |
|
1 | 5706 |
|
5707 |
%{ /* NOCONTEXT */ |
|
5708 |
||
252 | 5709 |
if (__isSmallInteger(numberOfSeconds)) { |
185 | 5710 |
sleep(_intVal(numberOfSeconds)); |
5711 |
RETURN ( self ); |
|
1 | 5712 |
} |
68 | 5713 |
%}. |
5714 |
" |
|
5715 |
argument not integer |
|
5716 |
" |
|
792 | 5717 |
^ self primitiveFailed |
95 | 5718 |
|
5719 |
" |
|
5720 |
OperatingSystem sleep:2 |
|
5721 |
" |
|
10 | 5722 |
! ! |
5723 |
||
616 | 5724 |
!OperatingSystem class methodsFor:'users & groups'! |
5725 |
||
5726 |
getEffectiveGroupID |
|
5727 |
"return the current users (thats you) effective numeric group id. |
|
5728 |
This is only different from getGroupID, if you have ST/X running |
|
5729 |
as a setuid program (of which you should think about twice)." |
|
5730 |
||
5731 |
%{ /* NOCONTEXT */ |
|
5732 |
||
5733 |
#ifdef UNIX_LIKE |
|
5734 |
int uid; |
|
5735 |
||
5736 |
uid = getegid(); |
|
5737 |
RETURN ( __MKSMALLINT(uid) ); |
|
5738 |
#endif |
|
5739 |
/* --- return same as getGroupID --- */ |
|
5740 |
%}. |
|
5741 |
^ self getGroupID |
|
5742 |
||
5743 |
" |
|
5744 |
OperatingSystem getEffectiveGroupID |
|
5745 |
" |
|
5746 |
! |
|
5747 |
||
5748 |
getEffectiveUserID |
|
5749 |
"return the current users (thats you) effective numeric user id. |
|
5750 |
This is only different from getUserID, if you have ST/X running |
|
5751 |
as a setuid program (of which you should think about twice)." |
|
10 | 5752 |
|
5753 |
%{ /* NOCONTEXT */ |
|
5754 |
||
616 | 5755 |
#ifdef UNIX_LIKE |
5756 |
int uid; |
|
5757 |
||
5758 |
uid = geteuid(); |
|
5759 |
RETURN ( __MKSMALLINT(uid) ); |
|
5760 |
#endif |
|
5761 |
/* --- return same as getUserID --- */ |
|
5762 |
%}. |
|
5763 |
^ self getUserID |
|
5764 |
||
5765 |
" |
|
5766 |
OperatingSystem getEffectiveUserID |
|
5767 |
" |
|
5768 |
! |
|
5769 |
||
5770 |
getGroupID |
|
5771 |
"return the current users (thats you) numeric group id" |
|
5772 |
||
5773 |
%{ /* NOCONTEXT */ |
|
5774 |
||
5775 |
#ifdef UNIX_LIKE |
|
5776 |
int uid; |
|
5777 |
||
5778 |
uid = getgid(); |
|
5779 |
RETURN ( __MKSMALLINT(uid) ); |
|
5780 |
#else |
|
5781 |
# ifdef SYSTEM_HAS_GROUPS |
|
5782 |
/* ... */ |
|
10 | 5783 |
# endif |
5784 |
#endif |
|
68 | 5785 |
%}. |
616 | 5786 |
^ 1 "just a dummy for systems which do not have userIDs" |
5787 |
||
68 | 5788 |
" |
616 | 5789 |
OperatingSystem getGroupID |
5790 |
" |
|
5791 |
! |
|
5792 |
||
5793 |
getGroupNameFromID:aNumber |
|
5794 |
"return the group-name-string for a given numeric group-id" |
|
5795 |
||
5796 |
%{ /* NOCONTEXT */ |
|
5797 |
||
5798 |
#ifdef UNIX_LIKE |
|
5799 |
struct group *g; |
|
5800 |
||
5801 |
if (__isSmallInteger(aNumber)) { |
|
5802 |
g = getgrgid(_intVal(aNumber)); |
|
5803 |
if (g) { |
|
830 | 5804 |
RETURN ( __MKSTRING(g->gr_name COMMA_CON) ); |
616 | 5805 |
} |
5806 |
} |
|
5807 |
#endif |
|
5808 |
%}. |
|
5809 |
^ '???' |
|
5810 |
||
5811 |
" |
|
5812 |
OperatingSystem getGroupNameFromID:0 |
|
5813 |
OperatingSystem getGroupNameFromID:10 |
|
5814 |
" |
|
5815 |
! |
|
5816 |
||
5817 |
getHomeDirectory |
|
5818 |
"return the name of the users home directory" |
|
5819 |
||
5820 |
^ OperatingSystem getEnvironment:'HOME' |
|
5821 |
||
5822 |
" |
|
5823 |
OperatingSystem getHomeDirectory |
|
5824 |
" |
|
5825 |
! |
|
5826 |
||
5827 |
getLoginName |
|
5828 |
"return a string with the users name" |
|
5829 |
||
5830 |
%{ /* NOCONTEXT */ |
|
5831 |
static char cachedName[64]; |
|
5832 |
static firstCall = 1; |
|
5833 |
||
831 | 5834 |
char *name = (char *)0; |
616 | 5835 |
#ifdef UNIX_LIKE |
5836 |
if (firstCall) { |
|
5837 |
name = (char *)getlogin(); |
|
5838 |
if (! name || (name[0] == 0)) { |
|
5839 |
name = (char *)getenv("LOGNAME"); |
|
5840 |
} |
|
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
827
diff
changeset
|
5841 |
if (name && (strlen(name) < sizeof(cachedName))) { |
616 | 5842 |
strcpy(cachedName, name); |
5843 |
firstCall = 0; |
|
5844 |
} |
|
5845 |
} else { |
|
5846 |
name = cachedName; |
|
5847 |
} |
|
831 | 5848 |
#else |
5849 |
# ifdef MSDOS_LIKE |
|
5850 |
if (firstCall) { |
|
5851 |
int nameSize = sizeof(cachedName); |
|
5852 |
||
5853 |
if (GetUserName(cachedName, &nameSize) == TRUE) { |
|
5854 |
name = cachedName; |
|
5855 |
firstCall = 0; |
|
5856 |
} |
|
5857 |
} else { |
|
5858 |
name = cachedName; |
|
5859 |
} |
|
5860 |
# endif |
|
5861 |
#endif |
|
5862 |
if (! name || (name[0] == 0) ) { |
|
5863 |
name = (char *)getenv("LOGNAME"); |
|
5864 |
} |
|
5865 |
if (! name || (name[0] == 0) ) { |
|
5866 |
name = "you"; |
|
5867 |
} |
|
5868 |
||
830 | 5869 |
RETURN ( __MKSTRING(name COMMA_CON) ); |
831 | 5870 |
%}. |
616 | 5871 |
" |
5872 |
OperatingSystem getLoginName |
|
5873 |
" |
|
5874 |
! |
|
5875 |
||
5876 |
getUserID |
|
5877 |
"return the current users (thats you) numeric user id" |
|
5878 |
||
5879 |
%{ /* NOCONTEXT */ |
|
5880 |
||
5881 |
#ifdef UNIX_LIKE |
|
5882 |
int uid; |
|
5883 |
||
5884 |
uid = getuid(); |
|
5885 |
RETURN ( __MKSMALLINT(uid) ); |
|
5886 |
#else |
|
5887 |
# ifdef SYSTEM_HAS_USERS |
|
5888 |
/* ... */ |
|
5889 |
# endif |
|
5890 |
#endif |
|
5891 |
%}. |
|
5892 |
^ 1 "just a dummy for systems which do not have userIDs" |
|
5893 |
||
5894 |
" |
|
5895 |
OperatingSystem getUserID |
|
68 | 5896 |
" |
616 | 5897 |
! |
5898 |
||
5899 |
getUserNameFromID:aNumber |
|
5900 |
"return the user-name-string for a given numeric user-id" |
|
5901 |
||
5902 |
%{ /* NOCONTEXT */ |
|
5903 |
||
5904 |
#ifdef UNIX_LIKE |
|
5905 |
struct passwd *p; |
|
5906 |
||
5907 |
if (__isSmallInteger(aNumber)) { |
|
5908 |
p = getpwuid(_intVal(aNumber)); |
|
5909 |
if (p) { |
|
830 | 5910 |
RETURN ( __MKSTRING(p->pw_name COMMA_CON) ); |
616 | 5911 |
} |
5912 |
} |
|
5913 |
#endif |
|
5914 |
%}. |
|
5915 |
^ '? (' , aNumber printString , ')' |
|
5916 |
||
5917 |
" |
|
5918 |
OperatingSystem getUserNameFromID:0 |
|
5919 |
OperatingSystem getUserNameFromID:100 |
|
5920 |
OperatingSystem getUserNameFromID:9991 |
|
5921 |
" |
|
1 | 5922 |
! |
5923 |
||
616 | 5924 |
userInfoOf:aNameOrID |
5925 |
"return a dictionary filled with userinfo. The argument can be either |
|
5926 |
a string with the users name or its numeric id. |
|
5927 |
Notice, that not all systems provide (all of) this info; |
|
5928 |
DOS systems return nothing; |
|
5929 |
non-SYSV4 systems have no age/comment. |
|
5930 |
Portable applications may want to check the systemType and NOT depend |
|
5931 |
on all keys to be present in the returned dictionary. |
|
5932 |
Another notice: on some systems (SYSV4), the gecos field includes multiple |
|
5933 |
entries (i.e. not just the name), separated by commas. You may want to |
|
5934 |
extract any substring, up to the first comma to get the real life name." |
|
5935 |
||
5936 |
|info name passw uid gid age comment |
|
5937 |
gecos dir shell| |
|
5938 |
||
5939 |
%{ |
|
5940 |
#ifdef UNIX_LIKE |
|
5941 |
struct passwd *buf; |
|
5942 |
int ret; |
|
5943 |
||
5944 |
if (__isString(aNameOrID)) { |
|
5945 |
buf = getpwnam(__stringVal(aNameOrID)); |
|
5946 |
} else if (__isSmallInteger(aNameOrID)) { |
|
5947 |
buf = getpwuid(__intVal(aNameOrID)); |
|
5948 |
} else { |
|
5949 |
buf = (struct passwd *)0; |
|
5950 |
} |
|
5951 |
if (buf) { |
|
830 | 5952 |
name = __MKSTRING(buf->pw_name COMMA_CON); |
5953 |
passw = __MKSTRING(buf->pw_passwd COMMA_CON); |
|
616 | 5954 |
# ifdef SYSV4 |
830 | 5955 |
age = __MKSTRING(buf->pw_age COMMA_CON); |
5956 |
comment = __MKSTRING(buf->pw_comment COMMA_CON); |
|
616 | 5957 |
# endif |
830 | 5958 |
dir = __MKSTRING(buf->pw_dir COMMA_CON); |
5959 |
gecos = __MKSTRING(buf->pw_gecos COMMA_CON); |
|
5960 |
shell = __MKSTRING(buf->pw_shell COMMA_CON); |
|
616 | 5961 |
|
5962 |
uid = _MKSMALLINT(buf->pw_uid); |
|
5963 |
gid = _MKSMALLINT(buf->pw_gid); |
|
5964 |
} |
|
5965 |
#endif |
|
5966 |
%}. |
|
5967 |
info := IdentityDictionary new. |
|
5968 |
name notNil ifTrue:[ |
|
5969 |
info at:#name put:name. |
|
5970 |
] ifFalse:[ |
|
5971 |
info at:#name put:'unknown' |
|
5972 |
]. |
|
5973 |
passw notNil ifTrue:[info at:#passwd put:passw]. |
|
5974 |
age notNil ifTrue:[info at:#age put:age]. |
|
5975 |
comment notNil ifTrue:[info at:#comment put:comment]. |
|
5976 |
gecos notNil ifTrue:[info at:#gecos put:gecos]. |
|
5977 |
shell notNil ifTrue:[info at:#shell put:shell]. |
|
5978 |
dir notNil ifTrue:[info at:#dir put:dir]. |
|
5979 |
uid notNil ifTrue:[info at:#uid put:uid]. |
|
5980 |
gid notNil ifTrue:[info at:#gid put:gid]. |
|
5981 |
^ info |
|
5982 |
||
5983 |
" |
|
5984 |
OperatingSystem userInfoOf:'root' |
|
5985 |
OperatingSystem userInfoOf:1 |
|
5986 |
OperatingSystem userInfoOf:'claus' |
|
5987 |
OperatingSystem userInfoOf:'fooBar' |
|
5988 |
OperatingSystem userInfoOf:(OperatingSystem getUserID) |
|
5989 |
" |
|
5990 |
! ! |
|
5991 |
||
5992 |
!OperatingSystem class methodsFor:'waiting for events'! |
|
5993 |
||
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
5994 |
blockingChildProcessWait |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
5995 |
"return true, if childProcessWait: blocks, if no childs are ready" |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
5996 |
%{ /*NOCONTEXT*/ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
5997 |
#if defined(HAS_WAITPID) || defined(HAS_WAIT3) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
5998 |
RETURN(false); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
5999 |
#else |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6000 |
RETURN(true); |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6001 |
#endif |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6002 |
%} |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6003 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6004 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6005 |
childProcessWait:blocking |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6006 |
"get status changes from child processes. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6007 |
Return an OSProcessStatus or nil, if no process has terminated. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6008 |
If blocking is true, we wait until a process changed state, |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6009 |
otherwise we return immediately." |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6010 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6011 |
|pid status code core| |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6012 |
%{ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6013 |
int p; |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6014 |
#if defined(HAS_WAITPID) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6015 |
int s; |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6016 |
# define __WAIT waitpid(-1, &s, blocking == true ? WUNTRACED : WNOHANG|WUNTRACED) |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6017 |
#else |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6018 |
# if defined(HAS_WAIT3) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6019 |
union wait s; |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6020 |
#define __WAIT wait3(&s, blocking == true ? WUNTRACED : WNOHANG|WUNTRACED, 0) |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6021 |
# else /*!HAS_WAIT3*/ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6022 |
int s; |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6023 |
# define __WAIT wait(&s) |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6024 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6025 |
# if !defined(WIFEXITED) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6026 |
# define WIFEXITED(stat) (((int)((stat)&0377))==0) |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6027 |
# define WIFSIGNALED(stat) (((int)((stat)&0377))>0&&((int)(((stat)>>8)&0377))==0) |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6028 |
# define WIFSTOPPED(stat) (((int)((stat)&0377))==0177&&((int)(((stat)>>8)&0377))!=0) |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6029 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6030 |
# define WEXITSTATUS(stat) ((int)(((stat)>>8)&0377)) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6031 |
# define WTERMSIG(stat) (((int)((stat)&0377))&0177) |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6032 |
# define WSTOPSIG(stat) ((int)(((stat)>>8)&0377)) |
843 | 6033 |
# endif /*!WIFEXITED*/ |
6034 |
# if !defined(WCOREDUMP) |
|
842
abd922d0f21e
WCOREDUMP is not defined on ULTRIX
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
6035 |
# define WCOREDUMP(stat) ((int)(((stat)>>8)&0200)) |
843 | 6036 |
# endif /*!WCOREDUMP*/ |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6037 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6038 |
if (blocking != true) { |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6039 |
/* |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6040 |
* We do not support nonBlocking waits, so signal an error |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6041 |
* Sorry about the goto, but with all these ifdefs ... |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6042 |
*/ |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6043 |
goto done; |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6044 |
} |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6045 |
# endif /*!HAS_WAIT3*/ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6046 |
#endif /*!HAS_WAITPID*/ |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6047 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6048 |
do { |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6049 |
p = __WAIT; |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6050 |
} while (p == -1 && errno == EINTR); |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6051 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6052 |
#undef __WAIT |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6053 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6054 |
if (p == 0) |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6055 |
RETURN(nil) |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6056 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6057 |
if (p == -1) { |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6058 |
if (errno == ECHILD) |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6059 |
RETURN(nil); |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6060 |
} else { |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6061 |
pid = __MKSMALLINT(p); |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6062 |
if (WIFEXITED(s)) { |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6063 |
status = @symbol(exit); |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6064 |
code = __MKSMALLINT(WEXITSTATUS(s)); |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6065 |
core = WCOREDUMP(s) ? true : false; |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6066 |
} else if (WIFSIGNALED(s)) { |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6067 |
status = @symbol(signal); |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6068 |
code = __MKSMALLINT(WTERMSIG(s)); |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6069 |
} else if (WIFSTOPPED(s)) { |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6070 |
status = @symbol(stop); |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6071 |
code = __MKSMALLINT(WSTOPSIG(s)); |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6072 |
} |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6073 |
#if defined(WIFCONTINUED) |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6074 |
else if (WIFCONTINUED(s)) { |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6075 |
status = @symbol(continue); |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6076 |
} |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6077 |
#endif |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6078 |
} |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6079 |
done: ; |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6080 |
%}. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6081 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6082 |
pid isNil ifTrue:[ |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6083 |
^ self primitiveFailed |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6084 |
]. |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6085 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6086 |
^ OSProcessStatus pid:pid status:status code:code core:core |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6087 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6088 |
" |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6089 |
OperatingSystem childProcessWait:false |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6090 |
" |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6091 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
832
diff
changeset
|
6092 |
"Created: 5.1.1996 / 16:39:14 / stefan" |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6093 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
813
diff
changeset
|
6094 |
|
10 | 6095 |
readCheck:fd |
95 | 6096 |
"return true, if data is available on a filedescriptor (i.e. read |
6097 |
is possible without blocking)" |
|
10 | 6098 |
|
6099 |
(self selectOnAnyReadable:(Array with:fd) |
|
185 | 6100 |
writable:nil |
6101 |
exception:nil |
|
6102 |
withTimeOut:0) == fd |
|
6103 |
ifTrue:[^ true]. |
|
10 | 6104 |
^ false |
6105 |
! |
|
6106 |
||
616 | 6107 |
selectOn:fd1 and:fd2 withTimeOut:millis |
6108 |
"wait for any fd to become ready; timeout after t milliseconds. |
|
6109 |
A zero timeout-time will immediately return (i.e. poll). |
|
6110 |
Return fd if i/o ok, nil if timed-out or interrupted. |
|
6111 |
Obsolete: |
|
6112 |
This is a leftover method and will vanish." |
|
6113 |
||
6114 |
^ self selectOnAnyReadable:(Array with:fd1 with:fd2) |
|
6115 |
writable:(Array with:fd1 with:fd2) |
|
6116 |
exception:nil |
|
6117 |
withTimeOut:millis |
|
10 | 6118 |
! |
6119 |
||
6120 |
selectOn:fd withTimeOut:millis |
|
6121 |
"wait for aFileDesriptor to become ready; timeout after t milliseconds. |
|
1 | 6122 |
Return true, if i/o ok, false if timed-out or interrupted. |
6123 |
With 0 as timeout argument, this can be used to check for availability |
|
6124 |
of read-data. |
|
6125 |
Experimental." |
|
6126 |
||
3 | 6127 |
^ self selectOnAnyReadable:(Array with:fd) |
185 | 6128 |
writable:(Array with:fd) |
6129 |
exception:nil |
|
6130 |
withTimeOut:millis |
|
1 | 6131 |
! |
6132 |
||
616 | 6133 |
selectOnAny:fdArray withTimeOut:millis |
6134 |
"wait for any fd in fdArray (an Array of integers) to become ready; |
|
6135 |
timeout after t milliseconds. An empty set will always wait. |
|
6136 |
Return first ready fd if i/o ok, nil if timed-out or interrupted. |
|
6137 |
Experimental." |
|
6138 |
||
6139 |
^ self selectOnAnyReadable:fdArray |
|
6140 |
writable:fdArray |
|
185 | 6141 |
exception:nil |
6142 |
withTimeOut:millis |
|
1 | 6143 |
! |
6144 |
||
10 | 6145 |
selectOnAnyReadable:fdArray withTimeOut:millis |
95 | 6146 |
"wait for any fd in fdArray (an Array of integers) to become ready for |
6147 |
reading. Timeout after t milliseconds. An empty set will always wait. |
|
6148 |
A zero timeout-time will immediately return (i.e. poll). |
|
3 | 6149 |
Return first ready fd if i/o ok, nil if timed-out or interrupted. |
6150 |
Experimental." |
|
6151 |
||
6152 |
^ self selectOnAnyReadable:fdArray |
|
185 | 6153 |
writable:nil |
6154 |
exception:nil |
|
6155 |
withTimeOut:millis |
|
3 | 6156 |
! |
6157 |
||
95 | 6158 |
selectOnAnyReadable:readFdArray writable:writeFdArray exception:exceptFdArray withTimeOut:millis |
6159 |
"wait for any fd in readFdArray (an Array of integers) to become ready for |
|
6160 |
reading, writeFdArray to become ready for writing, or exceptFdArray to |
|
6161 |
arrive exceptional data (i.e. out-of-band data). |
|
6162 |
Timeout after t milliseconds or, if the timeout time is 0, immediately.. |
|
6163 |
Empty fd-sets will always wait. Zero time can be used to poll file- |
|
6164 |
descriptors (i.e. to check if I/O possible without blocking). |
|
6165 |
Return first ready fd if I/O ok, nil if timed-out or interrupted." |
|
3 | 6166 |
|
1 | 6167 |
%{ |
831 | 6168 |
#ifdef MSDOS_LIKE |
6169 |
/* |
|
6170 |
* support a delay-wait only |
|
6171 |
* (i.e. fail if any filedescriptor is selected upon) |
|
6172 |
*/ |
|
6173 |
int count; |
|
6174 |
int i; |
|
6175 |
int t; |
|
6176 |
OBJ fd; |
|
6177 |
||
6178 |
if (! __isSmallInteger(millis)) { |
|
6179 |
goto fail; |
|
6180 |
} |
|
6181 |
||
6182 |
if (readFdArray != nil) { |
|
6183 |
if (! __isArray(readFdArray)) { |
|
6184 |
goto fail; |
|
6185 |
} |
|
6186 |
count = __arraySize(readFdArray); |
|
6187 |
for (i=0; i<count;i++) { |
|
6188 |
fd = _ArrayInstPtr(readFdArray)->a_element[i]; |
|
6189 |
if (fd != nil) { |
|
6190 |
goto fail; |
|
6191 |
} |
|
6192 |
} |
|
6193 |
} |
|
6194 |
if (writeFdArray != nil) { |
|
6195 |
if (! __isArray(writeFdArray)) { |
|
6196 |
goto fail; |
|
6197 |
} |
|
6198 |
count = __arraySize(writeFdArray); |
|
6199 |
for (i=0; i<count;i++) { |
|
6200 |
fd = _ArrayInstPtr(writeFdArray)->a_element[i]; |
|
6201 |
if (fd != nil) { |
|
6202 |
goto fail; |
|
6203 |
} |
|
6204 |
} |
|
6205 |
} |
|
6206 |
if (exceptFdArray != nil) { |
|
6207 |
if (! __isArray(exceptFdArray)) { |
|
6208 |
goto fail; |
|
6209 |
} |
|
6210 |
count = __arraySize(exceptFdArray); |
|
6211 |
for (i=0; i<count;i++) { |
|
6212 |
fd = _ArrayInstPtr(exceptFdArray)->a_element[i]; |
|
6213 |
if (fd != nil) { |
|
6214 |
goto fail; |
|
6215 |
} |
|
6216 |
} |
|
6217 |
} |
|
6218 |
t = _intVal(millis); |
|
6219 |
if (t != 0) { |
|
6220 |
/* |
|
6221 |
* delay only |
|
6222 |
*/ |
|
6223 |
Sleep(t); |
|
6224 |
} |
|
6225 |
RETURN (nil); |
|
6226 |
||
6227 |
#else /* not MSDOS_LIKE */ |
|
1 | 6228 |
fd_set rset, wset, eset; |
831 | 6229 |
struct timeval wt, et; |
1 | 6230 |
int t, f, maxF, i, lX, bX; |
6231 |
OBJ fd, retFd; |
|
95 | 6232 |
int ret; |
300 | 6233 |
int count; |
1 | 6234 |
|
252 | 6235 |
if (__isSmallInteger(millis)) { |
185 | 6236 |
FD_ZERO(&rset); |
6237 |
FD_ZERO(&wset); |
|
6238 |
FD_ZERO(&eset); |
|
6239 |
||
6240 |
maxF = -1; |
|
308 | 6241 |
if (readFdArray != nil) { |
300 | 6242 |
if (! __isArray(readFdArray)) { |
6243 |
goto fail; |
|
6244 |
} |
|
6245 |
count = __arraySize(readFdArray); |
|
308 | 6246 |
|
6247 |
for (i=0; i<count;i++) { |
|
6248 |
fd = _ArrayInstPtr(readFdArray)->a_element[i]; |
|
6249 |
if (fd != nil) { |
|
6250 |
f = _intVal(fd); |
|
6251 |
if ((f >= 0) && (f < FD_SETSIZE)) { |
|
6252 |
FD_SET(f, &rset); |
|
6253 |
if (f > maxF) maxF = f; |
|
6254 |
} |
|
185 | 6255 |
} |
6256 |
} |
|
6257 |
} |
|
300 | 6258 |
|
308 | 6259 |
if (writeFdArray != nil) { |
300 | 6260 |
if (! __isArray(writeFdArray)) { |
6261 |
goto fail; |
|
6262 |
} |
|
6263 |
count = __arraySize(writeFdArray); |
|
308 | 6264 |
for (i=0; i<count;i++) { |
6265 |
fd = _ArrayInstPtr(writeFdArray)->a_element[i]; |
|
6266 |
if (fd != nil) { |
|
6267 |
f = _intVal(fd); |
|
6268 |
if ((f >= 0) && (f < FD_SETSIZE)) { |
|
6269 |
FD_SET(f, &wset); |
|
6270 |
if (f > maxF) maxF = f; |
|
6271 |
} |
|
185 | 6272 |
} |
6273 |
} |
|
6274 |
} |
|
300 | 6275 |
|
308 | 6276 |
if (exceptFdArray != nil) { |
300 | 6277 |
if (! __isArray(exceptFdArray)) { |
6278 |
goto fail; |
|
6279 |
} |
|
6280 |
count = __arraySize(exceptFdArray); |
|
308 | 6281 |
for (i=0; i<count;i++) { |
6282 |
fd = _ArrayInstPtr(exceptFdArray)->a_element[i]; |
|
6283 |
if (fd != nil) { |
|
6284 |
f = _intVal(fd); |
|
6285 |
if ((f >= 0) && (f < FD_SETSIZE)) { |
|
6286 |
FD_SET(f, &eset); |
|
6287 |
if (f > maxF) maxF = f; |
|
6288 |
} |
|
185 | 6289 |
} |
6290 |
} |
|
6291 |
} |
|
308 | 6292 |
|
185 | 6293 |
t = _intVal(millis); |
774
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6294 |
if (t) { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6295 |
wt.tv_sec = t / 1000; |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6296 |
wt.tv_usec = (t % 1000) * 1000; |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6297 |
} else { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6298 |
wt.tv_sec = wt.tv_usec = 0; |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6299 |
} |
185 | 6300 |
|
6301 |
/* |
|
6302 |
* make certain, that interrupt gets us out of the select |
|
6303 |
*/ |
|
362 | 6304 |
__BEGIN_INTERRUPTABLE__ |
185 | 6305 |
errno = 0; |
774
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6306 |
|
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6307 |
if (t == 0) { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6308 |
/* |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6309 |
* if there is no timeout time, we can stay here |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6310 |
* interruptable. |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6311 |
*/ |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6312 |
do { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6313 |
ret = select(maxF+1, &rset, &wset, &eset, &wt); |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6314 |
} while ((ret < 0) && (errno == EINTR)); |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6315 |
} else { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6316 |
do { |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
6317 |
ret = select(maxF+1, &rset, &wset, &eset, &wt); |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
6318 |
/* |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
6319 |
* for now: dont loop; if we did, we had to adjust the vt-timeval; |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
6320 |
* could otherwise stay in this loop forever ... |
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
6321 |
* Premature return (before the time expired) must be handled by the caller. |
774
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6322 |
* A good solution is to update the wt-timeval and redo the select. |
813
1f9611434418
first stuff for locale support added
Claus Gittinger <cg@exept.de>
parents:
811
diff
changeset
|
6323 |
*/ |
774
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6324 |
} while (0 /* (ret < 0) && (errno == EINTR) */ ); |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
6325 |
} |
362 | 6326 |
__END_INTERRUPTABLE__ |
95 | 6327 |
|
185 | 6328 |
if (ret > 0) { |
6329 |
for (i=0; i <= maxF; i++) { |
|
6330 |
if (FD_ISSET(i, &rset) |
|
6331 |
|| FD_ISSET(i, &wset) |
|
6332 |
|| FD_ISSET(i, &eset)) { |
|
6333 |
RETURN ( _MKSMALLINT(i) ); |
|
6334 |
} |
|
6335 |
} |
|
855
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
6336 |
} else { |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
6337 |
if (ret < 0) { |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
6338 |
if (errno != EINTR) { |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
6339 |
printf("select errno = %d\n", errno); |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
6340 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
6341 |
} |
2de3c842c687
dont use SIGPIPE - it leads to trouble if its executed asynchrounously or
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
6342 |
} |
185 | 6343 |
} |
308 | 6344 |
|
185 | 6345 |
/* |
6346 |
* return nil (means time expired) |
|
6347 |
*/ |
|
6348 |
RETURN ( nil ); |
|
1 | 6349 |
} |
831 | 6350 |
#endif /* not MSDOS_LIKE */ |
6351 |
||
300 | 6352 |
fail: ; |
68 | 6353 |
%}. |
6354 |
" |
|
300 | 6355 |
timeout argument not integer, |
6356 |
or any fd-array nonNil and not an array |
|
792 | 6357 |
or not supported by OS |
68 | 6358 |
" |
792 | 6359 |
^ self primitiveFailed |
1 | 6360 |
! |
6361 |
||
616 | 6362 |
setBlocking:aBoolean on:fd |
6363 |
"set/clear the blocking attribute - if set (which is the default) |
|
6364 |
a read on the fileDescriptor will block until data is available. |
|
6365 |
If cleared, a read operation will immediately return with a value of |
|
6366 |
nil." |
|
10 | 6367 |
|
6368 |
%{ /* NOCONTEXT */ |
|
6369 |
||
616 | 6370 |
int ret, flags; |
6371 |
int savInt; |
|
6372 |
||
6373 |
#if defined(F_GETFL) && defined(F_SETFL) |
|
6374 |
# if defined(FNDELAY) |
|
6375 |
if (__isSmallInteger(fd)) { |
|
6376 |
flags = fcntl(_intVal(fd), F_GETFL, 0); |
|
6377 |
if (aBoolean == true) { |
|
6378 |
ret = fcntl(_intVal(fd), F_SETFL, flags & ~FNDELAY); |
|
6379 |
} else { |
|
6380 |
ret = fcntl(_intVal(fd), F_SETFL, flags | FNDELAY); |
|
185 | 6381 |
} |
616 | 6382 |
if (ret >= 0) ret = flags; |
6383 |
RETURN ( _MKSMALLINT(ret) ); |
|
77 | 6384 |
} |
616 | 6385 |
# endif |
77 | 6386 |
#endif |
308 | 6387 |
%}. |
77 | 6388 |
" |
616 | 6389 |
fd argument not integer |
185 | 6390 |
" |
792 | 6391 |
^ self primitiveFailed |
1 | 6392 |
! |
6393 |
||
616 | 6394 |
writeCheck:fd |
6395 |
"return true, if filedescriptor can be written without blocking" |
|
6396 |
||
6397 |
(self selectOnAnyReadable:nil |
|
6398 |
writable:(Array with:fd) |
|
6399 |
exception:nil |
|
6400 |
withTimeOut:0) == fd |
|
6401 |
ifTrue:[^ true]. |
|
6402 |
^ false |
|
1 | 6403 |
! ! |
434 | 6404 |
|
630 | 6405 |
!OperatingSystem class methodsFor:'documentation'! |
6406 |
||
6407 |
version |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
914
diff
changeset
|
6408 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.120 1996-02-04 19:06:28 cg Exp $' |
630 | 6409 |
! ! |
616 | 6410 |
OperatingSystem initialize! |