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 |
|
|
13 |
Object subclass:#OperatingSystem
|
|
14 |
instanceVariableNames:''
|
308
|
15 |
classVariableNames:'HostName LastErrorNumber LastExecStatus OSSignals
|
|
16 |
SlowFork ForkFailed'
|
1
|
17 |
poolDictionaries:''
|
|
18 |
category:'System-Support'
|
|
19 |
!
|
|
20 |
|
|
21 |
OperatingSystem comment:'
|
5
|
22 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
185
|
23 |
All Rights Reserved
|
|
24 |
|
375
|
25 |
$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.45 1995-08-08 00:49:29 claus Exp $
|
1
|
26 |
'!
|
|
27 |
|
216
|
28 |
!OperatingSystem primitiveDefinitions!
|
185
|
29 |
|
1
|
30 |
%{
|
|
31 |
|
|
32 |
#ifdef transputer
|
|
33 |
# define unlink(f) ((remove(f) == 0) ? 0 : -1)
|
|
34 |
#else
|
|
35 |
# include <signal.h>
|
|
36 |
|
|
37 |
# ifdef SYSV
|
|
38 |
# include <sys/types.h>
|
|
39 |
# include <sys/param.h>
|
|
40 |
# include <sys/times.h>
|
373
|
41 |
# include <sys/file.h>
|
1
|
42 |
# if ! defined(sco3_2)
|
|
43 |
# include <unistd.h>
|
|
44 |
# endif
|
68
|
45 |
|
1
|
46 |
# if defined(isc3_2) || defined(sco3_2)
|
|
47 |
# include <sys/time.h>
|
|
48 |
# endif
|
68
|
49 |
|
1
|
50 |
# if !defined(isc3_2)
|
|
51 |
# if defined(PCS) && defined(mips)
|
|
52 |
# include "/usr/include/bsd/sys/time.h"
|
|
53 |
# include "/usr/include/sys/time.h"
|
|
54 |
# else
|
|
55 |
# include <time.h>
|
|
56 |
# endif
|
|
57 |
# endif
|
68
|
58 |
|
1
|
59 |
# if defined(isc3_2)
|
|
60 |
# include <sys/bsdtypes.h>
|
|
61 |
# endif
|
68
|
62 |
|
1
|
63 |
# else /* not SYSV */
|
68
|
64 |
|
1
|
65 |
# include <sys/time.h>
|
|
66 |
# include <sys/types.h>
|
|
67 |
# endif
|
68
|
68 |
|
359
|
69 |
# ifdef aix
|
|
70 |
# include <time.h>
|
|
71 |
# include <sys/select.h>
|
|
72 |
# endif
|
|
73 |
|
1
|
74 |
# include <pwd.h>
|
|
75 |
# include <grp.h>
|
|
76 |
|
|
77 |
# include <sys/stat.h>
|
10
|
78 |
# include <errno.h>
|
|
79 |
|
202
|
80 |
/*
|
|
81 |
* posix systems should define these ...
|
|
82 |
* but on some (older) systems, they are not.
|
|
83 |
*/
|
1
|
84 |
# ifndef S_IXUSR
|
202
|
85 |
# ifdef S_IEXEC
|
|
86 |
# define S_IXUSR S_IEXEC
|
|
87 |
# define S_IXGRP (S_IEXEC>>3)
|
|
88 |
# define S_IXOTH (S_IEXEC>>6)
|
|
89 |
# endif
|
|
90 |
# endif
|
|
91 |
|
|
92 |
# ifndef S_IXUSR
|
|
93 |
# define S_IXUSR 0100
|
|
94 |
# define S_IXGRP 0010
|
|
95 |
# define S_IXOTH 0001
|
|
96 |
# endif
|
|
97 |
|
|
98 |
# ifndef S_IRUSR
|
|
99 |
# define S_IRUSR 0400
|
|
100 |
# define S_IRGRP 0040
|
|
101 |
# define S_IROTH 0004
|
|
102 |
# endif
|
|
103 |
|
|
104 |
# ifndef S_IWUSR
|
|
105 |
# define S_IWUSR 0200
|
|
106 |
# define S_IWGRP 0020
|
|
107 |
# define S_IWOTH 0002
|
1
|
108 |
# endif
|
|
109 |
|
77
|
110 |
# ifndef MAXPATHLEN
|
|
111 |
# include <sys/param.h>
|
|
112 |
# ifndef MAXPATHLEN
|
|
113 |
# define MAXPATHLEN 1024
|
|
114 |
# endif
|
|
115 |
# endif
|
|
116 |
|
204
|
117 |
# if defined(HAS_UNAME)
|
|
118 |
# include <sys/utsname.h>
|
|
119 |
# endif
|
|
120 |
|
359
|
121 |
# include <stdio.h>
|
|
122 |
# include <fcntl.h>
|
|
123 |
|
|
124 |
#endif /* ! transputer */
|
234
|
125 |
|
10
|
126 |
/*
|
|
127 |
* on some systems errno is a macro ... check for it here
|
|
128 |
*/
|
1
|
129 |
#ifndef errno
|
|
130 |
extern errno;
|
|
131 |
#endif
|
|
132 |
|
10
|
133 |
/*
|
68
|
134 |
* some (old ?) systems do not define this ...
|
10
|
135 |
*/
|
1
|
136 |
#ifndef R_OK
|
|
137 |
# define R_OK 4 /* Test for Read permission */
|
|
138 |
# define W_OK 2 /* Test for Write permission */
|
|
139 |
# define X_OK 1 /* Test for eXecute permission */
|
|
140 |
# define F_OK 0 /* Test for existence of File */
|
|
141 |
#endif
|
|
142 |
%}
|
185
|
143 |
! !
|
1
|
144 |
|
2
|
145 |
!OperatingSystem class methodsFor:'documentation'!
|
|
146 |
|
88
|
147 |
copyright
|
|
148 |
"
|
|
149 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
185
|
150 |
All Rights Reserved
|
88
|
151 |
|
|
152 |
This software is furnished under a license and may be used
|
|
153 |
only in accordance with the terms of that license and with the
|
|
154 |
inclusion of the above copyright notice. This software may not
|
|
155 |
be provided or otherwise made available to, or used by, any
|
|
156 |
other person. No title to or ownership of the software is
|
|
157 |
hereby transferred.
|
|
158 |
"
|
|
159 |
!
|
|
160 |
|
|
161 |
version
|
|
162 |
"
|
375
|
163 |
$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.45 1995-08-08 00:49:29 claus Exp $
|
88
|
164 |
"
|
|
165 |
!
|
|
166 |
|
2
|
167 |
documentation
|
|
168 |
"
|
68
|
169 |
this class gives access to some operating system services;
|
|
170 |
some of it is very specific for unix, so do not depend on
|
|
171 |
things available here in your applications - some may not
|
370
|
172 |
be found in other OS's or be slightly different ...
|
216
|
173 |
Currently, there is only this class available - once more than
|
|
174 |
Unix is supported, the corresponding class will be bound to the
|
|
175 |
global variable OperatingSystem.
|
68
|
176 |
|
|
177 |
(On the other hand: I do not want to hide all features
|
|
178 |
from you - in some situations it MAY be interresting to be
|
|
179 |
able to get down to a select or fork system call easily.
|
|
180 |
You decide - portability vs. functionality)
|
|
181 |
|
|
182 |
Class variables:
|
|
183 |
|
185
|
184 |
HostName <String> remembered hostname
|
|
185 |
|
|
186 |
LastErrorNumber <Integer> the last value of errno
|
|
187 |
|
|
188 |
LastExecStatus <Integer> the returned exec status after
|
|
189 |
the last call of system
|
|
190 |
|
|
191 |
OSSignals <Array> Array of signals to be raised for corresponding
|
|
192 |
OperatingSystem signals.
|
308
|
193 |
|
|
194 |
ForkFailed <Boolean> set if a fork (or popen) has failed;
|
|
195 |
ST/X will avoid doing more forks/popens
|
|
196 |
if this flag is set, for a slightly
|
|
197 |
smoother operation.
|
|
198 |
|
|
199 |
SlowFork <Boolean> if set, fork and popen are avoided;
|
2
|
200 |
"
|
|
201 |
! !
|
|
202 |
|
95
|
203 |
!OperatingSystem class methodsFor:'initialization'!
|
|
204 |
|
|
205 |
initialize
|
185
|
206 |
"initialize the class"
|
|
207 |
|
95
|
208 |
ObjectMemory addDependent:self
|
|
209 |
!
|
|
210 |
|
|
211 |
update:something
|
|
212 |
something == #earlyRestart ifTrue:[
|
185
|
213 |
"
|
|
214 |
flush cached data
|
|
215 |
"
|
|
216 |
HostName := nil.
|
|
217 |
LastErrorNumber := nil.
|
|
218 |
LastExecStatus := nil
|
95
|
219 |
]
|
|
220 |
! !
|
|
221 |
|
1
|
222 |
!OperatingSystem class methodsFor:'misc'!
|
|
223 |
|
308
|
224 |
slowFork:aBoolean
|
|
225 |
SlowFork := aBoolean
|
|
226 |
!
|
|
227 |
|
1
|
228 |
exit
|
68
|
229 |
"shutdown smalltalk immediately -
|
|
230 |
return 'good'-status (0) to parent unix process."
|
1
|
231 |
|
|
232 |
%{ /* NOCONTEXT */
|
357
|
233 |
__mainExit(0);
|
1
|
234 |
%}
|
|
235 |
"OperatingSystem exit - dont evaluate this"
|
|
236 |
!
|
|
237 |
|
|
238 |
exit:exitCode
|
68
|
239 |
"shutdown smalltalk immediately -
|
|
240 |
returning an exit-code to the parent unix process."
|
1
|
241 |
|
|
242 |
%{ /* NOCONTEXT */
|
357
|
243 |
int code = 1;
|
|
244 |
|
|
245 |
if (__isSmallInteger(exitCode)) {
|
|
246 |
code = _intVal(exitCode);
|
|
247 |
}
|
|
248 |
__mainExit(code);
|
1
|
249 |
%}
|
|
250 |
"OperatingSystem exit:1 - dont evaluate this"
|
68
|
251 |
!
|
|
252 |
|
|
253 |
exitWithCoreDump
|
|
254 |
"shutdown smalltalk immediately - dumping core.
|
|
255 |
This always returns 'bad'-status to the parent unix process.
|
357
|
256 |
Notice, that no cleanup is performed at all - you may have to
|
|
257 |
manually remove any tempfiles.
|
68
|
258 |
Use this only for debugging ST/X itself"
|
|
259 |
|
|
260 |
%{ /* NOCONTEXT */
|
|
261 |
abort();
|
|
262 |
%}
|
|
263 |
"OperatingSystem exitWithCoreDump - dont evaluate this"
|
10
|
264 |
! !
|
|
265 |
|
|
266 |
!OperatingSystem class methodsFor:'os queries'!
|
1
|
267 |
|
322
|
268 |
getEnvironment:aStringOrSymbol
|
1
|
269 |
"get an environment string"
|
|
270 |
|
|
271 |
%{ /* NOCONTEXT */
|
|
272 |
|
|
273 |
char *env;
|
|
274 |
|
322
|
275 |
if (__isString(aStringOrSymbol) || __isSymbol(aStringOrSymbol)) {
|
|
276 |
env = (char *)getenv(_stringVal(aStringOrSymbol));
|
185
|
277 |
if (env) {
|
|
278 |
RETURN ( _MKSTRING(env COMMA_CON) );
|
|
279 |
}
|
1
|
280 |
}
|
|
281 |
%}
|
|
282 |
.
|
|
283 |
^ nil
|
|
284 |
|
68
|
285 |
"
|
|
286 |
OperatingSystem getEnvironment:'LANG'
|
|
287 |
OperatingSystem getEnvironment:'LOGIN'
|
|
288 |
OperatingSystem getEnvironment:'HOME'
|
|
289 |
OperatingSystem getEnvironment:'NNTPSERVER'
|
|
290 |
OperatingSystem getEnvironment:'MAIL'
|
|
291 |
"
|
1
|
292 |
!
|
|
293 |
|
|
294 |
getProcessId
|
68
|
295 |
"return the (unix-)processId"
|
1
|
296 |
|
|
297 |
%{ /* NOCONTEXT */
|
|
298 |
|
|
299 |
int pid = 0;
|
|
300 |
#ifndef transputer
|
|
301 |
pid = getpid();
|
|
302 |
#endif
|
|
303 |
RETURN ( _MKSMALLINT(pid) );
|
|
304 |
%}
|
68
|
305 |
"
|
|
306 |
OperatingSystem getProcessId
|
|
307 |
"
|
1
|
308 |
!
|
|
309 |
|
|
310 |
getCPUType
|
68
|
311 |
"return a string giving the type of machine we're running on.
|
|
312 |
This may normally not be of any interrest to you ..."
|
1
|
313 |
|
|
314 |
|cpu|
|
|
315 |
|
|
316 |
%{ /* NOCONTEXT */
|
77
|
317 |
|
|
318 |
# ifdef vax
|
|
319 |
# define CPU_STRING "vax"
|
|
320 |
# endif
|
|
321 |
# ifdef mips
|
|
322 |
# define CPU_STRING "mips"
|
|
323 |
# endif
|
|
324 |
# ifdef i386
|
|
325 |
# define CPU_STRING "i386"
|
|
326 |
# endif
|
|
327 |
# ifdef ns32k
|
|
328 |
# define CPU_STRING "ns32k"
|
|
329 |
# endif
|
|
330 |
# ifdef mc68k
|
|
331 |
# define CPU_STRING "mc68k"
|
|
332 |
# endif
|
|
333 |
# ifdef sparc
|
|
334 |
# define CPU_STRING "sparc"
|
|
335 |
# endif
|
|
336 |
# ifdef hppa
|
|
337 |
# define CPU_STRING "hppa"
|
|
338 |
# endif
|
|
339 |
# ifdef rs6000
|
|
340 |
# define CPU_STRING "rs6000"
|
|
341 |
# endif
|
|
342 |
# ifdef alpha
|
|
343 |
# define CPU_STRING "alpha"
|
|
344 |
# endif
|
|
345 |
# ifdef powerPC
|
|
346 |
# define CPU_STRING "powerPC"
|
|
347 |
# endif
|
|
348 |
# ifdef transputer
|
|
349 |
# define CPU_STRING "transputer"
|
|
350 |
# endif
|
|
351 |
|
|
352 |
# ifndef CPU_STRING
|
|
353 |
# define CPU_STRING "unknown"
|
|
354 |
# endif
|
|
355 |
|
|
356 |
cpu = _MKSTRING(CPU_STRING COMMA_CON);
|
|
357 |
# undef CPU_STRING
|
1
|
358 |
%}
|
|
359 |
.
|
|
360 |
^ cpu
|
|
361 |
|
77
|
362 |
"
|
|
363 |
OperatingSystem getCPUType
|
|
364 |
"
|
|
365 |
|
|
366 |
"examples: are we running on a ss-10/solaris ?"
|
|
367 |
"
|
|
368 |
(OperatingSystem getCPUType = 'sparc')
|
|
369 |
and:[OperatingSystem getOSType = 'solaris']
|
|
370 |
"
|
|
371 |
|
|
372 |
"or on a pc/solaris ?"
|
|
373 |
"
|
|
374 |
(OperatingSystem getCPUType = 'i386')
|
|
375 |
and:[OperatingSystem getOSType = 'solaris']
|
|
376 |
"
|
1
|
377 |
!
|
|
378 |
|
|
379 |
getOSType
|
77
|
380 |
"return a string giving the type of OS we're running on.
|
|
381 |
This can be used to adapt programs to certain environment
|
|
382 |
differences (for example: mail-lock strategy ...)"
|
1
|
383 |
|
|
384 |
|os|
|
|
385 |
|
|
386 |
%{ /* NOCONTEXT */
|
77
|
387 |
|
|
388 |
# ifdef MSDOS
|
|
389 |
# define OS_STRING "msdos"
|
|
390 |
# endif
|
|
391 |
|
|
392 |
# ifdef NT
|
|
393 |
# define OS_STRING "nt"
|
|
394 |
# endif
|
|
395 |
|
|
396 |
# ifdef sinix
|
|
397 |
# define OS_STRING "sinix"
|
|
398 |
# endif
|
|
399 |
|
|
400 |
# ifdef ultrix
|
|
401 |
# define OS_STRING "ultrix"
|
|
402 |
# endif
|
|
403 |
|
|
404 |
# ifdef sco
|
|
405 |
# define OS_STRING "sco"
|
|
406 |
# endif
|
|
407 |
|
|
408 |
# ifdef hpux
|
|
409 |
# define OS_STRING "hpux"
|
|
410 |
# endif
|
|
411 |
|
|
412 |
# ifdef LINUX
|
|
413 |
# define OS_STRING "linux"
|
|
414 |
# endif
|
|
415 |
|
|
416 |
# ifdef sunos
|
|
417 |
# define OS_STRING "sunos"
|
|
418 |
# endif
|
|
419 |
|
|
420 |
# ifdef solaris
|
|
421 |
# define OS_STRING "solaris"
|
|
422 |
# endif
|
|
423 |
|
|
424 |
# ifdef IRIS
|
|
425 |
# define OS_STRING "irix"
|
|
426 |
# endif
|
|
427 |
|
359
|
428 |
# ifdef aix
|
|
429 |
# define OS_STRING "aix"
|
|
430 |
# endif
|
|
431 |
|
77
|
432 |
/*
|
|
433 |
* no concrete info; become somewhat vague ...
|
|
434 |
*/
|
|
435 |
# ifndef OS_STRING
|
|
436 |
# ifdef MACH
|
|
437 |
# define OS_STRING "mach"
|
|
438 |
# endif
|
|
439 |
# endif
|
|
440 |
|
|
441 |
# ifndef OS_STRING
|
|
442 |
# ifdef BSD
|
|
443 |
# define OS_STRING "bsd"
|
|
444 |
# endif
|
|
445 |
|
|
446 |
# ifdef SYSV
|
|
447 |
# ifdef SYSV3
|
|
448 |
# define OS_STRING "sys5.3"
|
|
449 |
# else
|
|
450 |
# ifdef SYSV4
|
|
451 |
# define OS_STRING "sys5.4"
|
|
452 |
# else
|
|
453 |
# define OS_STRING "sys5"
|
|
454 |
# endif
|
|
455 |
# endif
|
|
456 |
# endif
|
|
457 |
# endif
|
|
458 |
|
|
459 |
/*
|
|
460 |
* become very vague ...
|
|
461 |
*/
|
|
462 |
# ifndef OS_STRING
|
|
463 |
# ifdef POSIX
|
|
464 |
# define OS_STRING "posix"
|
|
465 |
# endif
|
|
466 |
# endif
|
|
467 |
# ifndef OS_STRING
|
|
468 |
# ifdef UNIX
|
|
469 |
# define OS_STRING "unix"
|
|
470 |
# endif
|
|
471 |
# endif
|
|
472 |
|
|
473 |
# ifndef OS_STRING
|
|
474 |
# define OS_STRING "unknown"
|
|
475 |
# endif
|
|
476 |
|
|
477 |
os = _MKSTRING(OS_STRING COMMA_CON);
|
|
478 |
# undef OS_STRING
|
1
|
479 |
%}
|
|
480 |
.
|
|
481 |
^ os
|
|
482 |
|
|
483 |
"OperatingSystem getOSType"
|
|
484 |
!
|
|
485 |
|
|
486 |
getSystemType
|
68
|
487 |
"return a string giving the type of system we're running on.
|
|
488 |
This is almost the same as getOSType, but the returned string
|
|
489 |
is slightly different for some systems (i.e. iris vs. irix).
|
|
490 |
Dont depend on this - use getOSType. I dont really see a point
|
77
|
491 |
here ... (except for slight differences between next/mach and other
|
|
492 |
machs)"
|
1
|
493 |
|
|
494 |
|sys|
|
|
495 |
|
77
|
496 |
%{
|
|
497 |
# ifdef NEXT
|
|
498 |
# define SYS_STRING "next"
|
|
499 |
# endif
|
|
500 |
|
|
501 |
# ifdef IRIS
|
|
502 |
# define SYS_STRING "iris"
|
|
503 |
# endif
|
|
504 |
|
|
505 |
# ifdef SYS_STRING
|
|
506 |
sys = _MKSTRING(SYS_STRING COMMA_CON);
|
|
507 |
# undef SYS_STRING
|
|
508 |
# endif
|
1
|
509 |
%}
|
|
510 |
.
|
77
|
511 |
sys isNil ifTrue:[
|
185
|
512 |
^ self getOSType
|
77
|
513 |
].
|
1
|
514 |
^ sys
|
|
515 |
|
77
|
516 |
"
|
|
517 |
OperatingSystem getSystemType
|
|
518 |
"
|
1
|
519 |
!
|
|
520 |
|
10
|
521 |
getHostName
|
|
522 |
"return the hostname we are running on - if there is
|
|
523 |
a HOST environment variable, we are much faster here ..."
|
|
524 |
|
|
525 |
|name p|
|
|
526 |
|
68
|
527 |
HostName notNil ifTrue:[
|
185
|
528 |
^ HostName
|
68
|
529 |
].
|
10
|
530 |
name := self getEnvironment:'HOST'.
|
204
|
531 |
|
|
532 |
%{ /* STACK: 2048 */
|
77
|
533 |
#if defined(HAS_GETHOSTNAME)
|
|
534 |
char buffer[128];
|
|
535 |
|
|
536 |
if (gethostname(buffer, sizeof(buffer)) == 0) {
|
185
|
537 |
name = _MKSTRING(buffer COMMA_CON);
|
77
|
538 |
}
|
|
539 |
#else
|
|
540 |
# if defined(HAS_UNAME)
|
|
541 |
struct utsname ubuff;
|
|
542 |
|
204
|
543 |
if (uname(&ubuff) >= 0) {
|
185
|
544 |
name = _MKSTRING(ubuff.nodename COMMA_CON);
|
77
|
545 |
}
|
|
546 |
# endif
|
|
547 |
#endif
|
|
548 |
%}.
|
10
|
549 |
name isNil ifTrue:[
|
185
|
550 |
"since fork might be slow on some machines, give a warning ..."
|
308
|
551 |
|
|
552 |
ForkFailed ifFalse:[
|
|
553 |
'please set the HOST shell variable for a faster startup' errorPrintNL.
|
|
554 |
|
|
555 |
PipeStream openErrorSignal handle:[:ex |
|
|
556 |
ForkFailed := true.
|
|
557 |
'UNIX: cannot fork/popen' errorPrintNL.
|
|
558 |
ex return.
|
|
559 |
] do:[
|
|
560 |
p := PipeStream readingFrom:'hostname'.
|
|
561 |
p notNil ifTrue:[
|
|
562 |
name := p nextLine.
|
|
563 |
p close
|
|
564 |
]
|
|
565 |
]
|
185
|
566 |
]
|
10
|
567 |
].
|
|
568 |
name isNil ifTrue:[
|
185
|
569 |
'cannot find out hostname' errorPrintNL.
|
308
|
570 |
name := 'unknown'.
|
10
|
571 |
].
|
68
|
572 |
HostName := name.
|
77
|
573 |
^ name
|
68
|
574 |
|
|
575 |
"
|
|
576 |
OperatingSystem getHostName
|
|
577 |
"
|
10
|
578 |
!
|
|
579 |
|
1
|
580 |
isBSDlike
|
68
|
581 |
"return true, if the OS we're running on is a 'real' unix."
|
1
|
582 |
|
|
583 |
%{ /* NOCONTEXT */
|
|
584 |
|
77
|
585 |
#if defined(BSD) || defined(MACH) || defined(SYSV4)
|
1
|
586 |
RETURN ( true );
|
|
587 |
#endif
|
|
588 |
%}
|
|
589 |
.
|
|
590 |
^ false
|
|
591 |
!
|
|
592 |
|
216
|
593 |
isUNIXlike
|
|
594 |
"return true, if the OS we're running on is a unix like."
|
|
595 |
|
|
596 |
%{ /* NOCONTEXT */
|
|
597 |
|
359
|
598 |
#if defined(MSDOS) || defined(NT) || defined(OS2)
|
216
|
599 |
RETURN ( false );
|
|
600 |
#endif
|
|
601 |
%}
|
|
602 |
.
|
|
603 |
^ true
|
|
604 |
!
|
|
605 |
|
|
606 |
isMSDOSlike
|
|
607 |
"return true, if the OS we're running on is a unix like."
|
|
608 |
|
|
609 |
%{ /* NOCONTEXT */
|
|
610 |
|
359
|
611 |
#if defined(MSDOS) || defined(NT) || defined(OS2)
|
216
|
612 |
RETURN ( true );
|
|
613 |
#endif
|
|
614 |
%}
|
|
615 |
.
|
|
616 |
^ false
|
|
617 |
!
|
|
618 |
|
1
|
619 |
maxFileNameLength
|
68
|
620 |
"return the max number of characters in a filename.
|
77
|
621 |
This is no problem on 'real' unixes, but those
|
|
622 |
'instant ****-stations' always make problems .."
|
1
|
623 |
|
|
624 |
%{ /* NOCONTEXT */
|
77
|
625 |
|
|
626 |
/*
|
|
627 |
* XXX: newer systems provide a query function for this ... use it
|
|
628 |
*/
|
|
629 |
# if defined(BSD) || defined(SYSV4) || defined(LONGFILENAMES)
|
|
630 |
RETURN ( _MKSMALLINT(255) );
|
|
631 |
# endif
|
|
632 |
|
252
|
633 |
# ifdef realIX
|
|
634 |
RETURN ( _MKSMALLINT(127) );
|
|
635 |
# endif
|
|
636 |
|
77
|
637 |
# ifdef SYSV
|
|
638 |
RETURN ( _MKSMALLINT(14) );
|
|
639 |
# endif
|
|
640 |
|
|
641 |
# ifdef MSDOS
|
|
642 |
RETURN ( _MKSMALLINT(9) );
|
|
643 |
# endif
|
|
644 |
|
|
645 |
# ifdef NT
|
|
646 |
/*
|
|
647 |
* mhmh - depends on the filesystem type
|
|
648 |
*/
|
|
649 |
RETURN ( _MKSMALLINT(9) );
|
|
650 |
# endif
|
1
|
651 |
%}
|
|
652 |
.
|
77
|
653 |
"unix default"
|
1
|
654 |
^ 14
|
10
|
655 |
!
|
|
656 |
|
|
657 |
supportsIOInterrupts
|
|
658 |
"return true, if the OS supports IO availability interrupts
|
42
|
659 |
(i.e. SIGPOLL/SIGIO).
|
|
660 |
|
|
661 |
Currently, this mechanism does not work at all ..."
|
10
|
662 |
|
|
663 |
%{ /* NOCONTEXT */
|
42
|
664 |
#ifdef NOTDEF
|
|
665 |
|
77
|
666 |
# if defined(SIGPOLL) || defined(SIGIO)
|
|
667 |
# if defined(F_GETFL) && defined(F_SETFL)
|
|
668 |
# if defined(FASYNC)
|
|
669 |
/*
|
|
670 |
* mhmh they seem to NOT work on NS2.1
|
|
671 |
*/
|
|
672 |
# if !defined(NEXT)
|
185
|
673 |
RETURN (true);
|
77
|
674 |
# endif
|
|
675 |
# endif
|
|
676 |
# endif
|
10
|
677 |
# endif
|
42
|
678 |
|
|
679 |
#endif
|
10
|
680 |
%}
|
|
681 |
.
|
|
682 |
^ false
|
|
683 |
!
|
|
684 |
|
|
685 |
supportsNonBlockingIO
|
68
|
686 |
"return true, if the OS supports nonblocking IO."
|
10
|
687 |
|
|
688 |
%{ /* NOCONTEXT */
|
77
|
689 |
# if defined(F_GETFL) && defined(F_SETFL)
|
|
690 |
# if defined(FNDELAY)
|
|
691 |
RETURN (true);
|
|
692 |
# endif
|
|
693 |
# endif
|
10
|
694 |
%}
|
|
695 |
.
|
|
696 |
^ false
|
|
697 |
!
|
|
698 |
|
|
699 |
supportsSelect
|
|
700 |
"return true, if the OS supports selecting on multiple
|
|
701 |
filedescriptors via select."
|
|
702 |
|
|
703 |
%{ /* NOCONTEXT */
|
|
704 |
#if defined(sco)
|
|
705 |
/*
|
|
706 |
* sco has a broken select - always waiting 1 second
|
|
707 |
*/
|
|
708 |
RETURN(false);
|
|
709 |
#endif
|
|
710 |
%}
|
|
711 |
.
|
|
712 |
^ true
|
1
|
713 |
! !
|
|
714 |
|
2
|
715 |
!OperatingSystem class methodsFor:'users & groups'!
|
|
716 |
|
|
717 |
getLoginName
|
|
718 |
"return a string with the users name"
|
|
719 |
|
|
720 |
%{ /* NOCONTEXT */
|
|
721 |
|
|
722 |
char *name = "you";
|
|
723 |
#ifndef transputer
|
|
724 |
name = (char *)getlogin();
|
26
|
725 |
if (! name || (name[0] == 0)) {
|
185
|
726 |
name = (char *)getenv("LOGNAME");
|
2
|
727 |
}
|
|
728 |
#endif
|
|
729 |
RETURN ( _MKSTRING(name COMMA_CON) );
|
|
730 |
%}
|
68
|
731 |
"
|
|
732 |
OperatingSystem getLoginName
|
|
733 |
"
|
2
|
734 |
!
|
|
735 |
|
|
736 |
getUserNameFromID:aNumber
|
|
737 |
"return the user-name-string for a given numeric user-id"
|
|
738 |
|
|
739 |
%{ /* NOCONTEXT */
|
|
740 |
|
|
741 |
#ifndef transputer
|
|
742 |
struct passwd *p;
|
|
743 |
|
252
|
744 |
if (__isSmallInteger(aNumber)) {
|
185
|
745 |
p = getpwuid(_intVal(aNumber));
|
|
746 |
if (p) {
|
|
747 |
RETURN ( _MKSTRING(p->pw_name COMMA_CON) );
|
|
748 |
}
|
2
|
749 |
}
|
|
750 |
#endif
|
|
751 |
%}
|
|
752 |
.
|
77
|
753 |
^ '? (' , aNumber printString , ')'
|
2
|
754 |
|
68
|
755 |
"
|
|
756 |
OperatingSystem getUserNameFromID:0
|
|
757 |
OperatingSystem getUserNameFromID:100
|
77
|
758 |
OperatingSystem getUserNameFromID:9991
|
68
|
759 |
"
|
2
|
760 |
!
|
|
761 |
|
|
762 |
getGroupNameFromID:aNumber
|
|
763 |
"return the group-name-string for a given numeric group-id"
|
|
764 |
|
|
765 |
%{ /* NOCONTEXT */
|
|
766 |
|
|
767 |
#ifndef transputer
|
|
768 |
struct group *g;
|
|
769 |
|
252
|
770 |
if (__isSmallInteger(aNumber)) {
|
185
|
771 |
g = getgrgid(_intVal(aNumber));
|
|
772 |
if (g) {
|
|
773 |
RETURN ( _MKSTRING(g->gr_name COMMA_CON) );
|
|
774 |
}
|
2
|
775 |
}
|
|
776 |
#endif
|
|
777 |
%}
|
|
778 |
.
|
|
779 |
^ '???'
|
|
780 |
|
68
|
781 |
"
|
|
782 |
OperatingSystem getGroupNameFromID:0
|
|
783 |
OperatingSystem getGroupNameFromID:10
|
|
784 |
"
|
2
|
785 |
!
|
|
786 |
|
|
787 |
getHomeDirectory
|
10
|
788 |
"return the name of the users home directory"
|
2
|
789 |
|
|
790 |
^ OperatingSystem getEnvironment:'HOME'
|
|
791 |
|
68
|
792 |
"
|
|
793 |
OperatingSystem getHomeDirectory
|
|
794 |
"
|
2
|
795 |
! !
|
|
796 |
|
1
|
797 |
!OperatingSystem class methodsFor:'error messages'!
|
|
798 |
|
85
|
799 |
currentErrorNumber
|
68
|
800 |
"returns the OS's last error nr (i.e. the value of errno).
|
|
801 |
Notice, that the value of this flag is only valid immediately
|
|
802 |
after the error occurred - it gets updated with every other
|
85
|
803 |
request to the OS.
|
|
804 |
Use lastErrorNumber - currentErrorNumber is invalidated by
|
|
805 |
many, many internal calls."
|
68
|
806 |
|
|
807 |
%{ /* NOCONTEXT */
|
|
808 |
|
|
809 |
RETURN ( _MKSMALLINT(errno) );
|
|
810 |
%}
|
|
811 |
"
|
85
|
812 |
OperatingSystem currentErrorNumber
|
|
813 |
"
|
|
814 |
!
|
|
815 |
|
|
816 |
lastErrorNumber
|
|
817 |
"return the last error number"
|
|
818 |
|
|
819 |
^ LastErrorNumber
|
|
820 |
|
|
821 |
"
|
|
822 |
OperatingSystem lastErrorNumber
|
|
823 |
"
|
|
824 |
!
|
|
825 |
|
|
826 |
lastExecStatus
|
|
827 |
"return the last execution status"
|
|
828 |
|
|
829 |
^ LastExecStatus
|
|
830 |
|
|
831 |
"
|
|
832 |
OperatingSystem lastExecStatus
|
68
|
833 |
"
|
|
834 |
!
|
|
835 |
|
3
|
836 |
lastErrorString
|
|
837 |
"return a message string describing the last error"
|
|
838 |
|
85
|
839 |
^ self errorTextForNumber:LastErrorNumber
|
68
|
840 |
|
|
841 |
"
|
|
842 |
OperatingSystem lastErrorString
|
|
843 |
"
|
3
|
844 |
!
|
|
845 |
|
1
|
846 |
errorTextForNumber:errNr
|
|
847 |
"return a message string from a unix errorNumber
|
68
|
848 |
(as returned by a system call).
|
|
849 |
Should be replaced by a resource lookup."
|
1
|
850 |
|
77
|
851 |
%{
|
|
852 |
/* claus:
|
|
853 |
* I made this some primitive code, since errnos are not
|
|
854 |
* standard across unixes
|
|
855 |
*/
|
|
856 |
char *msg = "unknown error";
|
|
857 |
char buffer[50];
|
|
858 |
|
252
|
859 |
if (__isSmallInteger(errNr)) {
|
185
|
860 |
switch (_intVal(errNr)) {
|
|
861 |
/*
|
|
862 |
* POSIX errnos - these should be defined
|
|
863 |
*/
|
|
864 |
case EPERM:
|
|
865 |
msg = "Operation not permitted";
|
|
866 |
break;
|
|
867 |
case ENOENT:
|
|
868 |
msg = "No such file or directory";
|
|
869 |
break;
|
|
870 |
case ESRCH:
|
|
871 |
msg = "No such process";
|
|
872 |
break;
|
|
873 |
case EINTR:
|
|
874 |
msg = "Interrupted system call";
|
|
875 |
break;
|
|
876 |
case EIO:
|
|
877 |
msg = "I/O error";
|
|
878 |
break;
|
|
879 |
case ENXIO:
|
|
880 |
msg = "No such device or address";
|
|
881 |
break;
|
|
882 |
case E2BIG:
|
|
883 |
msg = "Arg list too long";
|
|
884 |
break;
|
|
885 |
case ENOEXEC:
|
|
886 |
msg = "Exec format error";
|
|
887 |
break;
|
|
888 |
case EBADF:
|
|
889 |
msg = "Bad file number";
|
|
890 |
break;
|
|
891 |
case ECHILD:
|
|
892 |
msg = "No child processes";
|
|
893 |
break;
|
77
|
894 |
#if !defined(EWOULDBLOCK) && defined(EAGAIN) && (EWOULDBLOCK != EAGAIN)
|
185
|
895 |
case EAGAIN:
|
|
896 |
msg = "Try again";
|
|
897 |
break;
|
77
|
898 |
#endif
|
185
|
899 |
case ENOMEM:
|
|
900 |
msg = "Out of memory";
|
|
901 |
break;
|
|
902 |
case EACCES:
|
|
903 |
msg = "Permission denied";
|
|
904 |
break;
|
|
905 |
case EFAULT:
|
|
906 |
msg = "Bad address";
|
|
907 |
break;
|
|
908 |
case EBUSY:
|
|
909 |
msg = "Device or resource busy";
|
|
910 |
break;
|
|
911 |
case EEXIST:
|
|
912 |
msg = "File exists";
|
|
913 |
break;
|
|
914 |
case EXDEV:
|
|
915 |
msg = "Cross-device link";
|
|
916 |
break;
|
|
917 |
case ENODEV:
|
|
918 |
msg = "No such device";
|
|
919 |
break;
|
|
920 |
case ENOTDIR:
|
|
921 |
msg = "Not a directory";
|
|
922 |
break;
|
|
923 |
case EISDIR:
|
|
924 |
msg = "Is a directory";
|
|
925 |
break;
|
|
926 |
case EINVAL:
|
|
927 |
msg = "Invalid argument";
|
|
928 |
break;
|
|
929 |
case ENFILE:
|
|
930 |
msg = "File table overflow";
|
|
931 |
break;
|
|
932 |
case EMFILE:
|
|
933 |
msg = "Too many open files";
|
|
934 |
break;
|
|
935 |
case ENOTTY:
|
|
936 |
msg = "Not a typewriter";
|
|
937 |
break;
|
|
938 |
case EFBIG:
|
|
939 |
msg = "File too large";
|
|
940 |
break;
|
|
941 |
case ENOSPC:
|
|
942 |
msg = "No space left on device";
|
|
943 |
break;
|
|
944 |
case ESPIPE:
|
|
945 |
msg = "Illegal seek";
|
|
946 |
break;
|
|
947 |
case EROFS:
|
|
948 |
msg = "Read-only file system";
|
|
949 |
break;
|
|
950 |
case EMLINK:
|
|
951 |
msg = "Too many links";
|
|
952 |
break;
|
|
953 |
case EPIPE:
|
|
954 |
msg = "Broken pipe";
|
|
955 |
break;
|
|
956 |
case EDOM:
|
|
957 |
msg = "Math argument out of domain";
|
|
958 |
break;
|
|
959 |
case ERANGE:
|
|
960 |
msg = "Math result not representable";
|
|
961 |
break;
|
77
|
962 |
#ifdef EDEADLK
|
308
|
963 |
# if EDEADLK != EWOULDBLOCK
|
185
|
964 |
case EDEADLK:
|
|
965 |
msg = "Resource deadlock would occur";
|
|
966 |
break;
|
308
|
967 |
# endif
|
77
|
968 |
#endif
|
|
969 |
#ifdef ENAMETOOLONG
|
185
|
970 |
case ENAMETOOLONG:
|
|
971 |
msg = "File name too long";
|
|
972 |
break;
|
77
|
973 |
#endif
|
|
974 |
#ifdef ENOLCK
|
185
|
975 |
case ENOLCK:
|
|
976 |
msg = "No record locks available";
|
|
977 |
break;
|
77
|
978 |
#endif
|
|
979 |
#ifdef ENOSYS
|
185
|
980 |
case ENOSYS:
|
|
981 |
msg = "Function not implemented";
|
|
982 |
break;
|
77
|
983 |
#endif
|
359
|
984 |
#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST)
|
185
|
985 |
case ENOTEMPTY:
|
|
986 |
msg = "Directory not empty";
|
|
987 |
break;
|
77
|
988 |
#endif
|
|
989 |
#ifdef EILSEQ
|
185
|
990 |
case EILSEQ:
|
|
991 |
msg = "Illegal byte sequence";
|
|
992 |
break;
|
77
|
993 |
#endif
|
185
|
994 |
/*
|
|
995 |
* XPG3 errnos - defined on most systems
|
|
996 |
*/
|
77
|
997 |
#ifdef ENOTBLK
|
185
|
998 |
case ENOTBLK:
|
|
999 |
msg = "Block device required";
|
|
1000 |
break;
|
77
|
1001 |
#endif
|
|
1002 |
#ifdef ETXTBSY
|
185
|
1003 |
case ETXTBSY:
|
|
1004 |
msg = "Text file busy";
|
|
1005 |
break;
|
77
|
1006 |
#endif
|
185
|
1007 |
/*
|
|
1008 |
* some others
|
|
1009 |
*/
|
77
|
1010 |
#ifdef EWOULDBLOCK
|
185
|
1011 |
case EWOULDBLOCK:
|
|
1012 |
msg = "Operation would block";
|
|
1013 |
break;
|
77
|
1014 |
#endif
|
|
1015 |
#ifdef ENOMSG
|
185
|
1016 |
case ENOMSG:
|
|
1017 |
msg = "No message of desired type";
|
|
1018 |
break;
|
77
|
1019 |
#endif
|
|
1020 |
#ifdef ELOOP
|
185
|
1021 |
case ELOOP:
|
|
1022 |
msg = "Too many levels of symbolic links";
|
|
1023 |
break;
|
77
|
1024 |
#endif
|
|
1025 |
|
185
|
1026 |
/*
|
|
1027 |
* some stream errors
|
|
1028 |
*/
|
77
|
1029 |
#ifdef ETIME
|
185
|
1030 |
case ETIME:
|
|
1031 |
msg = "Timer expired";
|
|
1032 |
break;
|
77
|
1033 |
#endif
|
|
1034 |
#ifdef ENOSR
|
185
|
1035 |
case ENOSR:
|
|
1036 |
msg = "Out of streams resources";
|
|
1037 |
break;
|
77
|
1038 |
#endif
|
|
1039 |
#ifdef ENOSTR
|
185
|
1040 |
case ENOSTR:
|
|
1041 |
msg = "Device not a stream";
|
|
1042 |
break;
|
77
|
1043 |
#endif
|
|
1044 |
#ifdef ECOMM
|
185
|
1045 |
case ECOMM:
|
|
1046 |
msg = "Communication error on send";
|
|
1047 |
break;
|
77
|
1048 |
#endif
|
|
1049 |
#ifdef EPROTO
|
185
|
1050 |
case EPROTO:
|
|
1051 |
msg = "Protocol error";
|
|
1052 |
break;
|
77
|
1053 |
#endif
|
185
|
1054 |
/*
|
|
1055 |
* nfs errors
|
|
1056 |
*/
|
77
|
1057 |
#ifdef ESTALE
|
185
|
1058 |
case ESTALE:
|
|
1059 |
msg = "Stale NFS file handle";
|
|
1060 |
break;
|
77
|
1061 |
#endif
|
|
1062 |
#ifdef EREMOTE
|
185
|
1063 |
case EREMOTE:
|
|
1064 |
msg = "Too many levels of remote in path";
|
|
1065 |
break;
|
77
|
1066 |
#endif
|
185
|
1067 |
/*
|
|
1068 |
* some networking errors
|
|
1069 |
*/
|
77
|
1070 |
#ifdef EINPROGRESS
|
185
|
1071 |
case EINPROGRESS:
|
|
1072 |
msg = "Operation now in progress";
|
|
1073 |
break;
|
77
|
1074 |
#endif
|
|
1075 |
#ifdef EALREADY
|
185
|
1076 |
case EALREADY:
|
|
1077 |
msg = "Operation already in progress";
|
|
1078 |
break;
|
77
|
1079 |
#endif
|
|
1080 |
#ifdef ENOTSOCK
|
185
|
1081 |
case ENOTSOCK:
|
|
1082 |
msg = "Socket operation on non-socket";
|
|
1083 |
break;
|
77
|
1084 |
#endif
|
|
1085 |
#ifdef EDESTADDRREQ
|
185
|
1086 |
case EDESTADDRREQ:
|
|
1087 |
msg = "Destination address required";
|
|
1088 |
break;
|
77
|
1089 |
#endif
|
|
1090 |
#ifdef EMSGSIZE
|
185
|
1091 |
case EMSGSIZE:
|
|
1092 |
msg = "Message too long";
|
|
1093 |
break;
|
77
|
1094 |
#endif
|
|
1095 |
#ifdef EPROTOTYPE
|
185
|
1096 |
case EPROTOTYPE:
|
|
1097 |
msg = "Protocol wrong type for socket";
|
|
1098 |
break;
|
77
|
1099 |
#endif
|
|
1100 |
#ifdef ENOPROTOOPT
|
185
|
1101 |
case ENOPROTOOPT:
|
|
1102 |
msg = "Protocol not available";
|
|
1103 |
break;
|
77
|
1104 |
#endif
|
|
1105 |
#ifdef EPROTONOSUPPORT
|
185
|
1106 |
case EPROTONOSUPPORT:
|
|
1107 |
msg = "Protocol not supported";
|
|
1108 |
break;
|
77
|
1109 |
#endif
|
|
1110 |
#ifdef ESOCKTNOSUPPORT
|
185
|
1111 |
case ESOCKTNOSUPPORT:
|
|
1112 |
msg = "Socket type not supported";
|
|
1113 |
break;
|
77
|
1114 |
#endif
|
|
1115 |
#ifdef EOPNOTSUPP
|
185
|
1116 |
case EOPNOTSUPP:
|
|
1117 |
msg = "Operation not supported on socket";
|
|
1118 |
break;
|
77
|
1119 |
#endif
|
|
1120 |
#ifdef EPFNOSUPPORT
|
185
|
1121 |
case EPFNOSUPPORT:
|
|
1122 |
msg = "Protocol family not supported";
|
|
1123 |
break;
|
77
|
1124 |
#endif
|
|
1125 |
#ifdef EAFNOSUPPORT
|
185
|
1126 |
case EAFNOSUPPORT:
|
|
1127 |
msg = "Address family not supported by protocol family";
|
|
1128 |
break;
|
77
|
1129 |
#endif
|
|
1130 |
#ifdef EADDRINUSE
|
185
|
1131 |
case EADDRINUSE:
|
|
1132 |
msg = "Address already in use";
|
|
1133 |
break;
|
77
|
1134 |
#endif
|
|
1135 |
#ifdef EADDRNOTAVAIL
|
185
|
1136 |
case EADDRNOTAVAIL:
|
|
1137 |
msg = "Can\'t assign requested address";
|
|
1138 |
break;
|
77
|
1139 |
#endif
|
|
1140 |
#ifdef ETIMEDOUT
|
185
|
1141 |
case ETIMEDOUT:
|
|
1142 |
msg = "Connection timed out";
|
|
1143 |
break;
|
77
|
1144 |
#endif
|
|
1145 |
#ifdef ECONNREFUSED
|
185
|
1146 |
case ECONNREFUSED:
|
|
1147 |
msg = "Connection refused";
|
|
1148 |
break;
|
77
|
1149 |
#endif
|
362
|
1150 |
#ifdef ENETDOWN
|
|
1151 |
case ENETDOWN:
|
|
1152 |
msg = "Network is down";
|
|
1153 |
break;
|
|
1154 |
#endif
|
|
1155 |
#ifdef ENETUNREACH
|
|
1156 |
case ENETUNREACH:
|
|
1157 |
msg = "Network is unreachable";
|
|
1158 |
break;
|
|
1159 |
#endif
|
|
1160 |
#ifdef ENETRESET
|
|
1161 |
case ENETRESET:
|
|
1162 |
msg = "Network dropped conn due to reset";
|
|
1163 |
break;
|
|
1164 |
#endif
|
|
1165 |
#ifdef ECONNABORTED
|
|
1166 |
case ECONNABORTED:
|
|
1167 |
msg = "Software caused connection abort";
|
|
1168 |
break;
|
|
1169 |
#endif
|
|
1170 |
#ifdef ECONNRESET
|
|
1171 |
case ECONNRESET:
|
|
1172 |
msg = "Connection reset by peer";
|
|
1173 |
break;
|
|
1174 |
#endif
|
|
1175 |
#ifdef EISCONN
|
|
1176 |
case EISCONN:
|
|
1177 |
msg = "Socket is already connected";
|
|
1178 |
break;
|
|
1179 |
#endif
|
|
1180 |
#ifdef ENOTCONN
|
|
1181 |
case ENOTCONN:
|
|
1182 |
msg = "Socket is not connected";
|
|
1183 |
break;
|
|
1184 |
#endif
|
|
1185 |
#ifdef ESHUTDOWN
|
|
1186 |
case ESHUTDOWN:
|
|
1187 |
msg = "Can't send after socket shutdown";
|
|
1188 |
break;
|
|
1189 |
#endif
|
|
1190 |
#ifdef EHOSTDOWN
|
|
1191 |
case EHOSTDOWN:
|
|
1192 |
msg = "Host is down";
|
|
1193 |
break;
|
|
1194 |
#endif
|
|
1195 |
#ifdef EHOSTUNREACH
|
|
1196 |
case EHOSTUNREACH:
|
|
1197 |
msg = "No route to host";
|
|
1198 |
break;
|
|
1199 |
#endif
|
|
1200 |
|
185
|
1201 |
default:
|
368
|
1202 |
{
|
|
1203 |
#ifdef THISCONTEXT_IN_REGISTER
|
|
1204 |
extern OBJ __thisContext__;
|
|
1205 |
__thisContext__ = __thisContext;
|
|
1206 |
#endif
|
|
1207 |
sprintf(buffer, "ErrorNr: %d", _intVal(errNr));
|
|
1208 |
#ifdef THISCONTEXT_IN_REGISTER
|
|
1209 |
__thisContext = __thisContext__;
|
|
1210 |
__thisContext__ = nil;
|
|
1211 |
#endif
|
|
1212 |
}
|
185
|
1213 |
msg = buffer;
|
|
1214 |
break;
|
|
1215 |
}
|
77
|
1216 |
}
|
|
1217 |
RETURN (_MKSTRING(msg COMMA_CON));
|
|
1218 |
%}
|
1
|
1219 |
! !
|
|
1220 |
|
345
|
1221 |
!OperatingSystem class methodsFor:'OS signal constants'!
|
68
|
1222 |
|
|
1223 |
sigHUP
|
|
1224 |
"return the signal number for SIGHUP
|
|
1225 |
(the numeric value is not the same across unix-systems)"
|
|
1226 |
|
|
1227 |
%{ /* NOCONTEXT */
|
|
1228 |
return _MKSMALLINT(SIGHUP);
|
|
1229 |
%}
|
|
1230 |
!
|
|
1231 |
|
|
1232 |
sigINT
|
|
1233 |
"return the signal number for SIGINT
|
|
1234 |
(the numeric value is not the same across unix-systems)"
|
|
1235 |
|
|
1236 |
%{ /* NOCONTEXT */
|
|
1237 |
return _MKSMALLINT(SIGINT);
|
|
1238 |
%}
|
|
1239 |
!
|
|
1240 |
|
|
1241 |
sigQUIT
|
|
1242 |
"return the signal number for SIGQUIT
|
|
1243 |
(the numeric value is not the same across unix-systems)"
|
|
1244 |
|
|
1245 |
%{ /* NOCONTEXT */
|
|
1246 |
return _MKSMALLINT(SIGQUIT);
|
|
1247 |
%}
|
|
1248 |
!
|
|
1249 |
|
|
1250 |
sigILL
|
|
1251 |
"return the signal number for SIGILL - 0 if not supported by OS
|
|
1252 |
(the numeric value is not the same across unix-systems)"
|
|
1253 |
|
|
1254 |
%{ /* NOCONTEXT */
|
|
1255 |
#ifdef SIGILL
|
|
1256 |
return _MKSMALLINT(SIGILL);
|
|
1257 |
#else
|
|
1258 |
return _MKSMALLINT(0);
|
|
1259 |
#endif
|
|
1260 |
%}
|
|
1261 |
!
|
|
1262 |
|
|
1263 |
sigTRAP
|
|
1264 |
"return the signal number for SIGTRAP - 0 if not supported by OS
|
|
1265 |
(the numeric value is not the same across unix-systems)"
|
|
1266 |
|
|
1267 |
%{ /* NOCONTEXT */
|
|
1268 |
#ifdef SIGTRAP
|
|
1269 |
return _MKSMALLINT(SIGTRAP);
|
|
1270 |
#else
|
|
1271 |
return _MKSMALLINT(0);
|
|
1272 |
#endif
|
|
1273 |
%}
|
|
1274 |
!
|
|
1275 |
|
345
|
1276 |
sigABRT
|
|
1277 |
"return the signal number for SIGABRT - 0 if not supported by OS
|
|
1278 |
(the numeric value is not the same across unix-systems)"
|
|
1279 |
|
|
1280 |
%{ /* NOCONTEXT */
|
|
1281 |
#ifdef SIGABRT
|
|
1282 |
return _MKSMALLINT(SIGABRT);
|
|
1283 |
#else
|
|
1284 |
return _MKSMALLINT(0);
|
|
1285 |
#endif
|
|
1286 |
%}
|
|
1287 |
!
|
|
1288 |
|
68
|
1289 |
sigIOT
|
|
1290 |
"return the signal number for SIGIOT - 0 if not supported by OS
|
|
1291 |
(the numeric value is not the same across unix-systems)"
|
|
1292 |
|
|
1293 |
%{ /* NOCONTEXT */
|
|
1294 |
#ifdef SIGIOT
|
|
1295 |
return _MKSMALLINT(SIGIOT);
|
|
1296 |
#else
|
|
1297 |
return _MKSMALLINT(0);
|
|
1298 |
#endif
|
|
1299 |
%}
|
|
1300 |
!
|
|
1301 |
|
|
1302 |
sigEMT
|
|
1303 |
"return the signal number for SIGEMT - 0 if not supported by OS
|
|
1304 |
(the numeric value is not the same across unix-systems)"
|
|
1305 |
|
|
1306 |
%{ /* NOCONTEXT */
|
|
1307 |
#ifdef SIGEMT
|
|
1308 |
return _MKSMALLINT(SIGEMT);
|
|
1309 |
#else
|
|
1310 |
return _MKSMALLINT(0);
|
|
1311 |
#endif
|
|
1312 |
%}
|
|
1313 |
!
|
|
1314 |
|
|
1315 |
sigFP
|
|
1316 |
"return the signal number for SIGFP - 0 if not supported by OS
|
|
1317 |
(the numeric value is not the same across unix-systems)"
|
|
1318 |
|
|
1319 |
%{ /* NOCONTEXT */
|
|
1320 |
#ifdef SIGFPE
|
|
1321 |
return _MKSMALLINT(SIGFPE);
|
|
1322 |
#else
|
|
1323 |
return _MKSMALLINT(0);
|
|
1324 |
#endif
|
|
1325 |
%}
|
|
1326 |
!
|
|
1327 |
|
|
1328 |
sigKILL
|
|
1329 |
"return the signal number for SIGKILL
|
|
1330 |
(the numeric value is not the same across unix-systems)"
|
|
1331 |
|
|
1332 |
%{ /* NOCONTEXT */
|
|
1333 |
return _MKSMALLINT(SIGKILL);
|
|
1334 |
%}
|
|
1335 |
!
|
|
1336 |
|
|
1337 |
sigBUS
|
|
1338 |
"return the signal number for SIGBUS - 0 if not supported
|
|
1339 |
(the numeric value is not the same across unix-systems)"
|
|
1340 |
|
|
1341 |
%{ /* NOCONTEXT */
|
|
1342 |
#ifdef SIGBUS
|
|
1343 |
return _MKSMALLINT(SIGBUS);
|
|
1344 |
#else
|
|
1345 |
return _MKSMALLINT(0);
|
|
1346 |
#endif
|
|
1347 |
%}
|
|
1348 |
!
|
|
1349 |
|
|
1350 |
sigSEGV
|
|
1351 |
"return the signal number for SIGSEGV - 0 if not supported
|
|
1352 |
(the numeric value is not the same across unix-systems)"
|
|
1353 |
|
|
1354 |
%{ /* NOCONTEXT */
|
|
1355 |
#ifdef SIGSEGV
|
|
1356 |
return _MKSMALLINT(SIGSEGV);
|
|
1357 |
#else
|
|
1358 |
return _MKSMALLINT(0);
|
|
1359 |
#endif
|
|
1360 |
%}
|
|
1361 |
!
|
|
1362 |
|
|
1363 |
sigSYS
|
|
1364 |
"return the signal number for SIGSYS - 0 if not supported
|
|
1365 |
(the numeric value is not the same across unix-systems)"
|
|
1366 |
|
|
1367 |
%{ /* NOCONTEXT */
|
|
1368 |
#ifdef SIGSYS
|
|
1369 |
return _MKSMALLINT(SIGSYS);
|
|
1370 |
#else
|
|
1371 |
return _MKSMALLINT(0);
|
|
1372 |
#endif
|
|
1373 |
%}
|
|
1374 |
!
|
|
1375 |
|
|
1376 |
sigPIPE
|
|
1377 |
"return the signal number for SIGPIPE - 0 if not supported
|
|
1378 |
(the numeric value is not the same across unix-systems)"
|
|
1379 |
|
|
1380 |
%{ /* NOCONTEXT */
|
|
1381 |
#ifdef SIGPIPE
|
|
1382 |
return _MKSMALLINT(SIGPIPE);
|
|
1383 |
#else
|
|
1384 |
return _MKSMALLINT(0);
|
|
1385 |
#endif
|
|
1386 |
%}
|
|
1387 |
!
|
|
1388 |
|
|
1389 |
sigALRM
|
|
1390 |
"return the signal number for SIGALRM - 0 if not supported
|
|
1391 |
(the numeric value is not the same across unix-systems)"
|
|
1392 |
|
|
1393 |
%{ /* NOCONTEXT */
|
|
1394 |
return _MKSMALLINT(SIGALRM);
|
|
1395 |
%}
|
|
1396 |
!
|
|
1397 |
|
|
1398 |
sigTERM
|
|
1399 |
"return the signal number for SIGTERM - 0 if not supported
|
|
1400 |
(the numeric value is not the same across unix-systems)"
|
|
1401 |
|
|
1402 |
%{ /* NOCONTEXT */
|
|
1403 |
#ifdef SIGTERM
|
|
1404 |
return _MKSMALLINT(SIGTERM);
|
|
1405 |
#else
|
|
1406 |
return _MKSMALLINT(0);
|
|
1407 |
#endif
|
|
1408 |
%}
|
|
1409 |
!
|
|
1410 |
|
|
1411 |
sigURG
|
|
1412 |
"return the signal number for SIGURG - 0 if not supported
|
|
1413 |
(the numeric value is not the same across unix-systems)"
|
|
1414 |
|
|
1415 |
%{ /* NOCONTEXT */
|
|
1416 |
#if defined(SIGURG)
|
|
1417 |
return _MKSMALLINT(SIGURG);
|
|
1418 |
#else
|
|
1419 |
return _MKSMALLINT(0);
|
|
1420 |
#endif
|
|
1421 |
%}
|
|
1422 |
!
|
|
1423 |
|
|
1424 |
sigSTOP
|
|
1425 |
"return the signal number for SIGSTOP - 0 if not supported
|
|
1426 |
(the numeric value is not the same across unix-systems)"
|
|
1427 |
|
|
1428 |
%{ /* NOCONTEXT */
|
|
1429 |
#if defined(SIGSTOP)
|
|
1430 |
return _MKSMALLINT(SIGSTOP);
|
|
1431 |
#else
|
|
1432 |
return _MKSMALLINT(0);
|
|
1433 |
#endif
|
|
1434 |
%}
|
|
1435 |
!
|
|
1436 |
|
|
1437 |
sigTSTP
|
|
1438 |
"return the signal number for SIGTSTP - 0 if not supported
|
|
1439 |
(the numeric value is not the same across unix-systems)"
|
|
1440 |
|
|
1441 |
%{ /* NOCONTEXT */
|
|
1442 |
#if defined(SIGTSTP)
|
|
1443 |
return _MKSMALLINT(SIGTSTP);
|
|
1444 |
#else
|
|
1445 |
return _MKSMALLINT(0);
|
|
1446 |
#endif
|
|
1447 |
%}
|
|
1448 |
!
|
|
1449 |
|
|
1450 |
sigCONT
|
|
1451 |
"return the signal number for SIGCONT - 0 if not supported
|
|
1452 |
(the numeric value is not the same across unix-systems)"
|
|
1453 |
|
|
1454 |
%{ /* NOCONTEXT */
|
|
1455 |
#if defined(SIGCONT)
|
|
1456 |
return _MKSMALLINT(SIGCONT);
|
|
1457 |
#else
|
|
1458 |
return _MKSMALLINT(0);
|
|
1459 |
#endif
|
|
1460 |
%}
|
|
1461 |
!
|
|
1462 |
|
|
1463 |
sigCHLD
|
|
1464 |
"return the signal number for SIGCHLD - 0 if not supported
|
|
1465 |
(the numeric value is not the same across unix-systems)"
|
|
1466 |
|
|
1467 |
%{ /* NOCONTEXT */
|
|
1468 |
#if defined(SIGCHLD)
|
|
1469 |
return _MKSMALLINT(SIGCHLD);
|
|
1470 |
#else
|
|
1471 |
# if defined(SIGCLD)
|
|
1472 |
return _MKSMALLINT(SIGCLD);
|
|
1473 |
# else
|
|
1474 |
return _MKSMALLINT(0);
|
|
1475 |
# endif
|
|
1476 |
#endif
|
|
1477 |
%}
|
|
1478 |
!
|
|
1479 |
|
|
1480 |
sigTTIN
|
|
1481 |
"return the signal number for SIGTTIN - 0 if not supported
|
|
1482 |
(the numeric value is not the same across unix-systems)"
|
|
1483 |
|
|
1484 |
%{ /* NOCONTEXT */
|
|
1485 |
#if defined(SIGTTIN)
|
|
1486 |
return _MKSMALLINT(SIGTTIN);
|
|
1487 |
#else
|
|
1488 |
return _MKSMALLINT(0);
|
|
1489 |
#endif
|
|
1490 |
%}
|
|
1491 |
!
|
|
1492 |
|
|
1493 |
sigTTOU
|
|
1494 |
"return the signal number for SIGTTOU - 0 if not supported
|
|
1495 |
(the numeric value is not the same across unix-systems)"
|
|
1496 |
|
|
1497 |
%{ /* NOCONTEXT */
|
|
1498 |
#if defined(SIGTTOU)
|
|
1499 |
return _MKSMALLINT(SIGTTOU);
|
|
1500 |
#else
|
|
1501 |
return _MKSMALLINT(0);
|
|
1502 |
#endif
|
|
1503 |
%}
|
|
1504 |
!
|
|
1505 |
|
|
1506 |
sigIO
|
|
1507 |
"return the signal number for SIGIO - 0 if not supported
|
|
1508 |
(the numeric value is not the same across unix-systems)"
|
|
1509 |
|
|
1510 |
%{ /* NOCONTEXT */
|
|
1511 |
#if defined(SIGIO)
|
|
1512 |
return _MKSMALLINT(SIGIO);
|
|
1513 |
#else
|
|
1514 |
return _MKSMALLINT(0);
|
|
1515 |
#endif
|
|
1516 |
%}
|
|
1517 |
!
|
|
1518 |
|
|
1519 |
sigPOLL
|
|
1520 |
"return the signal number for SIGPOLL - 0 if not supported
|
|
1521 |
(the numeric value is not the same across unix-systems)"
|
|
1522 |
|
|
1523 |
%{ /* NOCONTEXT */
|
|
1524 |
#if defined(SIGPOLL)
|
|
1525 |
return _MKSMALLINT(SIGPOLL);
|
|
1526 |
#else
|
|
1527 |
return _MKSMALLINT(0);
|
|
1528 |
#endif
|
|
1529 |
%}
|
|
1530 |
!
|
|
1531 |
|
|
1532 |
sigXCPU
|
|
1533 |
"return the signal number for SIGXCPU - 0 if not supported
|
|
1534 |
(the numeric value is not the same across unix-systems)"
|
|
1535 |
|
|
1536 |
%{ /* NOCONTEXT */
|
|
1537 |
#if defined(SIGXCPU)
|
|
1538 |
return _MKSMALLINT(SIGXCPU);
|
|
1539 |
#else
|
|
1540 |
return _MKSMALLINT(0);
|
|
1541 |
#endif
|
|
1542 |
%}
|
|
1543 |
!
|
|
1544 |
|
|
1545 |
sigXFSZ
|
|
1546 |
"return the signal number for SIGXFSZ - 0 if not supported
|
|
1547 |
(the numeric value is not the same across unix-systems)"
|
|
1548 |
|
|
1549 |
%{ /* NOCONTEXT */
|
|
1550 |
#if defined(SIGXFSZ)
|
|
1551 |
return _MKSMALLINT(SIGXFSZ);
|
|
1552 |
#else
|
|
1553 |
return _MKSMALLINT(0);
|
|
1554 |
#endif
|
|
1555 |
%}
|
|
1556 |
!
|
|
1557 |
|
|
1558 |
sigVTALRM
|
|
1559 |
"return the signal number for SIGVTALRM - 0 if not supported
|
|
1560 |
(the numeric value is not the same across unix-systems)"
|
|
1561 |
|
|
1562 |
%{ /* NOCONTEXT */
|
|
1563 |
#if defined(SIGVTALRM)
|
|
1564 |
return _MKSMALLINT(SIGVTALRM);
|
|
1565 |
#else
|
|
1566 |
return _MKSMALLINT(0);
|
|
1567 |
#endif
|
|
1568 |
%}
|
|
1569 |
!
|
|
1570 |
|
|
1571 |
sigPROF
|
|
1572 |
"return the signal number for SIGPROF - 0 if not supported
|
|
1573 |
(the numeric value is not the same across unix-systems)"
|
|
1574 |
|
|
1575 |
%{ /* NOCONTEXT */
|
|
1576 |
#if defined(SIGPROF)
|
|
1577 |
return _MKSMALLINT(SIGPROF);
|
|
1578 |
#else
|
|
1579 |
return _MKSMALLINT(0);
|
|
1580 |
#endif
|
|
1581 |
%}
|
|
1582 |
!
|
|
1583 |
|
|
1584 |
sigWINCH
|
|
1585 |
"return the signal number for SIGWINCH - 0 if not supported
|
|
1586 |
(the numeric value is not the same across unix-systems)"
|
|
1587 |
|
|
1588 |
%{ /* NOCONTEXT */
|
|
1589 |
#if defined(SIGWINCH)
|
|
1590 |
return _MKSMALLINT(SIGWINCH);
|
|
1591 |
#else
|
|
1592 |
return _MKSMALLINT(0);
|
|
1593 |
#endif
|
|
1594 |
%}
|
|
1595 |
!
|
|
1596 |
|
|
1597 |
sigLOST
|
|
1598 |
"return the signal number for SIGLOST - 0 if not supported
|
|
1599 |
(the numeric value is not the same across unix-systems)"
|
|
1600 |
|
|
1601 |
%{ /* NOCONTEXT */
|
|
1602 |
#if defined(SIGLOST)
|
|
1603 |
return _MKSMALLINT(SIGLOST);
|
|
1604 |
#else
|
|
1605 |
return _MKSMALLINT(0);
|
|
1606 |
#endif
|
|
1607 |
%}
|
|
1608 |
!
|
|
1609 |
|
|
1610 |
sigUSR1
|
|
1611 |
"return the signal number for SIGUSR1 - 0 if not supported
|
|
1612 |
(the numeric value is not the same across unix-systems)"
|
|
1613 |
|
|
1614 |
%{ /* NOCONTEXT */
|
|
1615 |
#if defined(SIGUSR1)
|
|
1616 |
return _MKSMALLINT(SIGUSR1);
|
|
1617 |
#else
|
|
1618 |
return _MKSMALLINT(0);
|
|
1619 |
#endif
|
|
1620 |
%}
|
|
1621 |
!
|
|
1622 |
|
|
1623 |
sigUSR2
|
|
1624 |
"return the signal number for SIGUSR2 - 0 if not supported
|
|
1625 |
(the numeric value is not the same across unix-systems)"
|
|
1626 |
|
|
1627 |
%{ /* NOCONTEXT */
|
|
1628 |
#if defined(SIGUSR2)
|
|
1629 |
return _MKSMALLINT(SIGUSR2);
|
|
1630 |
#else
|
|
1631 |
return _MKSMALLINT(0);
|
|
1632 |
#endif
|
|
1633 |
%}
|
359
|
1634 |
!
|
|
1635 |
|
|
1636 |
sigMSG
|
|
1637 |
"return the signal number for SIGMSG - 0 if not supported
|
|
1638 |
(seems to be an AIX special)"
|
|
1639 |
|
|
1640 |
%{ /* NOCONTEXT */
|
|
1641 |
#if defined(SIGMSG)
|
|
1642 |
return _MKSMALLINT(SIGMSG);
|
|
1643 |
#else
|
|
1644 |
return _MKSMALLINT(0);
|
|
1645 |
#endif
|
|
1646 |
%}
|
|
1647 |
!
|
|
1648 |
|
|
1649 |
sigPWR
|
|
1650 |
"return the signal number for SIGPWR - 0 if not supported
|
|
1651 |
(not available on all systems)"
|
|
1652 |
|
|
1653 |
%{ /* NOCONTEXT */
|
|
1654 |
#if defined(SIGPWR)
|
|
1655 |
return _MKSMALLINT(SIGPWR);
|
|
1656 |
#else
|
|
1657 |
return _MKSMALLINT(0);
|
|
1658 |
#endif
|
|
1659 |
%}
|
|
1660 |
!
|
|
1661 |
|
|
1662 |
sigMIGRATE
|
|
1663 |
"return the signal number for SIGMIGRATE - 0 if not supported
|
|
1664 |
(seems to be an AIX special)"
|
|
1665 |
|
|
1666 |
%{ /* NOCONTEXT */
|
|
1667 |
#if defined(SIGMIGRATE)
|
|
1668 |
return _MKSMALLINT(SIGMIGRATE);
|
|
1669 |
#else
|
|
1670 |
return _MKSMALLINT(0);
|
|
1671 |
#endif
|
|
1672 |
%}
|
|
1673 |
!
|
|
1674 |
|
|
1675 |
sigPRE
|
|
1676 |
"return the signal number for SIGPRE - 0 if not supported
|
|
1677 |
(seems to be an AIX special)"
|
|
1678 |
|
|
1679 |
%{ /* NOCONTEXT */
|
|
1680 |
#if defined(SIGPRE)
|
|
1681 |
return _MKSMALLINT(SIGPRE);
|
|
1682 |
#else
|
|
1683 |
return _MKSMALLINT(0);
|
|
1684 |
#endif
|
|
1685 |
%}
|
|
1686 |
!
|
|
1687 |
|
|
1688 |
sigGRANT
|
|
1689 |
"return the signal number for SIGGRANT - 0 if not supported
|
|
1690 |
(seems to be an AIX special)"
|
|
1691 |
|
|
1692 |
%{ /* NOCONTEXT */
|
|
1693 |
#if defined(SIGGRANT)
|
|
1694 |
return _MKSMALLINT(SIGGRANT);
|
|
1695 |
#else
|
|
1696 |
return _MKSMALLINT(0);
|
|
1697 |
#endif
|
|
1698 |
%}
|
|
1699 |
!
|
|
1700 |
|
|
1701 |
sigRETRACT
|
|
1702 |
"return the signal number for SIGRETRACT - 0 if not supported
|
|
1703 |
(seems to be an AIX special)"
|
|
1704 |
|
|
1705 |
%{ /* NOCONTEXT */
|
|
1706 |
#if defined(SIGRETRACT)
|
|
1707 |
return _MKSMALLINT(SIGRETRACT);
|
|
1708 |
#else
|
|
1709 |
return _MKSMALLINT(0);
|
|
1710 |
#endif
|
|
1711 |
%}
|
|
1712 |
!
|
|
1713 |
|
|
1714 |
sigSOUND
|
|
1715 |
"return the signal number for SIGSOUND - 0 if not supported
|
|
1716 |
(seems to be an AIX special)"
|
|
1717 |
|
|
1718 |
%{ /* NOCONTEXT */
|
|
1719 |
#if defined(SIGSOUND)
|
|
1720 |
return _MKSMALLINT(SIGSOUND);
|
|
1721 |
#else
|
|
1722 |
return _MKSMALLINT(0);
|
|
1723 |
#endif
|
|
1724 |
%}
|
|
1725 |
!
|
|
1726 |
|
|
1727 |
sigSAK
|
|
1728 |
"return the signal number for SIGSAK - 0 if not supported
|
|
1729 |
(seems to be an AIX special)"
|
|
1730 |
|
|
1731 |
%{ /* NOCONTEXT */
|
|
1732 |
#if defined(SIGSAK)
|
|
1733 |
return _MKSMALLINT(SIGSAK);
|
|
1734 |
#else
|
|
1735 |
return _MKSMALLINT(0);
|
|
1736 |
#endif
|
|
1737 |
%}
|
370
|
1738 |
!
|
|
1739 |
|
|
1740 |
sigDANGER
|
|
1741 |
"return the signal number for SIGDANGER - 0 if not supported
|
|
1742 |
(seems to be an AIX special)"
|
|
1743 |
|
|
1744 |
%{ /* NOCONTEXT */
|
|
1745 |
#if defined(SIGSAK)
|
|
1746 |
return _MKSMALLINT(SIGSAK);
|
|
1747 |
#else
|
|
1748 |
return _MKSMALLINT(0);
|
|
1749 |
#endif
|
|
1750 |
%}
|
68
|
1751 |
! !
|
|
1752 |
|
63
|
1753 |
!OperatingSystem class methodsFor:'interrupts & signals'!
|
|
1754 |
|
|
1755 |
nameForSignal:aSignalNumber
|
|
1756 |
"for a given Unix signalnumber, return a descriptive string"
|
1
|
1757 |
|
68
|
1758 |
aSignalNumber == self sigHUP ifTrue:[^ 'hangup'].
|
|
1759 |
aSignalNumber == self sigINT ifTrue:[^ 'interrupt'].
|
|
1760 |
aSignalNumber == self sigKILL ifTrue:[^ 'kill'].
|
|
1761 |
aSignalNumber == self sigQUIT ifTrue:[^ 'quit'].
|
|
1762 |
aSignalNumber == self sigILL ifTrue:[^ 'illegal instruction'].
|
|
1763 |
aSignalNumber == self sigTRAP ifTrue:[^ 'trap'].
|
345
|
1764 |
aSignalNumber == self sigABRT ifTrue:[^ 'abort'].
|
68
|
1765 |
aSignalNumber == self sigIOT ifTrue:[^ 'iot trap'].
|
|
1766 |
aSignalNumber == self sigEMT ifTrue:[^ 'emt trap'].
|
|
1767 |
aSignalNumber == self sigFP ifTrue:[^ 'fp exception'].
|
|
1768 |
aSignalNumber == self sigBUS ifTrue:[^ 'bus error'].
|
|
1769 |
aSignalNumber == self sigSEGV ifTrue:[^ 'segmentation violation'].
|
|
1770 |
aSignalNumber == self sigSYS ifTrue:[^ 'bad system call'].
|
|
1771 |
aSignalNumber == self sigPIPE ifTrue:[^ 'broken pipe'].
|
|
1772 |
aSignalNumber == self sigALRM ifTrue:[^ 'alarm timer'].
|
|
1773 |
aSignalNumber == self sigTERM ifTrue:[^ 'termination'].
|
|
1774 |
aSignalNumber == self sigSTOP ifTrue:[^ 'stop'].
|
|
1775 |
aSignalNumber == self sigTSTP ifTrue:[^ 'tty stop'].
|
|
1776 |
aSignalNumber == self sigCONT ifTrue:[^ 'continue'].
|
|
1777 |
aSignalNumber == self sigCHLD ifTrue:[^ 'child death'].
|
|
1778 |
aSignalNumber == self sigTTIN ifTrue:[^ 'background tty input'].
|
|
1779 |
aSignalNumber == self sigTTOU ifTrue:[^ 'background tty output'].
|
|
1780 |
aSignalNumber == self sigIO ifTrue:[^ 'io available'].
|
|
1781 |
aSignalNumber == self sigXCPU ifTrue:[^ 'cpu time expired'].
|
|
1782 |
aSignalNumber == self sigXFSZ ifTrue:[^ 'file size limit'].
|
|
1783 |
aSignalNumber == self sigVTALRM ifTrue:[^ 'virtual alarm timer'].
|
|
1784 |
aSignalNumber == self sigPROF ifTrue:[^ 'profiling timer'].
|
|
1785 |
aSignalNumber == self sigWINCH ifTrue:[^ 'winsize changed'].
|
|
1786 |
aSignalNumber == self sigLOST ifTrue:[^ 'resource lost'].
|
|
1787 |
aSignalNumber == self sigUSR1 ifTrue:[^ 'user signal 1'].
|
|
1788 |
aSignalNumber == self sigUSR2 ifTrue:[^ 'user signal 2'].
|
359
|
1789 |
aSignalNumber == self sigMSG ifTrue:[^ 'HFT message'].
|
|
1790 |
aSignalNumber == self sigPWR ifTrue:[^ 'power-fail'].
|
|
1791 |
aSignalNumber == self sigPRE ifTrue:[^ 'programming exception'].
|
|
1792 |
aSignalNumber == self sigGRANT ifTrue:[^ 'HFT access wanted'].
|
|
1793 |
aSignalNumber == self sigRETRACT ifTrue:[^ 'HFT access relinquish'].
|
|
1794 |
aSignalNumber == self sigSOUND ifTrue:[^ 'HFT sound complete'].
|
370
|
1795 |
aSignalNumber == self sigDANGER ifTrue:[^ 'low on paging space'].
|
359
|
1796 |
|
68
|
1797 |
"notice: many systems map SIGPOLL and/or SIGUSR onto SIGIO
|
359
|
1798 |
therefore, keep SIGIO always above the two below"
|
68
|
1799 |
aSignalNumber == self sigPOLL ifTrue:[^ 'io available'].
|
|
1800 |
aSignalNumber == self sigURG ifTrue:[^ 'urgent'].
|
|
1801 |
|
|
1802 |
^ 'unknown signal'
|
|
1803 |
|
|
1804 |
"
|
|
1805 |
OperatingSystem nameForSignal:9
|
|
1806 |
OperatingSystem nameForSignal:(OperatingSystem sigPOLL)
|
|
1807 |
"
|
63
|
1808 |
!
|
68
|
1809 |
|
95
|
1810 |
interruptPending
|
|
1811 |
"return true, if an interrupt is pending. The returned value is
|
|
1812 |
invalid if interrupts are not currently blocked, since otherwise
|
|
1813 |
the interrupt is usually already handled before arriving here,
|
|
1814 |
or may be served while returning from here."
|
|
1815 |
|
|
1816 |
%{ /* NOCONTEXT */
|
329
|
1817 |
extern OBJ __INTERRUPTPENDING();
|
|
1818 |
|
|
1819 |
RETURN ( __INTERRUPTPENDING() );
|
95
|
1820 |
%}
|
|
1821 |
!
|
|
1822 |
|
10
|
1823 |
blockInterrupts
|
95
|
1824 |
"disable interrupt processing - if disabled, incoming
|
|
1825 |
interrupts will be registered and handled as soon as
|
|
1826 |
interrupts are reenabled by OperatingSystemclass>>unblockInterrupts.
|
|
1827 |
Returns the previous blocking status i.e. true if interrupts
|
|
1828 |
where already blocked. You need this information for proper
|
|
1829 |
unblocking, in case of nested block/unblock calls."
|
|
1830 |
|
|
1831 |
%{ /* NOCONTEXT */
|
356
|
1832 |
extern OBJ __BLOCKINTERRUPTS();
|
|
1833 |
|
|
1834 |
return ( __BLOCKINTERRUPTS() );
|
10
|
1835 |
%}
|
|
1836 |
!
|
|
1837 |
|
|
1838 |
unblockInterrupts
|
63
|
1839 |
"enable interrupt processing - if any interrupts are pending,
|
|
1840 |
these will be handled immediately.
|
95
|
1841 |
When unblocking interrupts, take care of nested block/unblock
|
|
1842 |
calls - you must only unblock after a blockcall if they where
|
|
1843 |
really not blocked before. See OperatingSystemclass>>blockInterrupts."
|
10
|
1844 |
%{
|
356
|
1845 |
extern void __UNBLOCKINTERRUPTS();
|
|
1846 |
|
|
1847 |
__UNBLOCKINTERRUPTS();
|
10
|
1848 |
%}
|
|
1849 |
!
|
|
1850 |
|
63
|
1851 |
disableSignal:signalNumber
|
95
|
1852 |
"disable (Unix-) signal processing for signalNumber.
|
|
1853 |
Dont confuse Unix signals with smalltalk signals.
|
63
|
1854 |
WARNING: for some signals, it is no good idea to disable
|
95
|
1855 |
them; for example, disabling the SIGINT signal turns off ^C
|
63
|
1856 |
handling.
|
68
|
1857 |
Also, NOTICE that signal numbers are not portable between unix
|
|
1858 |
systems - use OperatingSystem sigXXX to get the numeric value for
|
|
1859 |
a signal.
|
63
|
1860 |
Use only for fully debugged stand alone applications."
|
|
1861 |
|
|
1862 |
%{ /* NOCONTEXT */
|
|
1863 |
|
252
|
1864 |
if (__isSmallInteger(signalNumber)) {
|
185
|
1865 |
signal(_intVal(signalNumber), SIG_IGN);
|
|
1866 |
RETURN (self);
|
63
|
1867 |
}
|
68
|
1868 |
%}.
|
|
1869 |
"
|
|
1870 |
this error is triggered on non-integer argument
|
|
1871 |
"
|
|
1872 |
self primitiveFailed
|
|
1873 |
|
|
1874 |
"
|
|
1875 |
'now, ^C is totally ignored ...' printNewline.
|
|
1876 |
OperatingSystem disableSignal:(OperatingSystem sigINT).
|
|
1877 |
1 to:1000000 do:[:i| ].
|
|
1878 |
OperatingSystem enableSignal:(OperatingSystem sigINT).
|
|
1879 |
'^C handled again.' printNewline
|
|
1880 |
"
|
|
1881 |
!
|
|
1882 |
|
|
1883 |
defaultSignal:signalNumber
|
95
|
1884 |
"revert to the default action on arrival of a (Unix-)signal.
|
|
1885 |
Dont confuse Unix signals with smalltalk signals.
|
68
|
1886 |
WARNING: for some signals, it is no good idea to revert to default;
|
|
1887 |
for example, the default for SIGINT (i.e. ^C) is to exit; while the
|
|
1888 |
default for SIGQUIT (^ \) is to dump core.
|
|
1889 |
Also, NOTICE that signal numbers are not portable between unix
|
|
1890 |
systems - use OperatingSystem sigXXX to get the numeric value for
|
|
1891 |
a signal."
|
|
1892 |
|
|
1893 |
%{ /* NOCONTEXT */
|
|
1894 |
|
252
|
1895 |
if (__isSmallInteger(signalNumber)) {
|
185
|
1896 |
signal(_intVal(signalNumber), SIG_DFL);
|
|
1897 |
RETURN (self);
|
68
|
1898 |
}
|
|
1899 |
%}.
|
|
1900 |
"
|
|
1901 |
this error is triggered on non-integer argument
|
|
1902 |
"
|
|
1903 |
self primitiveFailed
|
|
1904 |
|
|
1905 |
"you better save a snapshot image before trying this ..."
|
|
1906 |
"
|
|
1907 |
'if you hit ^C now, Smalltalk will exit immediately' printNewline.
|
|
1908 |
OperatingSystem defaultSignal:(OperatingSystem sigINT).
|
|
1909 |
1 to:1000000 do:[:i| ].
|
|
1910 |
OperatingSystem enableSignal:(OperatingSystem sigINT).
|
|
1911 |
'normal ^C handling again.' printNewline
|
|
1912 |
"
|
|
1913 |
!
|
|
1914 |
|
|
1915 |
enableSignal:signalNumber
|
95
|
1916 |
"enable (Unix-)signal processing for signalNumber.
|
|
1917 |
Dont confuse Unix signals with smalltalk signals.
|
68
|
1918 |
The signal will be delivered to one of the standard handlers
|
|
1919 |
(SIGINT, SIGQUIT, etc) or to a general handler, which
|
|
1920 |
sends #signalInterrupt:.
|
|
1921 |
|
|
1922 |
NOTICE that signal numbers are not portable between unix
|
|
1923 |
systems - use OperatingSystem sigXXX to get the numeric value for
|
|
1924 |
a signal."
|
|
1925 |
|
|
1926 |
%{ /* NOCONTEXT */
|
|
1927 |
|
|
1928 |
#ifdef NSIG
|
|
1929 |
# define SIG_LIMIT NSIG
|
|
1930 |
#else
|
|
1931 |
# ifdef SIGUSR2
|
|
1932 |
# define SIG_LIMIT SIGUSR2
|
|
1933 |
# else
|
|
1934 |
# ifdef SIGUSR
|
|
1935 |
# define SIG_LIMIT SIGUSR
|
|
1936 |
# endif
|
|
1937 |
# endif
|
|
1938 |
#endif
|
|
1939 |
|
|
1940 |
#if defined(SIGPOLL) && !defined(SIGIO)
|
|
1941 |
# define SIGIO SIGPOLL
|
|
1942 |
#endif
|
|
1943 |
|
|
1944 |
#ifdef SIGCHLD
|
|
1945 |
# define CHILD_SIGNAL SIGCHLD
|
|
1946 |
#else
|
|
1947 |
# ifdef SIGCLD
|
|
1948 |
# define CHILD_SIGNAL SIGCLD
|
|
1949 |
# endif
|
|
1950 |
#endif
|
|
1951 |
|
|
1952 |
int sigNr;
|
329
|
1953 |
extern void __signalUserInterrupt();
|
|
1954 |
extern void __signalFpExceptionInterrupt();
|
|
1955 |
extern void __signalIoInterrupt();
|
68
|
1956 |
#ifdef CHILD_SIGNAL
|
329
|
1957 |
extern void __signalChildInterrupt();
|
68
|
1958 |
#endif
|
329
|
1959 |
extern void __signalPIPEInterrupt();
|
|
1960 |
extern void __signalBUSInterrupt();
|
|
1961 |
extern void __signalSEGVInterrupt();
|
|
1962 |
extern void __signalTimerInterrupt();
|
|
1963 |
extern void __signalInterrupt();
|
213
|
1964 |
void (*handler)();
|
|
1965 |
#ifdef HAS_SIGACTION
|
|
1966 |
struct sigaction act, oldAct;
|
|
1967 |
#endif
|
68
|
1968 |
|
252
|
1969 |
if (__isSmallInteger(signalNumber)
|
68
|
1970 |
&& ((sigNr = _intVal(signalNumber)) > 0)
|
|
1971 |
&& (sigNr <= SIG_LIMIT)) {
|
185
|
1972 |
/*
|
|
1973 |
* standard signals are forced into standard handlers
|
|
1974 |
* - all others go into general signalInterrupt
|
|
1975 |
*/
|
68
|
1976 |
#if defined(SIGPOLL) && defined(SIGIO)
|
185
|
1977 |
if (sigNr == SIGPOLL)
|
|
1978 |
sigNr = SIGIO;
|
68
|
1979 |
#endif
|
185
|
1980 |
switch (sigNr) {
|
|
1981 |
case SIGINT:
|
|
1982 |
case SIGQUIT:
|
329
|
1983 |
handler = __signalUserInterrupt;
|
185
|
1984 |
break;
|
|
1985 |
|
|
1986 |
case SIGFPE:
|
329
|
1987 |
handler = __signalFpExceptionInterrupt;
|
185
|
1988 |
break;
|
|
1989 |
|
|
1990 |
case SIGPIPE:
|
329
|
1991 |
handler = __signalPIPEInterrupt;
|
185
|
1992 |
break;
|
68
|
1993 |
#ifdef SIGBUS
|
185
|
1994 |
case SIGBUS:
|
329
|
1995 |
handler = __signalBUSInterrupt;
|
185
|
1996 |
break;
|
68
|
1997 |
#endif
|
185
|
1998 |
case SIGSEGV:
|
329
|
1999 |
handler = __signalSEGVInterrupt;
|
185
|
2000 |
break;
|
68
|
2001 |
#ifdef SIGIO
|
185
|
2002 |
case SIGIO:
|
329
|
2003 |
handler = __signalIoInterrupt;
|
185
|
2004 |
break;
|
68
|
2005 |
#endif
|
|
2006 |
|
|
2007 |
#ifdef CHILD_SIGNAL
|
185
|
2008 |
case CHILD_SIGNAL:
|
329
|
2009 |
handler = __signalChildInterrupt;
|
185
|
2010 |
break;
|
68
|
2011 |
#endif
|
185
|
2012 |
case SIGALRM:
|
329
|
2013 |
handler = __signalTimerInterrupt;
|
185
|
2014 |
break;
|
|
2015 |
|
|
2016 |
default:
|
329
|
2017 |
handler = __signalInterrupt;
|
185
|
2018 |
break;
|
|
2019 |
}
|
213
|
2020 |
#ifdef HAS_SIGACTION
|
216
|
2021 |
act.sa_flags = SA_RESTART;
|
373
|
2022 |
sigemptyset(&act.sa_mask);
|
|
2023 |
act.sa_handler = handler;
|
213
|
2024 |
sigaction(sigNr, &act, &oldAct);
|
|
2025 |
#else
|
|
2026 |
signal(sigNr, handler);
|
|
2027 |
#endif
|
|
2028 |
|
185
|
2029 |
/*
|
|
2030 |
* maybe, we should return the old enable-status
|
|
2031 |
* as boolean here ...
|
|
2032 |
*/
|
|
2033 |
RETURN (self);
|
68
|
2034 |
}
|
|
2035 |
%}.
|
|
2036 |
|
|
2037 |
"
|
|
2038 |
this error is triggered on non-integer argument, or
|
|
2039 |
if the signal number is not in the valid range (1..NSIG)
|
|
2040 |
"
|
63
|
2041 |
self primitiveFailed
|
|
2042 |
!
|
|
2043 |
|
1
|
2044 |
enableUserInterrupts
|
|
2045 |
"enable userInterrupt (^C) handling;
|
95
|
2046 |
when enabled, ^C in the terminal window will send the message
|
|
2047 |
'userInterrupt' to the UserInterruptHandler object."
|
1
|
2048 |
|
68
|
2049 |
^ self enableSignal:(self sigINT)
|
63
|
2050 |
!
|
|
2051 |
|
|
2052 |
enableQuitInterrupts
|
68
|
2053 |
"enable quitInterrupt (usually ^\) handling, and make it a userinterrupt.
|
|
2054 |
(the default will dump core and exit - which is not a good idea for
|
|
2055 |
end-user applications ...)"
|
|
2056 |
|
|
2057 |
^ self enableSignal:(self sigQUIT)
|
63
|
2058 |
!
|
|
2059 |
|
|
2060 |
disableUserInterrupts
|
|
2061 |
"disable userInterrupt processing;
|
95
|
2062 |
when disabled, no ^C processing takes place.
|
63
|
2063 |
Use this only for debugged stand-alone applications, since
|
|
2064 |
no exit to the debugger is possible with user interrupts disabled.
|
|
2065 |
Be WARNED."
|
|
2066 |
|
68
|
2067 |
^ self disableSignal:(self sigINT)
|
1
|
2068 |
!
|
|
2069 |
|
|
2070 |
enableFpExceptionInterrupts
|
|
2071 |
"enable floating point exception interrupts (if the
|
|
2072 |
architecture supports it).
|
|
2073 |
after enabling, fpu-exceptions will send the message
|
|
2074 |
'fpuExceptionInterrupt' to the FPUExceptionInterruptHandler object."
|
|
2075 |
|
68
|
2076 |
^ self enableSignal:(self sigFP)
|
1
|
2077 |
!
|
|
2078 |
|
77
|
2079 |
enableHardSignalInterrupts
|
|
2080 |
"enable hard signal exception interrupts (trap, buserror & segm. violation).
|
1
|
2081 |
after enabling, these exceptions will send the message
|
|
2082 |
'signalInterrupt' to the SignalInterruptHandler object."
|
|
2083 |
|
|
2084 |
%{ /* NOCONTEXT */
|
68
|
2085 |
|
329
|
2086 |
extern void __signalPIPEInterrupt();
|
77
|
2087 |
#ifdef SIGBUS
|
329
|
2088 |
extern void __signalBUSInterrupt();
|
77
|
2089 |
#endif
|
329
|
2090 |
extern void __signalSEGVInterrupt();
|
|
2091 |
|
|
2092 |
signal(SIGPIPE, __signalPIPEInterrupt);
|
1
|
2093 |
#ifdef SIGBUS
|
329
|
2094 |
signal(SIGBUS, __signalBUSInterrupt);
|
1
|
2095 |
#endif
|
329
|
2096 |
signal(SIGSEGV, __signalSEGVInterrupt);
|
1
|
2097 |
%}
|
|
2098 |
!
|
|
2099 |
|
10
|
2100 |
enableIOInterruptsOn:fd
|
|
2101 |
"turn on IO interrupts for a filedescriptor"
|
1
|
2102 |
|
|
2103 |
%{ /* NOCONTEXT */
|
10
|
2104 |
|
216
|
2105 |
int ret, flags, f;
|
329
|
2106 |
extern void __signalIoInterrupt();
|
216
|
2107 |
static int firstCall = 1;
|
1
|
2108 |
|
10
|
2109 |
#if defined(F_GETFL) && defined(F_SETFL)
|
|
2110 |
# if defined(FASYNC)
|
252
|
2111 |
if (__isSmallInteger(fd)) {
|
216
|
2112 |
if (firstCall) {
|
|
2113 |
firstCall = 0;
|
|
2114 |
# ifdef SIGIO
|
329
|
2115 |
signal(SIGIO, __signalIoInterrupt);
|
10
|
2116 |
# endif
|
216
|
2117 |
# ifdef SIGPOLL
|
329
|
2118 |
signal(SIGPOLL, __signalIoInterrupt);
|
10
|
2119 |
# endif
|
101
|
2120 |
# ifdef SIGURG
|
329
|
2121 |
signal(SIGURG, __signalIoInterrupt);
|
101
|
2122 |
# endif
|
216
|
2123 |
}
|
|
2124 |
|
|
2125 |
f = _intVal(fd);
|
|
2126 |
flags = fcntl(f, F_GETFL, 0);
|
|
2127 |
/*
|
|
2128 |
* if already set, there is no need for this syscall ...
|
|
2129 |
*/
|
|
2130 |
if (flags & FASYNC) {
|
|
2131 |
ret = flags;
|
|
2132 |
} else {
|
|
2133 |
ret = fcntl(f, F_SETFL, flags | FASYNC);
|
|
2134 |
if (ret >= 0) ret = flags;
|
|
2135 |
}
|
185
|
2136 |
RETURN ( _MKSMALLINT(ret) );
|
10
|
2137 |
}
|
|
2138 |
# endif
|
1
|
2139 |
#endif
|
68
|
2140 |
%}.
|
|
2141 |
"
|
|
2142 |
this error is triggered on non-integer argument
|
101
|
2143 |
or if the system does not support SIGIO
|
68
|
2144 |
"
|
10
|
2145 |
self primitiveFailed
|
|
2146 |
!
|
|
2147 |
|
|
2148 |
disableIOInterruptsOn:fd
|
|
2149 |
"turn off IO interrupts for a filedescriptor"
|
|
2150 |
|
|
2151 |
%{ /* NOCONTEXT */
|
|
2152 |
|
216
|
2153 |
int ret, flags, f;
|
10
|
2154 |
|
|
2155 |
#if defined(F_GETFL) && defined(F_SETFL)
|
|
2156 |
# if defined(FASYNC)
|
252
|
2157 |
if (__isSmallInteger(fd)) {
|
216
|
2158 |
f = _intVal(fd);
|
|
2159 |
flags = fcntl(f, F_GETFL, 0);
|
|
2160 |
/*
|
|
2161 |
* if already clear, there is no need for this syscall ...
|
|
2162 |
*/
|
|
2163 |
if (flags & FASYNC) {
|
|
2164 |
ret = fcntl(f, F_SETFL, flags & ~FASYNC);
|
|
2165 |
if (ret >= 0) ret = flags;
|
|
2166 |
} else {
|
|
2167 |
ret = flags;
|
|
2168 |
}
|
185
|
2169 |
RETURN ( _MKSMALLINT(ret) );
|
10
|
2170 |
}
|
|
2171 |
# endif
|
|
2172 |
#endif
|
68
|
2173 |
%}.
|
|
2174 |
"
|
|
2175 |
this error is triggered on non-integer argument
|
216
|
2176 |
or if the OS does not support IO interrupts.
|
68
|
2177 |
"
|
10
|
2178 |
self primitiveFailed
|
1
|
2179 |
!
|
|
2180 |
|
2
|
2181 |
enableChildSignalInterrupts
|
|
2182 |
"enable childSignal interrupts
|
|
2183 |
(SIGCHLD, if the architecture supports it).
|
|
2184 |
after enabling, these signals will send the message
|
|
2185 |
'childSignalInterrupt' to the ChildSignalInterruptHandler object."
|
|
2186 |
|
68
|
2187 |
^ self enableSignal:(self sigCHLD)
|
2
|
2188 |
!
|
|
2189 |
|
1
|
2190 |
startSpyTimer
|
63
|
2191 |
"trigger a spyInterrupt, to be signalled after some short (virtual) time.
|
359
|
2192 |
This is used by the old MessageTally for profiling.
|
63
|
2193 |
Should be changed to use real profiling timer if available.
|
68
|
2194 |
On systems, where no virtual timer is available, use the real timer
|
359
|
2195 |
(which is of course less correct).
|
|
2196 |
OBSOLETE: the new messageTally runs as a high prio process, not using
|
|
2197 |
spy interrupts."
|
1
|
2198 |
|
|
2199 |
%{ /* NOCONTEXT */
|
|
2200 |
|
329
|
2201 |
extern void __spyInterrupt();
|
10
|
2202 |
#if defined(ITIMER_VIRTUAL)
|
1
|
2203 |
struct itimerval dt;
|
|
2204 |
|
213
|
2205 |
# ifndef xxxSYSV4
|
68
|
2206 |
# if defined(BSD) || defined(HAS_SIGSETMASK)
|
1
|
2207 |
sigsetmask(0);
|
|
2208 |
# endif
|
|
2209 |
# endif
|
|
2210 |
|
13
|
2211 |
# ifdef SIGVTALRM
|
329
|
2212 |
signal(SIGVTALRM, __spyInterrupt);
|
13
|
2213 |
# else
|
329
|
2214 |
signal(SIGALRM, __spyInterrupt);
|
13
|
2215 |
# endif
|
|
2216 |
|
348
|
2217 |
dt.it_interval.tv_sec = 0;
|
|
2218 |
dt.it_interval.tv_usec = 0;
|
|
2219 |
dt.it_value.tv_sec = 0;
|
|
2220 |
dt.it_value.tv_usec = 1000; /* 1000 Hz */
|
|
2221 |
setitimer(ITIMER_VIRTUAL, &dt, 0);
|
|
2222 |
|
13
|
2223 |
RETURN (true);
|
1
|
2224 |
#endif
|
|
2225 |
%}
|
13
|
2226 |
.
|
|
2227 |
^ false
|
1
|
2228 |
!
|
|
2229 |
|
|
2230 |
stopSpyTimer
|
359
|
2231 |
"stop spy timing - disable spy timer.
|
|
2232 |
OBSOLETE: the new messageTally runs as a high prio process, not using
|
|
2233 |
spy interrupts."
|
1
|
2234 |
|
|
2235 |
%{ /* NOCONTEXT */
|
|
2236 |
|
10
|
2237 |
#if defined(ITIMER_VIRTUAL)
|
1
|
2238 |
struct itimerval dt;
|
|
2239 |
|
|
2240 |
dt.it_interval.tv_sec = 0;
|
|
2241 |
dt.it_interval.tv_usec = 0;
|
|
2242 |
dt.it_value.tv_sec = 0;
|
|
2243 |
dt.it_value.tv_usec = 0;
|
|
2244 |
setitimer(ITIMER_VIRTUAL, &dt, 0);
|
13
|
2245 |
RETURN (true);
|
10
|
2246 |
#endif
|
|
2247 |
%}
|
13
|
2248 |
.
|
|
2249 |
^ false
|
10
|
2250 |
!
|
|
2251 |
|
|
2252 |
enableTimer:millis
|
63
|
2253 |
"trigger a timerInterrupt, to be signalled after some (real) time."
|
10
|
2254 |
|
|
2255 |
%{ /* NOCONTEXT */
|
|
2256 |
|
329
|
2257 |
extern void __signalTimerInterrupt();
|
216
|
2258 |
|
10
|
2259 |
#if defined(ITIMER_REAL)
|
|
2260 |
struct itimerval dt;
|
|
2261 |
|
213
|
2262 |
# ifndef xxxSYSV4
|
68
|
2263 |
# if defined(BSD) || defined(HAS_SIGSETMASK)
|
10
|
2264 |
sigsetmask(0);
|
|
2265 |
# endif
|
1
|
2266 |
# endif
|
329
|
2267 |
signal(SIGALRM, __signalTimerInterrupt);
|
348
|
2268 |
|
|
2269 |
dt.it_interval.tv_sec = 0;
|
|
2270 |
dt.it_interval.tv_usec = 0;
|
|
2271 |
dt.it_value.tv_sec = _intVal(millis) / 1000;
|
|
2272 |
dt.it_value.tv_usec = (_intVal(millis) % 1000) * 1000;
|
|
2273 |
setitimer(ITIMER_REAL, &dt, 0);
|
13
|
2274 |
RETURN (true);
|
|
2275 |
#endif
|
10
|
2276 |
%}
|
13
|
2277 |
.
|
|
2278 |
^ false
|
10
|
2279 |
!
|
|
2280 |
|
|
2281 |
disableTimer
|
|
2282 |
"disable timer interrupt"
|
|
2283 |
|
|
2284 |
%{ /* NOCONTEXT */
|
|
2285 |
|
|
2286 |
#if defined(ITIMER_REAL)
|
|
2287 |
struct itimerval dt;
|
|
2288 |
|
|
2289 |
dt.it_interval.tv_sec = 0;
|
|
2290 |
dt.it_interval.tv_usec = 0;
|
|
2291 |
dt.it_value.tv_sec = 0;
|
|
2292 |
dt.it_value.tv_usec = 0;
|
|
2293 |
setitimer(ITIMER_REAL, &dt, 0);
|
13
|
2294 |
RETURN (true);
|
10
|
2295 |
#endif
|
1
|
2296 |
%}
|
13
|
2297 |
.
|
|
2298 |
^ false
|
123
|
2299 |
!
|
|
2300 |
|
|
2301 |
operatingSystemSignal:signalNumber
|
|
2302 |
"return the signal to be raised when an
|
|
2303 |
operatingSystem-signal occurs, or nil"
|
|
2304 |
|
|
2305 |
OSSignals notNil ifTrue:[
|
185
|
2306 |
^ OSSignals at:signalNumber ifAbsent:[nil]
|
123
|
2307 |
].
|
|
2308 |
^ nil
|
|
2309 |
!
|
|
2310 |
|
|
2311 |
operatingSystemSignal:signalNumber install:aSignal
|
|
2312 |
"install a signal to be raised when an operatingSystem-signal occurs"
|
|
2313 |
|
|
2314 |
OSSignals isNil ifTrue:[
|
185
|
2315 |
OSSignals := Array new:32
|
123
|
2316 |
].
|
|
2317 |
OSSignals at:signalNumber put:aSignal
|
370
|
2318 |
!
|
|
2319 |
|
|
2320 |
sendSignal:signalNumber to:processId
|
|
2321 |
"send a unix signal to some process (maybe myself).
|
|
2322 |
Returns false if any error occurred, true otherwise.
|
|
2323 |
|
|
2324 |
Do not confuse UNIX signals with Smalltalk-Signals."
|
|
2325 |
%{
|
|
2326 |
if (__bothSmallInteger(signalNumber, processId)) {
|
|
2327 |
if (kill(__intVal(processId), __intVal(signalNumber)) < 0) {
|
|
2328 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
2329 |
RETURN ( false );
|
|
2330 |
}
|
|
2331 |
RETURN ( true );
|
|
2332 |
}
|
|
2333 |
%}.
|
|
2334 |
self primitiveFailed
|
1
|
2335 |
! !
|
|
2336 |
|
|
2337 |
!OperatingSystem class methodsFor:'time and date'!
|
|
2338 |
|
|
2339 |
getTimeLow
|
|
2340 |
"return low 16 bits of current time.
|
63
|
2341 |
|
68
|
2342 |
OBSOLETE: Dont use this method, use getTimeParts.
|
1
|
2343 |
This method will not always return the correct time
|
63
|
2344 |
if used together with getTimeHi, since a wrap between
|
185
|
2345 |
the two getTimeXXX sends could occur.
|
|
2346 |
WARNING: this method will vanish - dont use it."
|
1
|
2347 |
|
|
2348 |
%{ /* NOCONTEXT */
|
|
2349 |
|
|
2350 |
RETURN ( _MKSMALLINT(time(0) & 0xFFFF) );
|
|
2351 |
%}
|
|
2352 |
|
|
2353 |
"OperatingSystem getTimeLow"
|
|
2354 |
!
|
|
2355 |
|
|
2356 |
getTimeHi
|
|
2357 |
"return hi 16 bits of current time.
|
63
|
2358 |
|
68
|
2359 |
OBSOLETE: Dont use this method, use getTimeParts.
|
1
|
2360 |
This method will NOT always return the correct time
|
63
|
2361 |
if used together with getTimeHi, since a wrap between
|
185
|
2362 |
the two getTimeXXX sends could occur.
|
|
2363 |
WARNING: this method will vanish - dont use it."
|
1
|
2364 |
|
|
2365 |
%{ /* NOCONTEXT */
|
|
2366 |
|
|
2367 |
RETURN ( _MKSMALLINT((time(0) >> 16) & 0xFFFF) );
|
|
2368 |
%}
|
|
2369 |
|
|
2370 |
"OperatingSystem getTimeHi"
|
|
2371 |
!
|
|
2372 |
|
63
|
2373 |
getTimeParts
|
|
2374 |
"return the current time as an array of 2 integers representing
|
|
2375 |
the current time (usually low 16bits / hi 16 bits) in some OS
|
|
2376 |
dependent way.
|
|
2377 |
|
|
2378 |
On unix, the values represent the seconds since 1970, on other
|
|
2379 |
systems this may be different.
|
185
|
2380 |
WARNING:
|
|
2381 |
for portability, never use these values directly, but pass them
|
|
2382 |
to #computeTimeParts and/or #computeDatePartsOf:, which know how to
|
|
2383 |
interpret them.
|
|
2384 |
Better yet, use Date>>today and Time>>now for ST-80 compatibility."
|
63
|
2385 |
|
|
2386 |
|low hi|
|
|
2387 |
%{
|
|
2388 |
int now;
|
|
2389 |
|
|
2390 |
now = time(0);
|
|
2391 |
hi = _MKSMALLINT((now >> 16) & 0xFFFF);
|
|
2392 |
low = _MKSMALLINT(now & 0xFFFF);
|
|
2393 |
%}
|
|
2394 |
.
|
|
2395 |
^ Array with:low with:hi
|
|
2396 |
|
|
2397 |
"OperatingSystem getTimeParts"
|
|
2398 |
!
|
|
2399 |
|
1
|
2400 |
getTimeInto:aBlock
|
|
2401 |
"evaluate the argument aBlock, passing the time-parts of
|
63
|
2402 |
the current time as arguments.
|
|
2403 |
See comment in 'OperatingSystem>>getTimeParts' on what to
|
|
2404 |
do with those parts."
|
1
|
2405 |
|
|
2406 |
|low hi|
|
|
2407 |
%{
|
|
2408 |
int now;
|
|
2409 |
|
|
2410 |
now = time(0);
|
|
2411 |
hi = _MKSMALLINT((now >> 16) & 0xFFFF);
|
|
2412 |
low = _MKSMALLINT(now & 0xFFFF);
|
|
2413 |
%}
|
|
2414 |
.
|
|
2415 |
aBlock value:low value:hi
|
|
2416 |
|
241
|
2417 |
"OperatingSystem getTimeInto:[:low :hi | low printNewline. hi printNewline]"
|
1
|
2418 |
!
|
|
2419 |
|
|
2420 |
getTime
|
63
|
2421 |
"return current Time in some OS dependent representation.
|
|
2422 |
(on unix, its the seconds since 1970).
|
1
|
2423 |
|
63
|
2424 |
WARNING: this is OperatingSystem dependent - for portable code,
|
185
|
2425 |
use getTimeParts and compute*PartsOf:and:for:.
|
|
2426 |
Better yet, use Date>>today or Time>>now for fully ST-80 compatible code."
|
63
|
2427 |
|
|
2428 |
OperatingSystem getTimeInto:[:low :hi | ^ hi*16r10000 + low]
|
1
|
2429 |
|
185
|
2430 |
"
|
|
2431 |
OperatingSystem getTime
|
|
2432 |
"
|
1
|
2433 |
!
|
|
2434 |
|
63
|
2435 |
computeDatePartsOf:timeParts for:aBlock
|
|
2436 |
"compute year, month and day from the ostime in timeParts,
|
241
|
2437 |
and evaluate the argument, a 3-arg block with these.
|
|
2438 |
Conversion is to localtime including any daylight saving adjustments."
|
63
|
2439 |
|
|
2440 |
^ self computeDatePartsOf:(timeParts at:1) and:(timeParts at:2) for:aBlock
|
|
2441 |
!
|
|
2442 |
|
|
2443 |
computeTimePartsOf:timeParts for:aBlock
|
|
2444 |
"compute hour, minute and seconds from the ostime in timeParts,
|
241
|
2445 |
and evaluate the argument, a 3-arg block with these.
|
|
2446 |
Conversion is to localtime including any daylight saving adjustments."
|
63
|
2447 |
|
|
2448 |
^ self computeTimePartsOf:(timeParts at:1) and:(timeParts at:2) for:aBlock
|
|
2449 |
!
|
|
2450 |
|
1
|
2451 |
computeDatePartsOf:timeLow and:timeHi for:aBlock
|
|
2452 |
"compute year, month and day from the time-parts timeLow and
|
|
2453 |
timeHi and evaluate the argument, a 3-arg block with these.
|
241
|
2454 |
Conversion is to localtime including any daylight saving adjustments.
|
63
|
2455 |
|
|
2456 |
This method was added to avoid LargeInteger arithmetic and to be
|
|
2457 |
independent of how the OperatingSystem represents time;
|
|
2458 |
the time-parts expected are those returned by getTimeParts."
|
1
|
2459 |
|
|
2460 |
|year month day|
|
|
2461 |
|
|
2462 |
((timeLow isMemberOf:SmallInteger) and:[timeHi isMemberOf:SmallInteger])
|
|
2463 |
ifFalse:[
|
185
|
2464 |
^ self primitiveFailed
|
1
|
2465 |
].
|
|
2466 |
%{
|
|
2467 |
struct tm *tmPtr;
|
|
2468 |
long t;
|
|
2469 |
|
|
2470 |
t = (_intVal(timeHi) << 16) | _intVal(timeLow);
|
|
2471 |
tmPtr = localtime(&t);
|
|
2472 |
year = _MKSMALLINT(tmPtr->tm_year + 1900);
|
|
2473 |
month = _MKSMALLINT(tmPtr->tm_mon + 1);
|
|
2474 |
day = _MKSMALLINT(tmPtr->tm_mday);
|
|
2475 |
%}
|
|
2476 |
.
|
|
2477 |
aBlock value:year value:month value:day
|
|
2478 |
!
|
|
2479 |
|
|
2480 |
computeTimePartsOf:timeLow and:timeHi for:aBlock
|
|
2481 |
"compute hours, minutes and seconds from the time-parts timeLow and
|
63
|
2482 |
timeHi and evaluate the argument, a 3-arg block with these.
|
241
|
2483 |
Conversion is to localtime including any daylight saving adjustments.
|
63
|
2484 |
|
|
2485 |
This method was added to avoid LargeInteger arithmetic and to be
|
|
2486 |
independent of how the OperatingSystem represents time;
|
|
2487 |
the time-parts expected are those returned by getTimeParts."
|
1
|
2488 |
|
|
2489 |
|hours minutes seconds|
|
|
2490 |
|
|
2491 |
((timeLow isMemberOf:SmallInteger) and:[timeHi isMemberOf:SmallInteger])
|
|
2492 |
ifFalse:[
|
185
|
2493 |
^ self primitiveFailed
|
1
|
2494 |
].
|
|
2495 |
%{
|
|
2496 |
struct tm *tmPtr;
|
|
2497 |
long t;
|
|
2498 |
|
|
2499 |
t = (_intVal(timeHi) << 16) | _intVal(timeLow);
|
|
2500 |
tmPtr = localtime(&t);
|
|
2501 |
hours = _MKSMALLINT(tmPtr->tm_hour);
|
|
2502 |
minutes = _MKSMALLINT(tmPtr->tm_min);
|
|
2503 |
seconds = _MKSMALLINT(tmPtr->tm_sec);
|
|
2504 |
%}
|
|
2505 |
.
|
|
2506 |
aBlock value:hours value:minutes value:seconds
|
|
2507 |
!
|
|
2508 |
|
63
|
2509 |
computeTimeAndDateFrom:timeParts
|
|
2510 |
"given an Array containing the OS-dependent time, return an Array
|
241
|
2511 |
containing year, month, day, hour, minute and seconds.
|
|
2512 |
Conversion is to localtime including any daylight saving adjustments."
|
63
|
2513 |
|
|
2514 |
|low hi year month day hours minutes seconds ret|
|
|
2515 |
|
|
2516 |
low := timeParts at:1.
|
|
2517 |
hi := timeParts at:2.
|
|
2518 |
%{
|
|
2519 |
struct tm *tmPtr;
|
|
2520 |
long t;
|
|
2521 |
|
252
|
2522 |
if (__bothSmallInteger(low, hi)) {
|
185
|
2523 |
t = (_intVal(hi) << 16) | _intVal(low);
|
|
2524 |
tmPtr = localtime(&t);
|
|
2525 |
hours = _MKSMALLINT(tmPtr->tm_hour);
|
|
2526 |
minutes = _MKSMALLINT(tmPtr->tm_min);
|
|
2527 |
seconds = _MKSMALLINT(tmPtr->tm_sec);
|
|
2528 |
|
|
2529 |
year = _MKSMALLINT(tmPtr->tm_year + 1900);
|
|
2530 |
month = _MKSMALLINT(tmPtr->tm_mon + 1);
|
|
2531 |
day = _MKSMALLINT(tmPtr->tm_mday);
|
63
|
2532 |
}
|
241
|
2533 |
%}.
|
63
|
2534 |
year notNil ifTrue:[
|
185
|
2535 |
"I would love to have SELF-like inline objects ..."
|
|
2536 |
ret := Array new:6.
|
|
2537 |
ret at:1 put:year.
|
|
2538 |
ret at:2 put:month.
|
|
2539 |
ret at:3 put:day.
|
|
2540 |
ret at:4 put:hours.
|
|
2541 |
ret at:5 put:minutes.
|
|
2542 |
ret at:6 put:seconds.
|
|
2543 |
^ ret
|
63
|
2544 |
].
|
|
2545 |
^ self primitiveFailed
|
|
2546 |
!
|
|
2547 |
|
241
|
2548 |
computeTimePartsFromYear:y month:m day:d hour:h minute:min seconds:s
|
|
2549 |
"return an Array containing the OS-dependent time for the given
|
|
2550 |
time and day. The arguments are assumed to be in localtime including
|
|
2551 |
any daylight saving adjustings."
|
|
2552 |
|
|
2553 |
|low hi|
|
|
2554 |
|
|
2555 |
%{
|
|
2556 |
struct tm tm;
|
|
2557 |
long t;
|
|
2558 |
|
252
|
2559 |
if (__bothSmallInteger(y, m)
|
|
2560 |
&& __bothSmallInteger(d, h)
|
|
2561 |
&& __bothSmallInteger(min, s)) {
|
|
2562 |
tm.tm_hour = __intVal(h);
|
|
2563 |
tm.tm_min = __intVal(min);
|
|
2564 |
tm.tm_sec = __intVal(s);
|
|
2565 |
|
|
2566 |
tm.tm_year = __intVal(y) - 1900;
|
|
2567 |
tm.tm_mon = __intVal(m) - 1;
|
|
2568 |
tm.tm_mday = __intVal(d);
|
241
|
2569 |
tm.tm_isdst = -1;
|
|
2570 |
|
|
2571 |
t = mktime(&tm);
|
|
2572 |
low = _MKSMALLINT(t & 0xFFFF);
|
|
2573 |
hi = _MKSMALLINT((t >> 16) & 0xFFFF);
|
|
2574 |
}
|
|
2575 |
%}.
|
|
2576 |
low notNil ifTrue:[
|
|
2577 |
^ Array with:low with:hi
|
|
2578 |
].
|
|
2579 |
^ self primitiveFailed
|
|
2580 |
!
|
|
2581 |
|
275
|
2582 |
maximumMillisecondTimeDelta
|
|
2583 |
"this returns the maximum delta supported by millisecondCounter
|
|
2584 |
based methods. The returned value is half the value at which the
|
|
2585 |
timer wraps."
|
|
2586 |
|
|
2587 |
%{ /* NOCONTEXT */
|
|
2588 |
RETURN ( _MKSMALLINT(0x0FFFFFFF) );
|
|
2589 |
%}
|
|
2590 |
!
|
|
2591 |
|
1
|
2592 |
getMillisecondTime
|
185
|
2593 |
"This returns the millisecond timers value.
|
|
2594 |
The range is limited to 0..1fffffff (i.e. the SmallInteger range) to avoid
|
|
2595 |
LargeInteger arithmetic when doing timeouts and delays.
|
|
2596 |
SInce this value is wrapping around in regular intervals, this can only be used for
|
|
2597 |
short relative time deltas.
|
|
2598 |
Use the millisecondTimeXXX:-methods to compare and add time deltas - these know about the wrap.
|
|
2599 |
|
|
2600 |
BAD DESIGN:
|
|
2601 |
This should be changed to return some instance of RelativeTime,
|
|
2602 |
and these computations moved there.
|
95
|
2603 |
|
|
2604 |
Dont use this method in application code since it is an internal (private)
|
|
2605 |
interface. For compatibility with ST-80, use Time millisecondClockValue.
|
|
2606 |
"
|
1
|
2607 |
|
|
2608 |
%{ /* NOCONTEXT */
|
|
2609 |
|
|
2610 |
long t;
|
185
|
2611 |
#if !defined(HAS_GETTIMEOFDAY) && defined(SYSV) && defined(HZ)
|
|
2612 |
/*
|
|
2613 |
* sys5 time
|
|
2614 |
*/
|
1
|
2615 |
long ticks;
|
|
2616 |
struct tms tb;
|
|
2617 |
|
|
2618 |
ticks = times(&tb);
|
|
2619 |
t = (ticks * 1000) / HZ;
|
185
|
2620 |
#else /* assume HAS_GETTIMEOFDAY */
|
|
2621 |
/*
|
|
2622 |
* bsd time
|
|
2623 |
*/
|
1
|
2624 |
struct timeval tb;
|
|
2625 |
struct timezone tzb;
|
|
2626 |
|
|
2627 |
gettimeofday(&tb, &tzb);
|
|
2628 |
t = tb.tv_sec*1000 + tb.tv_usec/1000;
|
68
|
2629 |
#endif
|
185
|
2630 |
RETURN ( _MKSMALLINT(t & 0x1FFFFFFF) );
|
1
|
2631 |
%}
|
|
2632 |
!
|
|
2633 |
|
|
2634 |
millisecondTimeDeltaBetween:msTime1 and:msTime2
|
95
|
2635 |
"subtract two millisecond times (such as returned getMillisecondTime)
|
185
|
2636 |
and return the difference. Since milli-times wrap (at 16r01FFFFFFF),
|
95
|
2637 |
some special handling is built-in here.
|
185
|
2638 |
The returned value is msTime1 - msTime2. The returned value is invalid
|
|
2639 |
if the delta is >= 0x10000000.
|
63
|
2640 |
|
|
2641 |
This should really be moved to some RelativeTime class."
|
1
|
2642 |
|
|
2643 |
(msTime1 > msTime2) ifTrue:[
|
185
|
2644 |
^ msTime1 - msTime2
|
1
|
2645 |
].
|
|
2646 |
^ msTime1 + 16r10000000 - msTime2
|
95
|
2647 |
|
|
2648 |
"
|
|
2649 |
OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1
|
|
2650 |
OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:(16 / 3)
|
|
2651 |
OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1000
|
|
2652 |
|
|
2653 |
OperatingSystem millisecondTimeDeltaBetween:0 and:16r0FFFFFFF
|
|
2654 |
OperatingSystem millisecondTimeDeltaBetween:(13/3) and:16r0FFFFFFF
|
|
2655 |
OperatingSystem millisecondTimeDeltaBetween:999 and:16r0FFFFFFF
|
|
2656 |
|
|
2657 |
OperatingSystem millisecondTime:0 isAfter:16r0FFFFFFF
|
|
2658 |
OperatingSystem millisecondTime:(13/3) isAfter:16r0FFFFFFF
|
|
2659 |
OperatingSystem millisecondTime:999 isAfter:16r0FFFFFFF
|
|
2660 |
|
|
2661 |
OperatingSystem millisecondTime:0 isAfter:0
|
|
2662 |
OperatingSystem millisecondTime:(13/3) isAfter:0
|
|
2663 |
OperatingSystem millisecondTime:999 isAfter:0
|
|
2664 |
|
|
2665 |
OperatingSystem millisecondTime:1 isAfter:0
|
|
2666 |
OperatingSystem millisecondTime:(13/3) isAfter:2
|
|
2667 |
OperatingSystem millisecondTime:999 isAfter:900
|
|
2668 |
|
|
2669 |
|t1 t2|
|
|
2670 |
|
|
2671 |
t1 := Time millisecondClockValue.
|
|
2672 |
(Delay forMilliseconds:1) wait.
|
|
2673 |
t2 := Time millisecondClockValue.
|
|
2674 |
OperatingSystem millisecondTimeDeltaBetween:t2 and:t1
|
|
2675 |
"
|
1
|
2676 |
!
|
|
2677 |
|
|
2678 |
millisecondTime:msTime1 isAfter:msTime2
|
|
2679 |
"return true if msTime1 is after msTime2, false if not.
|
95
|
2680 |
The two arguments are supposed to be millisecond times
|
185
|
2681 |
(such as returned getMillisecondTime) which wrap at 16r1FFFFFFF.
|
63
|
2682 |
|
|
2683 |
This should really be moved to some RelativeTime class."
|
1
|
2684 |
|
|
2685 |
(msTime1 > msTime2) ifTrue:[
|
185
|
2686 |
((msTime1 - msTime2) >= 16r10000000) ifTrue:[
|
|
2687 |
^ false
|
|
2688 |
].
|
|
2689 |
^ true
|
1
|
2690 |
].
|
185
|
2691 |
((msTime2 - msTime1) > 16r10000000) ifTrue:[
|
|
2692 |
^ true
|
1
|
2693 |
].
|
|
2694 |
^ false
|
|
2695 |
!
|
|
2696 |
|
|
2697 |
millisecondTimeAdd:msTime1 and:msTime2
|
95
|
2698 |
"Add two millisecond times (such as returned getMillisecondTime).
|
185
|
2699 |
The returned value is msTime1 + msTime2 where a wrap occurs at:16r1FFFFFFF.
|
63
|
2700 |
|
|
2701 |
This should really be moved to some RelativeTime class."
|
1
|
2702 |
|
|
2703 |
|sum|
|
|
2704 |
|
|
2705 |
sum := msTime1 + msTime2.
|
185
|
2706 |
(sum > 16r1FFFFFFF) ifTrue:[^ sum - 16r20000000].
|
|
2707 |
(sum < 0) ifTrue:[^ sum + 16r20000000].
|
1
|
2708 |
^ sum
|
|
2709 |
!
|
|
2710 |
|
|
2711 |
millisecondDelay:millis
|
95
|
2712 |
"delay execution for millis milliseconds or until the next event
|
|
2713 |
arrives.
|
308
|
2714 |
All lower priority threads will also sleep for the duration,
|
|
2715 |
interrupts (and therefore, higher prio processes) are
|
|
2716 |
still handled.
|
|
2717 |
Better use a Delay, to only delay the calling thread.
|
|
2718 |
(however, a delay cannot be used in the event handler or scheduler)"
|
|
2719 |
|
|
2720 |
|now then delta|
|
|
2721 |
|
|
2722 |
now := OperatingSystem getMillisecondTime.
|
|
2723 |
then := OperatingSystem millisecondTimeAdd:now and:millis.
|
|
2724 |
|
|
2725 |
[OperatingSystem millisecondTime:then isAfter:now] whileTrue:[
|
|
2726 |
delta := OperatingSystem millisecondTimeDeltaBetween:then and:now.
|
|
2727 |
self selectOnAnyReadable:nil writable:nil exception:nil withTimeOut:delta.
|
|
2728 |
now := OperatingSystem getMillisecondTime.
|
|
2729 |
]
|
95
|
2730 |
|
|
2731 |
"
|
|
2732 |
OperatingSystem millisecondDelay:2000
|
|
2733 |
"
|
1
|
2734 |
!
|
|
2735 |
|
|
2736 |
sleep:numberOfSeconds
|
308
|
2737 |
"cease ANY action for some time. This suspends the whole smalltalk
|
|
2738 |
(unix-) process for some time.
|
1
|
2739 |
Not really useful since not even low-prio processes and interrupt
|
95
|
2740 |
handling will run during the sleep.
|
|
2741 |
Use either OperatingSystem>>millisecondDelay: (which makes all
|
|
2742 |
threads sleep, but handles interrupts) or use a Delay (which makes
|
|
2743 |
only the calling thread sleep)."
|
1
|
2744 |
|
|
2745 |
%{ /* NOCONTEXT */
|
|
2746 |
|
252
|
2747 |
if (__isSmallInteger(numberOfSeconds)) {
|
185
|
2748 |
sleep(_intVal(numberOfSeconds));
|
|
2749 |
RETURN ( self );
|
1
|
2750 |
}
|
68
|
2751 |
%}.
|
|
2752 |
"
|
|
2753 |
argument not integer
|
|
2754 |
"
|
1
|
2755 |
self primitiveFailed
|
95
|
2756 |
|
|
2757 |
"
|
|
2758 |
OperatingSystem sleep:2
|
|
2759 |
"
|
10
|
2760 |
! !
|
|
2761 |
|
|
2762 |
!OperatingSystem class methodsFor:'waiting for events'!
|
|
2763 |
|
|
2764 |
setBlocking:aBoolean on:fd
|
|
2765 |
"set/clear the blocking attribute - if set (which is the default)
|
|
2766 |
a read on the fileDescriptor will block until data is available.
|
|
2767 |
If cleared, a read operation will immediately return with a value of
|
|
2768 |
nil."
|
|
2769 |
|
|
2770 |
%{ /* NOCONTEXT */
|
|
2771 |
|
|
2772 |
int ret, flags;
|
|
2773 |
int savInt;
|
|
2774 |
|
|
2775 |
#if defined(F_GETFL) && defined(F_SETFL)
|
|
2776 |
# if defined(FNDELAY)
|
252
|
2777 |
if (__isSmallInteger(fd)) {
|
185
|
2778 |
flags = fcntl(_intVal(fd), F_GETFL, 0);
|
|
2779 |
if (aBoolean == true) {
|
|
2780 |
ret = fcntl(_intVal(fd), F_SETFL, flags & ~FNDELAY);
|
|
2781 |
} else {
|
|
2782 |
ret = fcntl(_intVal(fd), F_SETFL, flags | FNDELAY);
|
|
2783 |
}
|
|
2784 |
if (ret >= 0) ret = flags;
|
|
2785 |
RETURN ( _MKSMALLINT(ret) );
|
10
|
2786 |
}
|
|
2787 |
# endif
|
|
2788 |
#endif
|
68
|
2789 |
%}.
|
|
2790 |
"
|
|
2791 |
fd argument not integer
|
|
2792 |
"
|
10
|
2793 |
self primitiveFailed
|
1
|
2794 |
!
|
|
2795 |
|
10
|
2796 |
readCheck:fd
|
95
|
2797 |
"return true, if data is available on a filedescriptor (i.e. read
|
|
2798 |
is possible without blocking)"
|
10
|
2799 |
|
|
2800 |
(self selectOnAnyReadable:(Array with:fd)
|
185
|
2801 |
writable:nil
|
|
2802 |
exception:nil
|
|
2803 |
withTimeOut:0) == fd
|
|
2804 |
ifTrue:[^ true].
|
10
|
2805 |
^ false
|
|
2806 |
!
|
|
2807 |
|
|
2808 |
writeCheck:fd
|
|
2809 |
"return true, if filedescriptor can be written without blocking"
|
|
2810 |
|
|
2811 |
(self selectOnAnyReadable:nil
|
185
|
2812 |
writable:(Array with:fd)
|
|
2813 |
exception:nil
|
|
2814 |
withTimeOut:0) == fd
|
|
2815 |
ifTrue:[^ true].
|
10
|
2816 |
^ false
|
|
2817 |
!
|
|
2818 |
|
|
2819 |
selectOn:fd withTimeOut:millis
|
|
2820 |
"wait for aFileDesriptor to become ready; timeout after t milliseconds.
|
1
|
2821 |
Return true, if i/o ok, false if timed-out or interrupted.
|
|
2822 |
With 0 as timeout argument, this can be used to check for availability
|
|
2823 |
of read-data.
|
|
2824 |
Experimental."
|
|
2825 |
|
3
|
2826 |
^ self selectOnAnyReadable:(Array with:fd)
|
185
|
2827 |
writable:(Array with:fd)
|
|
2828 |
exception:nil
|
|
2829 |
withTimeOut:millis
|
1
|
2830 |
!
|
|
2831 |
|
10
|
2832 |
selectOn:fd1 and:fd2 withTimeOut:millis
|
|
2833 |
"wait for any fd to become ready; timeout after t milliseconds.
|
95
|
2834 |
A zero timeout-time will immediately return (i.e. poll).
|
1
|
2835 |
Return fd if i/o ok, nil if timed-out or interrupted.
|
95
|
2836 |
Obsolete:
|
185
|
2837 |
This is a leftover method and will vanish."
|
1
|
2838 |
|
3
|
2839 |
^ self selectOnAnyReadable:(Array with:fd1 with:fd2)
|
185
|
2840 |
writable:(Array with:fd1 with:fd2)
|
|
2841 |
exception:nil
|
|
2842 |
withTimeOut:millis
|
1
|
2843 |
!
|
|
2844 |
|
10
|
2845 |
selectOnAnyReadable:fdArray withTimeOut:millis
|
95
|
2846 |
"wait for any fd in fdArray (an Array of integers) to become ready for
|
|
2847 |
reading. Timeout after t milliseconds. An empty set will always wait.
|
|
2848 |
A zero timeout-time will immediately return (i.e. poll).
|
3
|
2849 |
Return first ready fd if i/o ok, nil if timed-out or interrupted.
|
|
2850 |
Experimental."
|
|
2851 |
|
|
2852 |
^ self selectOnAnyReadable:fdArray
|
185
|
2853 |
writable:nil
|
|
2854 |
exception:nil
|
|
2855 |
withTimeOut:millis
|
3
|
2856 |
!
|
|
2857 |
|
10
|
2858 |
selectOnAny:fdArray withTimeOut:millis
|
1
|
2859 |
"wait for any fd in fdArray (an Array of integers) to become ready;
|
10
|
2860 |
timeout after t milliseconds. An empty set will always wait.
|
1
|
2861 |
Return first ready fd if i/o ok, nil if timed-out or interrupted.
|
|
2862 |
Experimental."
|
|
2863 |
|
3
|
2864 |
^ self selectOnAnyReadable:fdArray
|
185
|
2865 |
writable:fdArray
|
|
2866 |
exception:nil
|
|
2867 |
withTimeOut:millis
|
3
|
2868 |
!
|
|
2869 |
|
95
|
2870 |
selectOnAnyReadable:readFdArray writable:writeFdArray exception:exceptFdArray withTimeOut:millis
|
|
2871 |
"wait for any fd in readFdArray (an Array of integers) to become ready for
|
|
2872 |
reading, writeFdArray to become ready for writing, or exceptFdArray to
|
|
2873 |
arrive exceptional data (i.e. out-of-band data).
|
|
2874 |
Timeout after t milliseconds or, if the timeout time is 0, immediately..
|
|
2875 |
Empty fd-sets will always wait. Zero time can be used to poll file-
|
|
2876 |
descriptors (i.e. to check if I/O possible without blocking).
|
|
2877 |
Return first ready fd if I/O ok, nil if timed-out or interrupted."
|
3
|
2878 |
|
1
|
2879 |
%{
|
|
2880 |
fd_set rset, wset, eset;
|
|
2881 |
int t, f, maxF, i, lX, bX;
|
308
|
2882 |
struct timeval wt, et;
|
1
|
2883 |
OBJ fd, retFd;
|
95
|
2884 |
int ret;
|
300
|
2885 |
int count;
|
1
|
2886 |
|
252
|
2887 |
if (__isSmallInteger(millis)) {
|
185
|
2888 |
FD_ZERO(&rset);
|
|
2889 |
FD_ZERO(&wset);
|
|
2890 |
FD_ZERO(&eset);
|
|
2891 |
|
|
2892 |
maxF = -1;
|
308
|
2893 |
if (readFdArray != nil) {
|
300
|
2894 |
if (! __isArray(readFdArray)) {
|
|
2895 |
goto fail;
|
|
2896 |
}
|
|
2897 |
count = __arraySize(readFdArray);
|
308
|
2898 |
|
|
2899 |
for (i=0; i<count;i++) {
|
|
2900 |
fd = _ArrayInstPtr(readFdArray)->a_element[i];
|
|
2901 |
if (fd != nil) {
|
|
2902 |
f = _intVal(fd);
|
|
2903 |
if ((f >= 0) && (f < FD_SETSIZE)) {
|
|
2904 |
FD_SET(f, &rset);
|
|
2905 |
if (f > maxF) maxF = f;
|
|
2906 |
}
|
185
|
2907 |
}
|
|
2908 |
}
|
|
2909 |
}
|
300
|
2910 |
|
308
|
2911 |
if (writeFdArray != nil) {
|
300
|
2912 |
if (! __isArray(writeFdArray)) {
|
|
2913 |
goto fail;
|
|
2914 |
}
|
|
2915 |
count = __arraySize(writeFdArray);
|
308
|
2916 |
for (i=0; i<count;i++) {
|
|
2917 |
fd = _ArrayInstPtr(writeFdArray)->a_element[i];
|
|
2918 |
if (fd != nil) {
|
|
2919 |
f = _intVal(fd);
|
|
2920 |
if ((f >= 0) && (f < FD_SETSIZE)) {
|
|
2921 |
FD_SET(f, &wset);
|
|
2922 |
if (f > maxF) maxF = f;
|
|
2923 |
}
|
185
|
2924 |
}
|
|
2925 |
}
|
|
2926 |
}
|
300
|
2927 |
|
308
|
2928 |
if (exceptFdArray != nil) {
|
300
|
2929 |
if (! __isArray(exceptFdArray)) {
|
|
2930 |
goto fail;
|
|
2931 |
}
|
|
2932 |
count = __arraySize(exceptFdArray);
|
308
|
2933 |
for (i=0; i<count;i++) {
|
|
2934 |
fd = _ArrayInstPtr(exceptFdArray)->a_element[i];
|
|
2935 |
if (fd != nil) {
|
|
2936 |
f = _intVal(fd);
|
|
2937 |
if ((f >= 0) && (f < FD_SETSIZE)) {
|
|
2938 |
FD_SET(f, &eset);
|
|
2939 |
if (f > maxF) maxF = f;
|
|
2940 |
}
|
185
|
2941 |
}
|
|
2942 |
}
|
|
2943 |
}
|
308
|
2944 |
|
185
|
2945 |
t = _intVal(millis);
|
|
2946 |
wt.tv_sec = t / 1000;
|
|
2947 |
wt.tv_usec = (t % 1000) * 1000;
|
|
2948 |
|
|
2949 |
/*
|
|
2950 |
* make certain, that interrupt gets us out of the select
|
|
2951 |
*/
|
362
|
2952 |
__BEGIN_INTERRUPTABLE__
|
185
|
2953 |
errno = 0;
|
|
2954 |
do {
|
|
2955 |
ret = select(maxF+1, &rset, &wset, &eset, &wt);
|
308
|
2956 |
} while (0 /* (ret < 0) && (errno == EINTR) */ );
|
362
|
2957 |
__END_INTERRUPTABLE__
|
95
|
2958 |
|
185
|
2959 |
if (ret > 0) {
|
|
2960 |
for (i=0; i <= maxF; i++) {
|
|
2961 |
if (FD_ISSET(i, &rset)
|
|
2962 |
|| FD_ISSET(i, &wset)
|
|
2963 |
|| FD_ISSET(i, &eset)) {
|
|
2964 |
RETURN ( _MKSMALLINT(i) );
|
|
2965 |
}
|
|
2966 |
}
|
|
2967 |
}
|
308
|
2968 |
|
185
|
2969 |
/*
|
|
2970 |
* return nil (means time expired)
|
|
2971 |
*/
|
|
2972 |
RETURN ( nil );
|
1
|
2973 |
}
|
300
|
2974 |
fail: ;
|
68
|
2975 |
%}.
|
|
2976 |
"
|
300
|
2977 |
timeout argument not integer,
|
|
2978 |
or any fd-array nonNil and not an array
|
68
|
2979 |
"
|
1
|
2980 |
self primitiveFailed
|
|
2981 |
! !
|
|
2982 |
|
|
2983 |
!OperatingSystem class methodsFor:'executing commands'!
|
|
2984 |
|
|
2985 |
fork
|
68
|
2986 |
"fork a new (HEAVY-weight) unix process.
|
95
|
2987 |
Dont confuse this with Block>>fork, which creates
|
|
2988 |
lightweight smalltalk processes. This method will return
|
|
2989 |
0 to the child process, abd a non-zero number (which is the childs
|
|
2990 |
unix-process-id) to the parent (original) process."
|
1
|
2991 |
|
|
2992 |
%{ /* NOCONTEXT */
|
|
2993 |
|
|
2994 |
int pid;
|
|
2995 |
|
|
2996 |
pid = fork();
|
|
2997 |
RETURN ( _MKSMALLINT(pid) );
|
|
2998 |
%}
|
68
|
2999 |
"
|
|
3000 |
|id|
|
|
3001 |
|
|
3002 |
id := OperatingSystem fork.
|
|
3003 |
id == 0 ifTrue:[
|
185
|
3004 |
OperatingSystem exit
|
68
|
3005 |
]
|
|
3006 |
"
|
1
|
3007 |
!
|
|
3008 |
|
|
3009 |
exec:aPath withArguments:argArray
|
|
3010 |
"execute the unix command specified by the argument, aPath, with
|
68
|
3011 |
arguments in argArray (no arguments, if nil).
|
1
|
3012 |
If successful, this method does not return and smalltalk is gone.
|
|
3013 |
If not sucessfull, false is returned. Normal use is with fork."
|
|
3014 |
|
|
3015 |
%{
|
68
|
3016 |
char **argv;
|
1
|
3017 |
int nargs, i;
|
|
3018 |
OBJ arg;
|
|
3019 |
|
68
|
3020 |
if (__isString(aPath) && ((argArray == nil) || __isArray(argArray))) {
|
185
|
3021 |
nargs = argArray == nil ? 0 : _arraySize(argArray);
|
|
3022 |
argv = (char **) malloc(sizeof(char *) * (nargs + 1));
|
216
|
3023 |
if (argv) {
|
|
3024 |
for (i=0; i < nargs; i++) {
|
241
|
3025 |
arg = _ArrayInstPtr(argArray)->a_element[i];
|
|
3026 |
if (__isString(arg)) {
|
216
|
3027 |
argv[i] = (char *) _stringVal(arg);
|
241
|
3028 |
}
|
185
|
3029 |
}
|
216
|
3030 |
argv[i] = NULL;
|
|
3031 |
execv(_stringVal(aPath), argv);
|
|
3032 |
/* should not be reached */
|
|
3033 |
free(argv);
|
|
3034 |
RETURN ( false );
|
185
|
3035 |
}
|
1
|
3036 |
}
|
245
|
3037 |
%}.
|
68
|
3038 |
"
|
|
3039 |
path-argument not string or
|
245
|
3040 |
argArray not an array/nil or
|
|
3041 |
malloc failed
|
68
|
3042 |
"
|
1
|
3043 |
self primitiveFailed
|
68
|
3044 |
|
|
3045 |
"
|
|
3046 |
|id|
|
|
3047 |
|
|
3048 |
id := OperatingSystem fork.
|
|
3049 |
id == 0 ifTrue:[
|
185
|
3050 |
"I am the child"
|
375
|
3051 |
OperatingSystem exec:'/bin/ls' withArguments:#('ls' '/tmp').
|
185
|
3052 |
"not reached"
|
68
|
3053 |
]
|
|
3054 |
"
|
1
|
3055 |
!
|
|
3056 |
|
|
3057 |
executeCommand:aCommandString
|
|
3058 |
"execute the unix command specified by the argument, aCommandString.
|
85
|
3059 |
Return true if successful, false otherwise.
|
|
3060 |
Smalltalk is suspended, while the command is executing.
|
|
3061 |
The return value of the system()-call is available in the variable
|
|
3062 |
LastExecStatus (which is zero after successful execution); this value
|
|
3063 |
consists of the reason for termination (0=normal) in the upper 8bits and,
|
|
3064 |
iff it was a normal return, the value passed to exit() in the low 8bits."
|
1
|
3065 |
|
|
3066 |
%{ /* NOCONTEXT */
|
|
3067 |
|
|
3068 |
int status;
|
|
3069 |
|
63
|
3070 |
if (__isString(aCommandString)) {
|
185
|
3071 |
status = system((char *) _stringVal(aCommandString));
|
|
3072 |
OperatingSystem_LastExecStatus = _MKSMALLINT(status);
|
|
3073 |
if (status == 0) {
|
|
3074 |
RETURN ( true );
|
|
3075 |
}
|
354
|
3076 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
185
|
3077 |
RETURN ( false );
|
1
|
3078 |
}
|
|
3079 |
%}
|
|
3080 |
.
|
|
3081 |
self primitiveFailed
|
|
3082 |
|
85
|
3083 |
"
|
95
|
3084 |
OperatingSystem executeCommand:'pwd'.
|
|
3085 |
OperatingSystem lastExecStatus printNL.
|
|
3086 |
|
|
3087 |
OperatingSystem executeCommand:'ls -l'.
|
|
3088 |
OperatingSystem lastExecStatus printNL.
|
|
3089 |
|
|
3090 |
OperatingSystem executeCommand:'invalidCommand'.
|
|
3091 |
(OperatingSystem lastExecStatus printStringRadix:16) printNL.
|
|
3092 |
|
|
3093 |
OperatingSystem executeCommand:'rm /tmp/foofoofoofoo'.
|
|
3094 |
(OperatingSystem lastExecStatus printStringRadix:16) printNL.
|
85
|
3095 |
"
|
1
|
3096 |
! !
|
|
3097 |
|
|
3098 |
!OperatingSystem class methodsFor:'file access'!
|
|
3099 |
|
10
|
3100 |
getCharacter
|
68
|
3101 |
"read a character from keyboard -
|
|
3102 |
this is a blocking low-level read, provided for debugger
|
|
3103 |
and fatal conditions. Use Stdin or (even better) the event
|
|
3104 |
mechanisms provided."
|
10
|
3105 |
|
|
3106 |
%{ /* NOCONTEXT */
|
|
3107 |
|
|
3108 |
RETURN ( _MKSMALLINT(getchar()) );
|
|
3109 |
%}
|
|
3110 |
!
|
|
3111 |
|
2
|
3112 |
fileSeparator
|
|
3113 |
"return the character used to separate names in a path.
|
|
3114 |
This character differs for MSDOS and other systems,
|
68
|
3115 |
(but those are currently not supported - so this is some
|
|
3116 |
preparation for the future)"
|
2
|
3117 |
|
|
3118 |
^ $/
|
|
3119 |
!
|
|
3120 |
|
216
|
3121 |
parentDirectoryName
|
|
3122 |
"return the name used to refer to parent directories.
|
|
3123 |
In MSDOS, Unix and other systems this is '..', but maybe different
|
|
3124 |
for other systems.
|
|
3125 |
(but those are currently not supported - so this is some
|
|
3126 |
preparation for the future)"
|
|
3127 |
|
|
3128 |
^ '..'
|
|
3129 |
!
|
|
3130 |
|
|
3131 |
caseSensitiveFilenames
|
185
|
3132 |
"return true, if the OS has caseSensitive file naming.
|
|
3133 |
On MSDOS, this will return false. Since this is for Unix, we
|
|
3134 |
return true."
|
|
3135 |
|
|
3136 |
^ true
|
|
3137 |
!
|
|
3138 |
|
2
|
3139 |
baseNameOf:aPathString
|
|
3140 |
"return the baseName of the argument, aPathString
|
1
|
3141 |
- thats the file/directory name without leading parent-dirs
|
|
3142 |
(i.e. OperatingSystem baseNameOf:'/usr/lib/st/file' -> 'file'
|
|
3143 |
and OperatingSystem baseNameOf:'/usr/lib' -> lib).
|
2
|
3144 |
This method does not check if the path is valid
|
77
|
3145 |
(i.e. if these directories really exist & is readable)."
|
2
|
3146 |
|
|
3147 |
|prev index sep|
|
1
|
3148 |
|
2
|
3149 |
sep := self fileSeparator.
|
|
3150 |
((aPathString size == 1) and:[(aPathString at:1) == sep]) ifTrue:[
|
185
|
3151 |
^ aPathString
|
2
|
3152 |
].
|
1
|
3153 |
prev := 1.
|
|
3154 |
[true] whileTrue:[
|
185
|
3155 |
index := aPathString indexOf:sep startingAt:prev.
|
|
3156 |
index == 0 ifTrue:[
|
|
3157 |
^ aPathString copyFrom:prev
|
|
3158 |
].
|
|
3159 |
prev := index + 1
|
1
|
3160 |
]
|
2
|
3161 |
|
77
|
3162 |
"
|
|
3163 |
OperatingSystem baseNameOf:'/fee/foo/bar'
|
|
3164 |
OperatingSystem baseNameOf:'foo/bar'
|
|
3165 |
OperatingSystem baseNameOf:'../../foo/bar'
|
|
3166 |
OperatingSystem baseNameOf:'hello'
|
|
3167 |
"
|
1
|
3168 |
!
|
|
3169 |
|
2
|
3170 |
directoryNameOf:aPathString
|
1
|
3171 |
"return the directoryName of the argument, aPath
|
|
3172 |
- thats the name of the directory where aPath is
|
|
3173 |
(i.e. OperatingSystem directoryNameOf:'/usr/lib/st/file' -> '/usr/lib/st'
|
|
3174 |
and OperatingSystem directoryNameOf:'/usr/lib' -> /usr').
|
77
|
3175 |
This method does not check if the path is valid
|
|
3176 |
(i.e. if these directories really exist & are readable)."
|
1
|
3177 |
|
2
|
3178 |
|last index sep sepString|
|
1
|
3179 |
|
2
|
3180 |
sep := self fileSeparator.
|
|
3181 |
sepString := sep asString.
|
|
3182 |
(aPathString = sepString) ifTrue:[
|
185
|
3183 |
"
|
|
3184 |
the trivial '/' case
|
|
3185 |
"
|
|
3186 |
^ aPathString
|
2
|
3187 |
].
|
|
3188 |
(aPathString startsWith:sepString) ifFalse:[
|
185
|
3189 |
(aPathString endsWith:sepString) ifTrue:[
|
|
3190 |
^ aPathString copyTo:(aPathString size - 1)
|
|
3191 |
].
|
1
|
3192 |
].
|
|
3193 |
last := 1.
|
|
3194 |
[true] whileTrue:[
|
185
|
3195 |
index := aPathString indexOf:sep startingAt:(last + 1).
|
|
3196 |
index == 0 ifTrue:[
|
|
3197 |
(last == 1) ifTrue:[
|
|
3198 |
(aPathString startsWith:sepString) ifTrue:[
|
|
3199 |
^ sepString
|
|
3200 |
].
|
|
3201 |
^ '.'
|
|
3202 |
].
|
77
|
3203 |
"
|
185
|
3204 |
(aPathString startsWith:sepString) ifFalse:[
|
|
3205 |
(aPathString startsWith:('..' , sepString)) ifFalse:[
|
|
3206 |
^ './' , (aPathString copyTo:(last - 1))
|
|
3207 |
]
|
|
3208 |
].
|
77
|
3209 |
"
|
185
|
3210 |
^ aPathString copyTo:(last - 1)
|
|
3211 |
].
|
|
3212 |
last := index.
|
1
|
3213 |
]
|
|
3214 |
|
77
|
3215 |
"
|
|
3216 |
OperatingSystem directoryNameOf:'/fee/foo/bar'
|
|
3217 |
OperatingSystem directoryNameOf:'foo/bar'
|
|
3218 |
OperatingSystem directoryNameOf:'../../foo/bar'
|
|
3219 |
OperatingSystem directoryNameOf:'bar'
|
|
3220 |
OperatingSystem directoryNameOf:'/bar'
|
|
3221 |
"
|
|
3222 |
!
|
|
3223 |
|
308
|
3224 |
primPathNameOf:pathName
|
77
|
3225 |
"return the pathName of the argument, aPathString,
|
|
3226 |
- thats the full pathname of the directory, starting at '/'.
|
308
|
3227 |
This method here returns nil, if the OS does not provide a
|
|
3228 |
realPath library function.
|
77
|
3229 |
Notice: if symbolic links are involved, the result may look different
|
|
3230 |
from what you expect."
|
|
3231 |
|
308
|
3232 |
|path|
|
77
|
3233 |
|
185
|
3234 |
"some systems have a convenient function for this ..."
|
77
|
3235 |
%{ /* STACK: 16000 */
|
|
3236 |
#ifdef HAS_REALPATH
|
|
3237 |
char nameBuffer[MAXPATHLEN + 1];
|
|
3238 |
|
|
3239 |
if (__isString(pathName)) {
|
185
|
3240 |
if (realpath(_stringVal(pathName), nameBuffer)) {
|
308
|
3241 |
RETURN ( _MKSTRING(nameBuffer COMMA_CON) );
|
185
|
3242 |
}
|
77
|
3243 |
}
|
|
3244 |
#endif
|
308
|
3245 |
%}.
|
|
3246 |
^ nil
|
|
3247 |
!
|
|
3248 |
|
|
3249 |
compressPath:pathName
|
|
3250 |
"return the pathName compressed - that is, remove all ..-entries
|
|
3251 |
and . entries. This does not always (in case of symbolic links)
|
|
3252 |
return the true pathName and is therefore used as a fallback
|
|
3253 |
if realPath and popen failed."
|
|
3254 |
|
|
3255 |
|names|
|
|
3256 |
|
|
3257 |
names := pathName
|
|
3258 |
asCollectionOfSubstringsSeparatedBy:self fileSeparator.
|
|
3259 |
names := names asOrderedCollection.
|
|
3260 |
"
|
|
3261 |
cut off initial double-slashes
|
|
3262 |
"
|
|
3263 |
[names startsWith:#('' '')] whileTrue:[
|
|
3264 |
names removeFirst.
|
|
3265 |
].
|
|
3266 |
"
|
|
3267 |
cut off double-slashes at end
|
|
3268 |
"
|
|
3269 |
[names endsWith:#('')] whileTrue:[
|
|
3270 |
names removeLast.
|
|
3271 |
].
|
|
3272 |
"
|
|
3273 |
cut off current-dir at beginning
|
|
3274 |
"
|
|
3275 |
[(names size >= 2) and:[names startsWith:#('.')]] whileTrue:[
|
|
3276 |
names removeFirst.
|
|
3277 |
].
|
|
3278 |
|
|
3279 |
"
|
|
3280 |
cut off parent-dirs at end
|
|
3281 |
"
|
|
3282 |
[(names size > 2)
|
|
3283 |
and:[(names endsWith:#('..'))
|
|
3284 |
and:[((names at:(names size - 1)) startsWith:'.') not ]]] whileTrue:[
|
|
3285 |
names removeLast; removeLast
|
|
3286 |
].
|
|
3287 |
|
|
3288 |
^ names asStringWith:self fileSeparator
|
|
3289 |
from:1
|
|
3290 |
to:names size
|
|
3291 |
compressTabs:false final:nil
|
|
3292 |
|
|
3293 |
"
|
|
3294 |
OperatingSystem compressPath:'./..'
|
|
3295 |
|
|
3296 |
OperatingSystem compressPath:'/foo/bar/baz/..'
|
|
3297 |
|
|
3298 |
OperatingSystem compressPath:'foo/bar/baz/..'
|
|
3299 |
|
|
3300 |
OperatingSystem compressPath:'foo/bar/baz/../'
|
|
3301 |
|
|
3302 |
OperatingSystem compressPath:'foo/bar/baz/..///'
|
|
3303 |
|
|
3304 |
OperatingSystem compressPath:'///foo/bar/baz/..///'
|
|
3305 |
"
|
|
3306 |
!
|
|
3307 |
|
|
3308 |
pathNameOf:pathName
|
|
3309 |
"return the pathName of the argument, aPathString,
|
|
3310 |
- thats the full pathname of the directory, starting at '/'.
|
|
3311 |
This method needs the path to be valid
|
|
3312 |
(i.e. all directories must exist, be readable and executable).
|
|
3313 |
Notice: if symbolic links are involved, the result may look different
|
|
3314 |
from what you expect."
|
|
3315 |
|
|
3316 |
|p path command|
|
|
3317 |
|
|
3318 |
"some systems have a convenient function for this ..."
|
|
3319 |
path := self primPathNameOf:pathName.
|
|
3320 |
|
77
|
3321 |
path isNil ifTrue:[
|
308
|
3322 |
(SlowFork==true or:[ForkFailed]) ifFalse:[
|
|
3323 |
PipeStream openErrorSignal handle:[:ex |
|
|
3324 |
ForkFailed := true.
|
|
3325 |
'UNIX: cannot fork/popen' errorPrintNL.
|
|
3326 |
ex return.
|
|
3327 |
] do:[
|
|
3328 |
"have to fall back ..."
|
|
3329 |
command := 'cd ' , pathName , '; pwd'.
|
|
3330 |
p := PipeStream readingFrom:command.
|
|
3331 |
].
|
|
3332 |
|
|
3333 |
(p isNil or:[p atEnd]) ifTrue:[
|
|
3334 |
('UNIX: PipeStream for <' , command , '> failed') errorPrintNL.
|
|
3335 |
] ifFalse:[
|
|
3336 |
path := p nextLine.
|
|
3337 |
p close.
|
|
3338 |
].
|
|
3339 |
].
|
|
3340 |
path isNil ifTrue:[
|
185
|
3341 |
path := pathName
|
|
3342 |
].
|
308
|
3343 |
(SlowFork==true or:[ForkFailed]) ifTrue:[
|
|
3344 |
path := self compressPath:path
|
|
3345 |
]
|
77
|
3346 |
].
|
|
3347 |
^ path.
|
|
3348 |
|
|
3349 |
"
|
|
3350 |
OperatingSystem pathNameOf:'.'
|
|
3351 |
OperatingSystem pathNameOf:'../smalltalk/../smalltalk'
|
|
3352 |
OperatingSystem pathNameOf:'../../..'
|
|
3353 |
OperatingSystem pathNameOf:'..'
|
|
3354 |
"
|
1
|
3355 |
!
|
|
3356 |
|
|
3357 |
isValidPath:aPathName
|
|
3358 |
"return true, if 'aPathName' is a valid path name
|
|
3359 |
(i.e. the file or directory exists)"
|
|
3360 |
|
|
3361 |
%{ /* NOCONTEXT */
|
|
3362 |
|
|
3363 |
struct stat buf;
|
10
|
3364 |
int ret;
|
1
|
3365 |
|
322
|
3366 |
if (__isString(aPathName) || __isSymbol(aPathName) ) {
|
185
|
3367 |
do {
|
|
3368 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
|
3369 |
} while (ret < 0 && errno == EINTR);
|
|
3370 |
RETURN ( ret ? false : true );
|
1
|
3371 |
}
|
|
3372 |
%}
|
|
3373 |
.
|
|
3374 |
self primitiveFailed
|
|
3375 |
!
|
|
3376 |
|
|
3377 |
isDirectory:aPathName
|
|
3378 |
"return true, if 'aPathName' is a valid directory path name.
|
|
3379 |
(i.e. exists and is a directory)"
|
|
3380 |
|
|
3381 |
%{ /* NOCONTEXT */
|
|
3382 |
|
|
3383 |
struct stat buf;
|
10
|
3384 |
int ret;
|
1
|
3385 |
|
63
|
3386 |
if (__isString(aPathName)) {
|
185
|
3387 |
do {
|
|
3388 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
|
3389 |
} while (ret < 0 && errno == EINTR);
|
|
3390 |
if ((ret < 0) || ((buf.st_mode & S_IFMT) != S_IFDIR)) {
|
354
|
3391 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
185
|
3392 |
RETURN ( false );
|
|
3393 |
}
|
|
3394 |
RETURN ( true );
|
1
|
3395 |
}
|
185
|
3396 |
%}.
|
1
|
3397 |
self primitiveFailed
|
185
|
3398 |
|
|
3399 |
"an alternative implementation would be:
|
|
3400 |
^ (self infoOf:aPathName) at:#type == #directory
|
|
3401 |
"
|
1
|
3402 |
!
|
|
3403 |
|
|
3404 |
isReadable:aPathName
|
|
3405 |
"return true, if the file/dir 'aPathName' is readable."
|
|
3406 |
|
|
3407 |
%{ /* NOCONTEXT */
|
|
3408 |
|
63
|
3409 |
if (__isString(aPathName)) {
|
185
|
3410 |
if (access(_stringVal(aPathName), R_OK) == 0) {
|
|
3411 |
RETURN ( true );
|
|
3412 |
}
|
|
3413 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
3414 |
RETURN ( false );
|
1
|
3415 |
}
|
|
3416 |
%}
|
|
3417 |
.
|
|
3418 |
self primitiveFailed
|
|
3419 |
!
|
|
3420 |
|
|
3421 |
isWritable:aPathName
|
|
3422 |
"return true, if the given file is writable"
|
|
3423 |
|
|
3424 |
%{ /* NOCONTEXT */
|
|
3425 |
|
63
|
3426 |
if (__isString(aPathName)) {
|
185
|
3427 |
if (access(_stringVal(aPathName), W_OK) == 0) {
|
|
3428 |
RETURN ( true );
|
|
3429 |
}
|
|
3430 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
3431 |
RETURN ( false );
|
1
|
3432 |
}
|
|
3433 |
%}
|
|
3434 |
.
|
|
3435 |
self primitiveFailed
|
|
3436 |
!
|
|
3437 |
|
|
3438 |
isExecutable:aPathName
|
|
3439 |
"return true, if the given file is executable"
|
|
3440 |
|
|
3441 |
%{ /* NOCONTEXT */
|
|
3442 |
|
63
|
3443 |
if (__isString(aPathName)) {
|
185
|
3444 |
if (access(_stringVal(aPathName), X_OK) == 0) {
|
|
3445 |
RETURN ( true );
|
|
3446 |
}
|
|
3447 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
3448 |
RETURN ( false );
|
1
|
3449 |
}
|
|
3450 |
%}
|
|
3451 |
.
|
|
3452 |
self primitiveFailed
|
|
3453 |
!
|
|
3454 |
|
329
|
3455 |
isSymbolicLink:aPathName
|
|
3456 |
"return true, if the given file is a symbolic link"
|
|
3457 |
|
|
3458 |
^ (self linkInfoOf:aPathName) notNil
|
356
|
3459 |
|
|
3460 |
"
|
|
3461 |
OperatingSystem isSymbolicLink:'Make.proto'
|
|
3462 |
OperatingSystem isSymbolicLink:'Makefile'
|
|
3463 |
"
|
329
|
3464 |
!
|
|
3465 |
|
|
3466 |
linkInfoOf:aPathName
|
|
3467 |
"return a dictionary filled with info for the file 'aPathName',
|
|
3468 |
IFF aPathName is a symbolic link. If not, return nil.
|
|
3469 |
The contents of the dictionary gives info about the link itself,
|
|
3470 |
on contrast to #infoOf:, which returns the info of the pointed to file
|
|
3471 |
in case of a symbolic link."
|
|
3472 |
|
|
3473 |
|info type mode uid gid size id atimeLow atimeHi mtimeLow mtimeHi ctimeLow ctimeHi
|
|
3474 |
path|
|
|
3475 |
|
|
3476 |
%{ /* STACK: 1200 */
|
|
3477 |
struct stat buf;
|
|
3478 |
int ret;
|
|
3479 |
char pathBuffer[1024];
|
|
3480 |
|
|
3481 |
if (__isString(aPathName)) {
|
|
3482 |
do {
|
|
3483 |
ret = lstat((char *) _stringVal(aPathName), &buf);
|
|
3484 |
} while (ret < 0 && errno == EINTR);
|
|
3485 |
if (ret < 0) {
|
|
3486 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
3487 |
RETURN ( nil );
|
|
3488 |
}
|
|
3489 |
switch (buf.st_mode & S_IFMT) {
|
|
3490 |
default:
|
|
3491 |
RETURN ( nil ); /* not a symbolic link */
|
|
3492 |
|
|
3493 |
case S_IFLNK:
|
|
3494 |
type = @symbol(symbolicLink);
|
|
3495 |
break;
|
|
3496 |
}
|
|
3497 |
|
|
3498 |
mode = _MKSMALLINT(buf.st_mode & 0777);
|
|
3499 |
uid = _MKSMALLINT(buf.st_uid);
|
|
3500 |
gid = _MKSMALLINT(buf.st_gid);
|
|
3501 |
size = _MKSMALLINT(buf.st_size);
|
|
3502 |
id = _MKSMALLINT(buf.st_ino);
|
|
3503 |
atimeLow = _MKSMALLINT(buf.st_atime & 0xFFFF);
|
|
3504 |
atimeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF);
|
|
3505 |
mtimeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF);
|
|
3506 |
mtimeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF);
|
|
3507 |
ctimeLow = _MKSMALLINT(buf.st_ctime & 0xFFFF);
|
|
3508 |
ctimeHi = _MKSMALLINT((buf.st_ctime >> 16) & 0xFFFF);
|
356
|
3509 |
if ((ret = readlink((char *) _stringVal(aPathName), pathBuffer, sizeof(pathBuffer))) < 0) {
|
329
|
3510 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
3511 |
RETURN ( nil );
|
|
3512 |
}
|
356
|
3513 |
pathBuffer[ret] = '\0'; /* readlink does not 0-terminate */
|
329
|
3514 |
path = _MKSTRING(pathBuffer COMMA_CON);
|
|
3515 |
}
|
|
3516 |
%}.
|
|
3517 |
mode notNil ifTrue:[
|
|
3518 |
info := IdentityDictionary new.
|
|
3519 |
info at:#type put:type.
|
|
3520 |
info at:#mode put:mode.
|
|
3521 |
info at:#uid put:uid.
|
|
3522 |
info at:#gid put:gid.
|
|
3523 |
info at:#size put:size.
|
|
3524 |
info at:#id put:id.
|
|
3525 |
info at:#path put:path.
|
|
3526 |
info at:#accessed put:(AbsoluteTime fromOSTimeLow:atimeLow and:atimeHi).
|
|
3527 |
info at:#modified put:(AbsoluteTime fromOSTimeLow:mtimeLow and:mtimeHi).
|
|
3528 |
info at:#statusChanged put:(AbsoluteTime fromOSTimeLow:ctimeLow and:ctimeHi).
|
|
3529 |
^ info
|
|
3530 |
].
|
|
3531 |
self primitiveFailed
|
|
3532 |
|
|
3533 |
"
|
|
3534 |
OperatingSystem infoOf:'Make.proto'
|
|
3535 |
OperatingSystem linkInfoOf:'Make.proto'
|
|
3536 |
"
|
|
3537 |
!
|
|
3538 |
|
1
|
3539 |
infoOf:aPathName
|
329
|
3540 |
"return a dictionary filled with info for the file 'aPathName';
|
1
|
3541 |
info is: (type->t mode->n uid->u gid->g size->s id->ino).
|
|
3542 |
return nil if such a file does not exist. A dictionary is returned,
|
|
3543 |
since we might need to add more info in the future without affecting
|
|
3544 |
existing applications."
|
|
3545 |
|
329
|
3546 |
|info type mode uid gid size id
|
|
3547 |
atimeLow atimeHi mtimeLow mtimeHi ctimeLow ctimeHi|
|
1
|
3548 |
|
|
3549 |
%{
|
|
3550 |
struct stat buf;
|
10
|
3551 |
int ret;
|
1
|
3552 |
|
63
|
3553 |
if (__isString(aPathName)) {
|
185
|
3554 |
do {
|
|
3555 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
|
3556 |
} while (ret < 0 && errno == EINTR);
|
|
3557 |
if (ret < 0) {
|
|
3558 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
3559 |
RETURN ( nil );
|
|
3560 |
}
|
|
3561 |
switch (buf.st_mode & S_IFMT) {
|
|
3562 |
case S_IFDIR:
|
329
|
3563 |
type = @symbol(directory);
|
185
|
3564 |
break;
|
|
3565 |
case S_IFCHR:
|
329
|
3566 |
type = @symbol(characterSpecial);
|
185
|
3567 |
break;
|
|
3568 |
case S_IFBLK:
|
329
|
3569 |
type = @symbol(blockSpecial);
|
185
|
3570 |
break;
|
|
3571 |
case S_IFREG:
|
329
|
3572 |
type = @symbol(regular);
|
185
|
3573 |
break;
|
1
|
3574 |
#ifdef S_IFLNK
|
185
|
3575 |
case S_IFLNK:
|
329
|
3576 |
type = @symbol(symbolicLink);
|
185
|
3577 |
break;
|
1
|
3578 |
#endif
|
|
3579 |
#ifdef S_IFSOCK
|
185
|
3580 |
case S_IFSOCK:
|
329
|
3581 |
type = @symbol(socket);
|
185
|
3582 |
break;
|
1
|
3583 |
#endif
|
|
3584 |
#ifdef S_IFIFO
|
185
|
3585 |
case S_IFIFO:
|
329
|
3586 |
type = @symbol(fifo);
|
185
|
3587 |
break;
|
1
|
3588 |
#endif
|
185
|
3589 |
default:
|
329
|
3590 |
type = @symbol(unknown);
|
185
|
3591 |
break;
|
|
3592 |
}
|
|
3593 |
mode = _MKSMALLINT(buf.st_mode & 0777);
|
|
3594 |
uid = _MKSMALLINT(buf.st_uid);
|
|
3595 |
gid = _MKSMALLINT(buf.st_gid);
|
|
3596 |
size = _MKSMALLINT(buf.st_size);
|
|
3597 |
id = _MKSMALLINT(buf.st_ino);
|
|
3598 |
atimeLow = _MKSMALLINT(buf.st_atime & 0xFFFF);
|
|
3599 |
atimeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF);
|
|
3600 |
mtimeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF);
|
|
3601 |
mtimeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF);
|
329
|
3602 |
ctimeLow = _MKSMALLINT(buf.st_ctime & 0xFFFF);
|
|
3603 |
ctimeHi = _MKSMALLINT((buf.st_ctime >> 16) & 0xFFFF);
|
1
|
3604 |
}
|
329
|
3605 |
%}.
|
1
|
3606 |
mode notNil ifTrue:[
|
185
|
3607 |
info := IdentityDictionary new.
|
|
3608 |
info at:#type put:type.
|
|
3609 |
info at:#mode put:mode.
|
|
3610 |
info at:#uid put:uid.
|
|
3611 |
info at:#gid put:gid.
|
|
3612 |
info at:#size put:size.
|
|
3613 |
info at:#id put:id.
|
329
|
3614 |
info at:#accessed put:(AbsoluteTime fromOSTimeLow:atimeLow and:atimeHi).
|
|
3615 |
info at:#modified put:(AbsoluteTime fromOSTimeLow:mtimeLow and:mtimeHi).
|
|
3616 |
info at:#statusChanged put:(AbsoluteTime fromOSTimeLow:ctimeLow and:ctimeHi).
|
185
|
3617 |
^ info
|
1
|
3618 |
].
|
|
3619 |
self primitiveFailed
|
|
3620 |
|
329
|
3621 |
"
|
|
3622 |
OperatingSystem infoOf:'/'
|
|
3623 |
(OperatingSystem infoOf:'/') at:#uid
|
|
3624 |
(OperatingSystem infoOf:'/') at:#accessed
|
|
3625 |
"
|
1
|
3626 |
!
|
|
3627 |
|
185
|
3628 |
accessMaskFor:aSymbol
|
|
3629 |
"return the access bits mask for numbers as returned by
|
|
3630 |
OperatingSystem>>accessModeOf:
|
|
3631 |
and expected by OperatingSystem>>changeAccessModeOf:to:.
|
|
3632 |
Since these numbers are OS dependent, always use the mask
|
|
3633 |
(never hardcode 8rxxx into your code)."
|
|
3634 |
|
|
3635 |
%{ /* NOCONTEXT */
|
|
3636 |
# ifndef S_IRUSR
|
|
3637 |
/* posix systems should define these ... */
|
|
3638 |
# define S_IRUSR 0400
|
|
3639 |
# define S_IWUSR 0200
|
|
3640 |
# define S_IXUSR 0100
|
|
3641 |
# define S_IRGRP 0040
|
|
3642 |
# define S_IWGRP 0020
|
|
3643 |
# define S_IXGRP 0010
|
|
3644 |
# define S_IROTH 0004
|
|
3645 |
# define S_IWOTH 0002
|
|
3646 |
# define S_IXOTH 0001
|
|
3647 |
|
|
3648 |
# endif
|
|
3649 |
|
|
3650 |
if (aSymbol == @symbol(readUser)) {
|
|
3651 |
return _MKSMALLINT(S_IRUSR);
|
|
3652 |
}
|
|
3653 |
if (aSymbol == @symbol(writeUser)) {
|
|
3654 |
return _MKSMALLINT(S_IWUSR);
|
|
3655 |
}
|
|
3656 |
if (aSymbol == @symbol(executeUser)) {
|
|
3657 |
return _MKSMALLINT(S_IXUSR);
|
|
3658 |
}
|
|
3659 |
if (aSymbol == @symbol(readGroup)) {
|
|
3660 |
return _MKSMALLINT(S_IRGRP);
|
|
3661 |
}
|
|
3662 |
if (aSymbol == @symbol(writeGroup)) {
|
|
3663 |
return _MKSMALLINT(S_IWGRP);
|
|
3664 |
}
|
|
3665 |
if (aSymbol == @symbol(executeGroup)) {
|
|
3666 |
return _MKSMALLINT(S_IXGRP);
|
|
3667 |
}
|
|
3668 |
if (aSymbol == @symbol(readOthers)) {
|
|
3669 |
return _MKSMALLINT(S_IROTH);
|
|
3670 |
}
|
|
3671 |
if (aSymbol == @symbol(writeOthers)) {
|
|
3672 |
return _MKSMALLINT(S_IWOTH);
|
|
3673 |
}
|
|
3674 |
if (aSymbol == @symbol(executeOthers)) {
|
|
3675 |
return _MKSMALLINT(S_IXOTH);
|
|
3676 |
}
|
|
3677 |
%}.
|
|
3678 |
self primitiveFailed
|
|
3679 |
|
|
3680 |
"
|
|
3681 |
OperatingSystem accessMaskFor:#readUser
|
|
3682 |
"
|
|
3683 |
!
|
|
3684 |
|
1
|
3685 |
accessModeOf:aPathName
|
|
3686 |
"return a number representing access rights rwxrwxrwx for owner,
|
185
|
3687 |
group and others. Return nil if such a file does not exist.
|
|
3688 |
Notice that the returned number is OS dependent - use the
|
|
3689 |
modeMasks as returned by OperatingSystem>>accessMaskFor:"
|
1
|
3690 |
|
|
3691 |
"
|
|
3692 |
this could have been implemented as:
|
185
|
3693 |
(self infoOf:aPathName) at:#mode
|
1
|
3694 |
but for huge directory searches the code below is faster
|
|
3695 |
"
|
|
3696 |
|
|
3697 |
%{ /* NOCONTEXT */
|
|
3698 |
|
|
3699 |
struct stat buf;
|
10
|
3700 |
int ret;
|
1
|
3701 |
|
63
|
3702 |
if (__isString(aPathName)) {
|
185
|
3703 |
do {
|
|
3704 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
|
3705 |
} while (ret < 0 && errno == EINTR);
|
|
3706 |
if (ret < 0) {
|
|
3707 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
3708 |
RETURN ( nil );
|
|
3709 |
}
|
|
3710 |
RETURN ( _MKSMALLINT(buf.st_mode & 0777) );
|
1
|
3711 |
}
|
185
|
3712 |
%}.
|
1
|
3713 |
self primitiveFailed
|
|
3714 |
|
185
|
3715 |
"
|
|
3716 |
(OperatingSystem accessModeOf:'/') printStringRadix:8
|
|
3717 |
"
|
1
|
3718 |
!
|
|
3719 |
|
|
3720 |
changeAccessModeOf:aPathName to:modeBits
|
185
|
3721 |
"change the access rights of aPathName to the OS dependent modeBits.
|
|
3722 |
You should construct this mask using accessMaskFor, to be OS
|
|
3723 |
independent. Return true if changed,
|
|
3724 |
false if such a file does not exist or change was not allowd."
|
1
|
3725 |
|
|
3726 |
%{ /* NOCONTEXT */
|
185
|
3727 |
int ret;
|
1
|
3728 |
|
252
|
3729 |
if (__isString(aPathName) && __isSmallInteger(modeBits)) {
|
185
|
3730 |
do {
|
|
3731 |
ret = chmod((char *)_stringVal(aPathName), _intVal(modeBits));
|
|
3732 |
} while (ret < 0 && errno == EINTR);
|
|
3733 |
if (ret < 0) {
|
|
3734 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
3735 |
RETURN ( false );
|
|
3736 |
}
|
|
3737 |
RETURN ( true );
|
1
|
3738 |
}
|
185
|
3739 |
%}.
|
|
3740 |
self primitiveFailed
|
1
|
3741 |
!
|
|
3742 |
|
|
3743 |
timeOfLastChange:aPathName
|
2
|
3744 |
"return the time, when the file was last changed"
|
1
|
3745 |
|
329
|
3746 |
"could be implemented as:
|
|
3747 |
(self infoOf:aPathName) at:#modified
|
|
3748 |
"
|
|
3749 |
|
1
|
3750 |
|timeLow timeHi|
|
|
3751 |
%{
|
|
3752 |
struct stat buf;
|
10
|
3753 |
int ret;
|
1
|
3754 |
time_t mtime;
|
|
3755 |
|
63
|
3756 |
if (__isString(aPathName)) {
|
185
|
3757 |
do {
|
|
3758 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
|
3759 |
} while (ret < 0 && errno == EINTR);
|
|
3760 |
if (ret >= 0) {
|
|
3761 |
timeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF);
|
|
3762 |
timeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF);
|
|
3763 |
}
|
|
3764 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
1
|
3765 |
}
|
|
3766 |
%}
|
|
3767 |
.
|
241
|
3768 |
timeLow notNil ifTrue:[^ AbsoluteTime fromOSTimeLow:timeLow and:timeHi].
|
1
|
3769 |
self primitiveFailed
|
|
3770 |
|
241
|
3771 |
"
|
|
3772 |
OperatingSystem timeOfLastChange:'/'
|
|
3773 |
"
|
1
|
3774 |
!
|
|
3775 |
|
2
|
3776 |
timeOfLastAccess:aPathName
|
|
3777 |
"return the time, when the file was last accessed"
|
|
3778 |
|
329
|
3779 |
"could be implemented as:
|
|
3780 |
(self infoOf:aPathName) at:#accessed
|
|
3781 |
"
|
2
|
3782 |
|timeLow timeHi|
|
|
3783 |
%{
|
|
3784 |
struct stat buf;
|
|
3785 |
time_t mtime;
|
10
|
3786 |
int ret;
|
2
|
3787 |
|
63
|
3788 |
if (__isString(aPathName)) {
|
185
|
3789 |
do {
|
|
3790 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
|
3791 |
} while (ret < 0 && errno == EINTR);
|
|
3792 |
if (ret >= 0) {
|
|
3793 |
timeLow = _MKSMALLINT(buf.st_atime & 0xFFFF);
|
|
3794 |
timeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF);
|
|
3795 |
}
|
|
3796 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
2
|
3797 |
}
|
|
3798 |
%}
|
|
3799 |
.
|
241
|
3800 |
timeLow notNil ifTrue:[^ AbsoluteTime fromOSTimeLow:timeLow and:timeHi].
|
2
|
3801 |
self primitiveFailed
|
|
3802 |
|
241
|
3803 |
"
|
|
3804 |
OperatingSystem timeOfLastAccess:'/'
|
|
3805 |
"
|
2
|
3806 |
!
|
|
3807 |
|
1
|
3808 |
idOf:aPathName
|
|
3809 |
"return the fileNumber (i.e. inode number) of a file"
|
|
3810 |
|
|
3811 |
"
|
|
3812 |
this could have been implemented as:
|
185
|
3813 |
(self infoOf:aPathName) at:#id
|
1
|
3814 |
but for huge directory searches the code below is faster
|
|
3815 |
"
|
|
3816 |
|
|
3817 |
%{ /* NOCONTEXT */
|
|
3818 |
|
|
3819 |
struct stat buf;
|
10
|
3820 |
int ret;
|
1
|
3821 |
|
63
|
3822 |
if (__isString(aPathName)) {
|
185
|
3823 |
do {
|
|
3824 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
|
3825 |
} while (ret < 0 && errno == EINTR);
|
|
3826 |
if (ret >= 0) {
|
|
3827 |
RETURN (_MKSMALLINT(buf.st_ino));
|
|
3828 |
}
|
|
3829 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
1
|
3830 |
}
|
|
3831 |
%}
|
|
3832 |
.
|
|
3833 |
self primitiveFailed
|
|
3834 |
|
|
3835 |
"OperatingSystem idOf:'/'"
|
|
3836 |
!
|
|
3837 |
|
|
3838 |
typeOf:aPathName
|
|
3839 |
"return the type of a file as a symbol"
|
|
3840 |
|
|
3841 |
"
|
|
3842 |
this could have been implemented as:
|
185
|
3843 |
(self infoOf:aPathName) at:#type
|
1
|
3844 |
but for huge directory searches the code below is faster
|
|
3845 |
"
|
|
3846 |
|
|
3847 |
%{ /* NOCONTEXT */
|
|
3848 |
|
|
3849 |
struct stat buf;
|
10
|
3850 |
int ret;
|
1
|
3851 |
|
63
|
3852 |
if (__isString(aPathName)) {
|
185
|
3853 |
do {
|
|
3854 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
|
3855 |
} while (ret < 0 && errno == EINTR);
|
|
3856 |
if (ret < 0) {
|
|
3857 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno);
|
|
3858 |
RETURN ( nil );
|
|
3859 |
}
|
|
3860 |
switch (buf.st_mode & S_IFMT) {
|
|
3861 |
case S_IFDIR:
|
|
3862 |
RETURN ( @symbol(directory) );
|
|
3863 |
case S_IFCHR:
|
|
3864 |
RETURN ( @symbol(characterSpecial) );
|
|
3865 |
case S_IFBLK:
|
|
3866 |
RETURN ( @symbol(blockSpecial) );
|
|
3867 |
case S_IFREG:
|
|
3868 |
RETURN ( @symbol(regular) );
|
1
|
3869 |
#ifdef S_IFLNK
|
185
|
3870 |
case S_IFLNK:
|
|
3871 |
RETURN ( @symbol(symbolicLink) );
|
1
|
3872 |
#endif
|
|
3873 |
#ifdef S_IFSOCK
|
185
|
3874 |
case S_IFSOCK:
|
|
3875 |
RETURN ( @symbol(socket) );
|
1
|
3876 |
#endif
|
|
3877 |
#ifdef S_IFIFO
|
185
|
3878 |
case S_IFIFO:
|
|
3879 |
RETURN ( @symbol(fifo) );
|
1
|
3880 |
#endif
|
185
|
3881 |
default:
|
|
3882 |
RETURN ( @symbol(unknown) );
|
|
3883 |
}
|
1
|
3884 |
}
|
329
|
3885 |
%}.
|
1
|
3886 |
self primitiveFailed
|
|
3887 |
|
329
|
3888 |
"
|
|
3889 |
OperatingSystem typeOf:'/'
|
|
3890 |
OperatingSystem typeOf:'.'
|
|
3891 |
OperatingSystem typeOf:'Make.proto'
|
|
3892 |
"
|
1
|
3893 |
!
|
|
3894 |
|
|
3895 |
createDirectory:newPathName
|
|
3896 |
"create a new directory with name 'newPathName'.
|
|
3897 |
Return true if successful, false if failed."
|
|
3898 |
|
|
3899 |
"since createDirectory is not used too often,
|
|
3900 |
you'll forgive me using mkdir ..."
|
|
3901 |
|
|
3902 |
^ self executeCommand:('mkdir ' , newPathName)
|
|
3903 |
|
|
3904 |
"OperatingSystem createDirectory:'foo'"
|
|
3905 |
!
|
|
3906 |
|
|
3907 |
recursiveCreateDirectory:dirName
|
|
3908 |
"create a directory - with all parent dirs if needed.
|
|
3909 |
Return true if successful, false otherwise. If false
|
|
3910 |
is returned, a partial created tree may be left,
|
|
3911 |
which is not cleaned-up here."
|
|
3912 |
|
|
3913 |
self createDirectory:dirName.
|
|
3914 |
(self isDirectory:dirName) ifFalse:[
|
185
|
3915 |
(self recursiveCreateDirectory:(self directoryNameOf:dirName)) ifFalse:[^ false].
|
|
3916 |
^ self createDirectory:dirName
|
1
|
3917 |
].
|
|
3918 |
^ (self isDirectory:dirName)
|
|
3919 |
|
|
3920 |
"OperatingSystem recursiveCreateDirectory:'foo/bar/baz'"
|
|
3921 |
!
|
|
3922 |
|
|
3923 |
removeFile:fullPathName
|
|
3924 |
"remove the file named 'fullPathName'; return true if successful"
|
|
3925 |
|
|
3926 |
%{ /* NOCONTEXT */
|
|
3927 |
|
63
|
3928 |
if (__isString(fullPathName)) {
|
185
|
3929 |
RETURN ( (unlink((char *) _stringVal(fullPathName)) >= 0) ? true : false );
|
1
|
3930 |
}
|
|
3931 |
%}
|
|
3932 |
.
|
|
3933 |
self primitiveFailed
|
|
3934 |
!
|
|
3935 |
|
|
3936 |
removeDirectory:fullPathName
|
|
3937 |
"remove the directory named 'fullPathName'.
|
|
3938 |
Return true if successful, false if directory is not empty or no permission"
|
|
3939 |
|
|
3940 |
%{ /* NOCONTEXT */
|
|
3941 |
|
63
|
3942 |
if (__isString(fullPathName)) {
|
185
|
3943 |
RETURN ( (rmdir((char *) _stringVal(fullPathName)) >= 0) ? true : false );
|
1
|
3944 |
}
|
|
3945 |
%}
|
|
3946 |
.
|
|
3947 |
self primitiveFailed
|
|
3948 |
!
|
|
3949 |
|
18
|
3950 |
recursiveRemoveDirectory:fullPathName
|
|
3951 |
"remove the directory named 'fullPathName' and all contained files/directories.
|
|
3952 |
Return true if successful."
|
|
3953 |
|
|
3954 |
^ self executeCommand:('rm -rf ' , fullPathName)
|
|
3955 |
!
|
|
3956 |
|
63
|
3957 |
linkFile:oldPath to:newPath
|
1
|
3958 |
"link the file 'oldPath' to 'newPath'. The link will be a hard link.
|
|
3959 |
Return true if successful, false if not."
|
|
3960 |
|
|
3961 |
%{ /* NOCONTEXT */
|
|
3962 |
|
63
|
3963 |
if (__isString(oldPath) && __isString(newPath)) {
|
185
|
3964 |
RETURN ( (link((char *) _stringVal(oldPath), (char *) _stringVal(newPath)) >= 0) ?
|
|
3965 |
true : false );
|
1
|
3966 |
}
|
|
3967 |
%}
|
|
3968 |
.
|
|
3969 |
self primitiveFailed
|
|
3970 |
|
63
|
3971 |
"OperatingSystem linkFile:'foo' to:'bar'"
|
1
|
3972 |
!
|
|
3973 |
|
63
|
3974 |
renameFile:oldPath to:newPath
|
1
|
3975 |
"rename the file 'oldPath' to 'newPath'.
|
|
3976 |
Return true if sucessfull, false if not"
|
|
3977 |
|
|
3978 |
%{ /* NOCONTEXT */
|
|
3979 |
|
63
|
3980 |
if (__isString(oldPath) && __isString(newPath)) {
|
77
|
3981 |
#if defined(HAS_RENAME)
|
185
|
3982 |
if (rename((char *) _stringVal(oldPath), (char *) _stringVal(newPath)) >= 0) {
|
|
3983 |
RETURN ( true );
|
|
3984 |
}
|
1
|
3985 |
#else
|
185
|
3986 |
if (link((char *) _stringVal(oldPath), (char *) _stringVal(newPath)) >= 0) {
|
|
3987 |
if (unlink((char *) _stringVal(oldPath)) >= 0) {
|
|
3988 |
RETURN ( true );
|
|
3989 |
}
|
|
3990 |
unlink((char *) _stringVal(newPath));
|
|
3991 |
}
|
1
|
3992 |
#endif
|
185
|
3993 |
RETURN ( false );
|
1
|
3994 |
}
|
|
3995 |
%}
|
|
3996 |
.
|
|
3997 |
self primitiveFailed
|
|
3998 |
|
63
|
3999 |
"OperatingSystem renameFile:'foo' to:'bar'"
|
1
|
4000 |
! !
|