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