1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
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:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
OperatingSystem comment:'
|
|
21 |
|
5
|
22 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
23 |
All Rights Reserved
|
|
24 |
|
51
|
25 |
$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.11 1994-02-05 12:27:58 claus Exp $
|
1
|
26 |
|
|
27 |
written 1988 by claus
|
|
28 |
'!
|
|
29 |
|
|
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>
|
|
41 |
# if ! defined(sco3_2)
|
|
42 |
# include <unistd.h>
|
|
43 |
# endif
|
|
44 |
# if defined(isc3_2) || defined(sco3_2)
|
|
45 |
# include <sys/time.h>
|
|
46 |
# endif
|
|
47 |
# if !defined(isc3_2)
|
|
48 |
# if defined(PCS) && defined(mips)
|
|
49 |
# include "/usr/include/bsd/sys/time.h"
|
|
50 |
# include "/usr/include/sys/time.h"
|
|
51 |
# else
|
|
52 |
# include <time.h>
|
|
53 |
# endif
|
|
54 |
# endif
|
|
55 |
# if defined(isc3_2)
|
|
56 |
# include <sys/bsdtypes.h>
|
|
57 |
# endif
|
|
58 |
# ifdef FAST_TIMER
|
|
59 |
# include <ft.h>
|
|
60 |
static int timer_fd = -1;
|
|
61 |
# endif
|
|
62 |
# else /* not SYSV */
|
|
63 |
# include <sys/time.h>
|
|
64 |
# include <sys/types.h>
|
|
65 |
# endif
|
|
66 |
# include <pwd.h>
|
|
67 |
# include <grp.h>
|
|
68 |
|
|
69 |
# include <sys/stat.h>
|
10
|
70 |
# include <errno.h>
|
|
71 |
|
1
|
72 |
# ifndef S_IXUSR
|
|
73 |
# define S_IXUSR S_IEXEC
|
|
74 |
# define S_IXGRP (S_IEXEC>>3)
|
|
75 |
# define S_IXOTH (S_IEXEC>>6)
|
|
76 |
# endif
|
|
77 |
|
|
78 |
#endif
|
|
79 |
|
10
|
80 |
/*
|
|
81 |
* on some systems errno is a macro ... check for it here
|
|
82 |
*/
|
1
|
83 |
#ifndef errno
|
|
84 |
extern errno;
|
|
85 |
#endif
|
|
86 |
|
|
87 |
#include <stdio.h>
|
10
|
88 |
#include <fcntl.h>
|
|
89 |
|
|
90 |
/*
|
|
91 |
* some (old) systems do not define this ...
|
|
92 |
*/
|
1
|
93 |
#ifndef R_OK
|
|
94 |
# define R_OK 4 /* Test for Read permission */
|
|
95 |
# define W_OK 2 /* Test for Write permission */
|
|
96 |
# define X_OK 1 /* Test for eXecute permission */
|
|
97 |
# define F_OK 0 /* Test for existence of File */
|
|
98 |
#endif
|
|
99 |
%}
|
|
100 |
|
2
|
101 |
!OperatingSystem class methodsFor:'documentation'!
|
|
102 |
|
|
103 |
documentation
|
|
104 |
"
|
|
105 |
this class gives access to some operating system services;
|
|
106 |
some of it is very specific for unix.
|
|
107 |
|
|
108 |
"
|
|
109 |
! !
|
|
110 |
|
1
|
111 |
!OperatingSystem class methodsFor:'misc'!
|
|
112 |
|
|
113 |
exit
|
|
114 |
"shutdown smalltalk immediately"
|
|
115 |
|
|
116 |
%{ /* NOCONTEXT */
|
|
117 |
mainExit(0);
|
|
118 |
%}
|
|
119 |
"OperatingSystem exit - dont evaluate this"
|
|
120 |
!
|
|
121 |
|
|
122 |
exit:exitCode
|
|
123 |
"shutdown smalltalk immediately returning an exit-code"
|
|
124 |
|
|
125 |
%{ /* NOCONTEXT */
|
|
126 |
if (! _isSmallInteger(exitCode))
|
|
127 |
exit(1);
|
|
128 |
mainExit(_intVal(exitCode));
|
|
129 |
%}
|
|
130 |
"OperatingSystem exit:1 - dont evaluate this"
|
10
|
131 |
! !
|
|
132 |
|
|
133 |
!OperatingSystem class methodsFor:'os queries'!
|
1
|
134 |
|
|
135 |
getEnvironment:aString
|
|
136 |
"get an environment string"
|
|
137 |
|
|
138 |
%{ /* NOCONTEXT */
|
|
139 |
|
|
140 |
char *env;
|
|
141 |
|
|
142 |
if (_isString(aString)) {
|
|
143 |
env = (char *)getenv(_stringVal(aString));
|
|
144 |
if (env) {
|
|
145 |
RETURN ( _MKSTRING(env COMMA_CON) );
|
|
146 |
}
|
|
147 |
}
|
|
148 |
%}
|
|
149 |
.
|
|
150 |
^ nil
|
|
151 |
|
|
152 |
"OperatingSystem getEnvironment:'LANG'"
|
|
153 |
!
|
|
154 |
|
|
155 |
getProcessId
|
|
156 |
"return the processId"
|
|
157 |
|
|
158 |
%{ /* NOCONTEXT */
|
|
159 |
|
|
160 |
int pid = 0;
|
|
161 |
#ifndef transputer
|
|
162 |
pid = getpid();
|
|
163 |
#endif
|
|
164 |
RETURN ( _MKSMALLINT(pid) );
|
|
165 |
%}
|
|
166 |
"OperatingSystem getProcessId"
|
|
167 |
!
|
|
168 |
|
|
169 |
getCPUType
|
|
170 |
"return a string giving the type of machine we're running on"
|
|
171 |
|
|
172 |
|cpu|
|
|
173 |
|
|
174 |
cpu := 'unknown'.
|
|
175 |
|
|
176 |
%{ /* NOCONTEXT */
|
|
177 |
#ifdef vax
|
|
178 |
cpu = _MKSTRING("vax" COMMA_CON);
|
|
179 |
#endif
|
|
180 |
#ifdef mips
|
|
181 |
cpu = _MKSTRING("mips" COMMA_CON);
|
|
182 |
#endif
|
|
183 |
#ifdef i386
|
|
184 |
cpu = _MKSTRING("i386" COMMA_CON);
|
|
185 |
#endif
|
|
186 |
#ifdef ns32k
|
|
187 |
cpu = _MKSTRING("ns32k" COMMA_CON);
|
|
188 |
#endif
|
|
189 |
#ifdef mc68k
|
|
190 |
cpu = _MKSTRING("mc68k" COMMA_CON);
|
|
191 |
#endif
|
|
192 |
#ifdef sparc
|
|
193 |
cpu = _MKSTRING("sparc" COMMA_CON);
|
|
194 |
#endif
|
42
|
195 |
#if defined(hppa)
|
|
196 |
cpu = _MKSTRING("hppa" COMMA_CON);
|
1
|
197 |
#endif
|
|
198 |
#ifdef rs6000
|
|
199 |
cpu = _MKSTRING("rs6000" COMMA_CON);
|
|
200 |
#endif
|
|
201 |
#ifdef alpha
|
|
202 |
cpu = _MKSTRING("alpha" COMMA_CON);
|
|
203 |
#endif
|
|
204 |
#ifdef transputer
|
|
205 |
cpu = _MKSTRING("transputer" COMMA_CON);
|
|
206 |
#endif
|
|
207 |
%}
|
|
208 |
.
|
|
209 |
^ cpu
|
|
210 |
|
|
211 |
"OperatingSystem getCPUType"
|
|
212 |
!
|
|
213 |
|
|
214 |
getOSType
|
|
215 |
"return a string giving the type of os we're running on"
|
|
216 |
|
|
217 |
|os|
|
|
218 |
|
|
219 |
os := 'unknown'.
|
|
220 |
|
|
221 |
%{ /* NOCONTEXT */
|
10
|
222 |
#ifdef MSDOS
|
|
223 |
os = _MKSTRING("msdos" COMMA_CON);
|
|
224 |
#endif
|
|
225 |
|
1
|
226 |
#ifdef sinix
|
|
227 |
os = _MKSTRING("sinix" COMMA_CON);
|
|
228 |
#endif
|
|
229 |
|
|
230 |
#ifdef ultrix
|
|
231 |
os = _MKSTRING("ultrix" COMMA_CON);
|
|
232 |
#endif
|
|
233 |
|
|
234 |
#ifdef sco
|
|
235 |
os = _MKSTRING("sco" COMMA_CON);
|
|
236 |
#endif
|
|
237 |
|
42
|
238 |
#ifdef hpux
|
|
239 |
os = _MKSTRING("hpux" COMMA_CON);
|
|
240 |
#endif
|
|
241 |
|
1
|
242 |
#ifdef LINUX
|
|
243 |
os = _MKSTRING("linux" COMMA_CON);
|
|
244 |
#endif
|
|
245 |
|
|
246 |
#ifdef BSD
|
|
247 |
# ifdef MACH
|
|
248 |
os = _MKSTRING("mach" COMMA_CON);
|
|
249 |
# endif
|
|
250 |
|
|
251 |
# ifdef sunos
|
|
252 |
os = _MKSTRING("sunos" COMMA_CON);
|
|
253 |
# endif
|
|
254 |
|
|
255 |
# ifdef IRIS
|
|
256 |
os = _MKSTRING("irix" COMMA_CON);
|
|
257 |
# endif
|
|
258 |
|
|
259 |
if (os == nil) os = _MKSTRING("bsd" COMMA_CON);
|
|
260 |
#endif
|
|
261 |
|
|
262 |
#ifdef SYSV
|
|
263 |
# ifdef SYSV3
|
|
264 |
os = _MKSTRING("sys5.3" COMMA_CON);
|
|
265 |
# else
|
|
266 |
# ifdef SYSV4
|
|
267 |
os = _MKSTRING("sys5.4" COMMA_CON);
|
|
268 |
# else
|
|
269 |
os = _MKSTRING("sys5" COMMA_CON);
|
|
270 |
# endif
|
|
271 |
# endif
|
|
272 |
#endif
|
|
273 |
%}
|
|
274 |
.
|
|
275 |
^ os
|
|
276 |
|
|
277 |
"OperatingSystem getOSType"
|
|
278 |
!
|
|
279 |
|
|
280 |
getSystemType
|
|
281 |
"return a string giving the type of system we're running on"
|
|
282 |
|
|
283 |
|sys|
|
|
284 |
|
|
285 |
sys := 'unknown'.
|
|
286 |
|
|
287 |
%{ /* NOCONTEXT */
|
10
|
288 |
#ifdef MSDOS
|
|
289 |
sys = _MKSTRING("msdos" COMMA_CON);
|
|
290 |
#endif
|
|
291 |
|
1
|
292 |
#ifdef sinix
|
|
293 |
sys = _MKSTRING("sinix" COMMA_CON);
|
|
294 |
#endif
|
|
295 |
|
|
296 |
#ifdef ultrix
|
|
297 |
sys = _MKSTRING("ultrix" COMMA_CON);
|
|
298 |
#endif
|
|
299 |
|
|
300 |
#ifdef sco
|
|
301 |
sys = _MKSTRING("sco" COMMA_CON);
|
|
302 |
#endif
|
|
303 |
|
|
304 |
#ifdef sunos
|
|
305 |
sys = _MKSTRING("sunos" COMMA_CON);
|
|
306 |
#endif
|
|
307 |
|
|
308 |
#ifdef solaris
|
|
309 |
sys = _MKSTRING("solaris" COMMA_CON);
|
|
310 |
#endif
|
|
311 |
|
|
312 |
#ifdef NEXT
|
|
313 |
sys = _MKSTRING("next" COMMA_CON);
|
|
314 |
#endif
|
|
315 |
|
|
316 |
#ifdef IRIS
|
|
317 |
sys = _MKSTRING("iris" COMMA_CON);
|
|
318 |
#endif
|
|
319 |
|
|
320 |
#ifdef LINUX
|
|
321 |
sys = _MKSTRING("linux" COMMA_CON);
|
|
322 |
#endif
|
|
323 |
|
42
|
324 |
#ifdef hpux
|
|
325 |
sys = _MKSTRING("hpux" COMMA_CON);
|
|
326 |
#endif
|
|
327 |
|
1
|
328 |
#ifdef BSD
|
|
329 |
# ifdef MACH
|
|
330 |
if (sys == nil) sys = _MKSTRING("mach" COMMA_CON);
|
|
331 |
# endif
|
|
332 |
if (sys == nil) sys = _MKSTRING("bsd" COMMA_CON);
|
|
333 |
#endif
|
|
334 |
|
|
335 |
#ifdef SYSV
|
|
336 |
# ifdef SYSV3
|
|
337 |
if (sys == nil) sys = _MKSTRING("sys5.3" COMMA_CON);
|
|
338 |
# else
|
|
339 |
# ifdef SYSV4
|
|
340 |
if (sys == nil) sys = _MKSTRING("sys5.4" COMMA_CON);
|
|
341 |
# else
|
|
342 |
if (sys == nil) sys = _MKSTRING("sys5" COMMA_CON);
|
|
343 |
# endif
|
|
344 |
# endif
|
|
345 |
#endif
|
|
346 |
%}
|
|
347 |
.
|
|
348 |
^ sys
|
|
349 |
|
|
350 |
"OperatingSystem getSystemType"
|
|
351 |
!
|
|
352 |
|
10
|
353 |
getHostName
|
|
354 |
"return the hostname we are running on - if there is
|
|
355 |
a HOST environment variable, we are much faster here ..."
|
|
356 |
|
|
357 |
|name p|
|
|
358 |
|
|
359 |
name := self getEnvironment:'HOST'.
|
|
360 |
name isNil ifTrue:[
|
|
361 |
"since fork might be slow on some machines, give a warning ..."
|
|
362 |
'please set the HOST shell variable for faster startup' printNewline.
|
|
363 |
|
|
364 |
p := PipeStream readingFrom:'hostname'.
|
|
365 |
p notNil ifTrue:[
|
|
366 |
name := p nextLine.
|
|
367 |
p close
|
|
368 |
]
|
|
369 |
].
|
|
370 |
name isNil ifTrue:[
|
|
371 |
'cannot find out hostname' printNewline.
|
|
372 |
].
|
|
373 |
^name
|
|
374 |
!
|
|
375 |
|
1
|
376 |
isBSDlike
|
|
377 |
"return true, if the OS we're running on is a real unix."
|
|
378 |
|
|
379 |
%{ /* NOCONTEXT */
|
|
380 |
|
|
381 |
#ifdef BSD
|
|
382 |
RETURN ( true );
|
|
383 |
#endif
|
|
384 |
#ifdef SYSV4
|
|
385 |
RETURN ( true );
|
|
386 |
#endif
|
|
387 |
%}
|
|
388 |
.
|
|
389 |
^ false
|
|
390 |
!
|
|
391 |
|
|
392 |
maxFileNameLength
|
|
393 |
"return the max number of characters in a filename."
|
|
394 |
|
|
395 |
%{ /* NOCONTEXT */
|
42
|
396 |
#if defined(BSD) || defined(SYSV4) || defined(LONGFILENAMES)
|
1
|
397 |
RETURN ( _MKSMALLINT(255) );
|
|
398 |
#else
|
|
399 |
# ifdef SYSV
|
|
400 |
RETURN ( _MKSMALLINT(14) );
|
|
401 |
# endif
|
|
402 |
# ifdef MSDOS
|
|
403 |
RETURN ( _MKSMALLINT(9) );
|
|
404 |
# endif
|
|
405 |
#endif
|
|
406 |
%}
|
|
407 |
.
|
|
408 |
^ 14
|
10
|
409 |
!
|
|
410 |
|
|
411 |
supportsIOInterrupts
|
|
412 |
"return true, if the OS supports IO availability interrupts
|
42
|
413 |
(i.e. SIGPOLL/SIGIO).
|
|
414 |
|
|
415 |
Currently, this mechanism does not work at all ..."
|
10
|
416 |
|
|
417 |
%{ /* NOCONTEXT */
|
42
|
418 |
#ifdef NOTDEF
|
|
419 |
|
10
|
420 |
#if defined(SIGPOLL) || defined(SIGIO)
|
|
421 |
# if defined(F_GETFL) && defined(F_SETFL)
|
|
422 |
# if defined(FASYNC)
|
|
423 |
/*
|
|
424 |
* mhmh they seem to NOT work on NS2.1
|
|
425 |
*/
|
|
426 |
# if !defined(NEXT)
|
|
427 |
RETURN (true);
|
|
428 |
# endif
|
|
429 |
# endif
|
|
430 |
# endif
|
|
431 |
#endif
|
42
|
432 |
|
|
433 |
#endif
|
10
|
434 |
%}
|
|
435 |
.
|
|
436 |
^ false
|
|
437 |
!
|
|
438 |
|
|
439 |
supportsNonBlockingIO
|
|
440 |
"return true, if the OS supports nonblocking IO"
|
|
441 |
|
|
442 |
%{ /* NOCONTEXT */
|
|
443 |
#if defined(F_GETFL) && defined(F_SETFL)
|
|
444 |
# if defined(FNDELAY)
|
|
445 |
RETURN (true);
|
|
446 |
# endif
|
|
447 |
#endif
|
|
448 |
%}
|
|
449 |
.
|
|
450 |
^ false
|
|
451 |
!
|
|
452 |
|
|
453 |
supportsSelect
|
|
454 |
"return true, if the OS supports selecting on multiple
|
|
455 |
filedescriptors via select."
|
|
456 |
|
|
457 |
%{ /* NOCONTEXT */
|
|
458 |
#if defined(sco)
|
|
459 |
/*
|
|
460 |
* sco has a broken select - always waiting 1 second
|
|
461 |
*/
|
|
462 |
RETURN(false);
|
|
463 |
#endif
|
|
464 |
%}
|
|
465 |
.
|
|
466 |
^ true
|
1
|
467 |
! !
|
|
468 |
|
2
|
469 |
!OperatingSystem class methodsFor:'users & groups'!
|
|
470 |
|
|
471 |
getLoginName
|
|
472 |
"return a string with the users name"
|
|
473 |
|
|
474 |
%{ /* NOCONTEXT */
|
|
475 |
|
|
476 |
char *name = "you";
|
|
477 |
#ifndef transputer
|
|
478 |
name = (char *)getlogin();
|
26
|
479 |
if (! name || (name[0] == 0)) {
|
2
|
480 |
name = (char *)getenv("LOGNAME");
|
|
481 |
}
|
|
482 |
#endif
|
|
483 |
RETURN ( _MKSTRING(name COMMA_CON) );
|
|
484 |
%}
|
|
485 |
"OperatingSystem getLogin"
|
|
486 |
!
|
|
487 |
|
|
488 |
getUserNameFromID:aNumber
|
|
489 |
"return the user-name-string for a given numeric user-id"
|
|
490 |
|
|
491 |
%{ /* NOCONTEXT */
|
|
492 |
|
|
493 |
#ifndef transputer
|
|
494 |
struct passwd *p;
|
|
495 |
|
|
496 |
if (_isSmallInteger(aNumber)) {
|
|
497 |
p = getpwuid(_intVal(aNumber));
|
|
498 |
if (p) {
|
|
499 |
RETURN ( _MKSTRING(p->pw_name COMMA_CON) );
|
|
500 |
}
|
|
501 |
}
|
|
502 |
#endif
|
|
503 |
%}
|
|
504 |
.
|
|
505 |
^ '???'
|
|
506 |
|
|
507 |
"OperatingSystem getUserNameFromID:0"
|
|
508 |
!
|
|
509 |
|
|
510 |
getGroupNameFromID:aNumber
|
|
511 |
"return the group-name-string for a given numeric group-id"
|
|
512 |
|
|
513 |
%{ /* NOCONTEXT */
|
|
514 |
|
|
515 |
#ifndef transputer
|
|
516 |
struct group *g;
|
|
517 |
|
|
518 |
if (_isSmallInteger(aNumber)) {
|
|
519 |
g = getgrgid(_intVal(aNumber));
|
|
520 |
if (g) {
|
|
521 |
RETURN ( _MKSTRING(g->gr_name COMMA_CON) );
|
|
522 |
}
|
|
523 |
}
|
|
524 |
#endif
|
|
525 |
%}
|
|
526 |
.
|
|
527 |
^ '???'
|
|
528 |
|
|
529 |
"OperatingSystem getGroupNameFromID:0"
|
|
530 |
!
|
|
531 |
|
|
532 |
getHomeDirectory
|
10
|
533 |
"return the name of the users home directory"
|
2
|
534 |
|
|
535 |
^ OperatingSystem getEnvironment:'HOME'
|
|
536 |
|
|
537 |
"OperatingSystem getHomeDirectory"
|
|
538 |
! !
|
|
539 |
|
1
|
540 |
!OperatingSystem class methodsFor:'error messages'!
|
|
541 |
|
3
|
542 |
lastErrorString
|
|
543 |
"return a message string describing the last error"
|
|
544 |
|
|
545 |
^ self errorTextForNumber:ErrorNumber
|
|
546 |
!
|
|
547 |
|
1
|
548 |
errorTextForNumber:errNr
|
|
549 |
"return a message string from a unix errorNumber
|
|
550 |
(as returned by a system call). Should be replaced by
|
|
551 |
a resource lookup."
|
|
552 |
|
|
553 |
|msg messages|
|
|
554 |
|
|
555 |
(Language == #german) ifTrue:[
|
|
556 |
messages := #('keine superuser Berechtigung'
|
|
557 |
'ungueltiger Datei- oder VerzeichnisName'
|
|
558 |
nil "'ungueltige Prozessnummer' "
|
|
559 |
nil "'unterbrochener systemcall' "
|
|
560 |
'E/A Fehler'
|
|
561 |
nil "'Geraet existiert nicht' "
|
|
562 |
'zu viele Argumente'
|
|
563 |
'nicht ausfuehrbar'
|
|
564 |
nil "'falscher FileDescriptor'"
|
|
565 |
nil "'kein Kindprozess' "
|
|
566 |
'zu viele Prozesse oder zu wenig Speicher'
|
|
567 |
'zu wenig Speicher'
|
|
568 |
'keine ZugriffsBerechtigung'
|
|
569 |
nil "'falsche Adresse' "
|
|
570 |
nil "'kein Blockgeraet' "
|
|
571 |
nil "'Platte noch im Zugriff' "
|
|
572 |
'Datei existiert bereits'
|
|
573 |
nil "'Link ueber Plattengrenzen hinweg' "
|
|
574 |
'Geraet existiert nicht'
|
|
575 |
'ist kein Verzeichnis'
|
|
576 |
'ist ein Verzeichnis'
|
|
577 |
nil "'ungueltiges Argument' "
|
|
578 |
'zu viele Dateien offen'
|
|
579 |
'zu viele Dateien offen'
|
|
580 |
nil "'kein Terminalgeraet' "
|
|
581 |
'Datei wird gerade ausgefuehrt'
|
|
582 |
'Datei zu gross'
|
|
583 |
'Platte ist voll'
|
|
584 |
'ungueltige Positionierung'
|
|
585 |
'Platte ist schreibgeschuetzt'
|
|
586 |
'zu viele Links'
|
|
587 |
'Pipe unterbrochen'
|
|
588 |
'argument nicht im gueltigen Bereich'
|
|
589 |
'Ergebnis nicht im gueltigen Bereich')
|
|
590 |
] ifFalse:[
|
|
591 |
messages := #('Not super-user'
|
|
592 |
'No such file or directory'
|
|
593 |
nil "'No such process' "
|
|
594 |
nil "'interrupted system call' "
|
|
595 |
'I/O error'
|
|
596 |
nil "'No such device or address' "
|
|
597 |
'Arg list too long'
|
|
598 |
'Exec format error'
|
|
599 |
nil "'Bad file number'"
|
|
600 |
nil "'No children' "
|
|
601 |
'No more processes'
|
|
602 |
'Not enough core'
|
|
603 |
'Permission denied'
|
|
604 |
nil "'Bad address' "
|
|
605 |
nil "'Block device required' "
|
|
606 |
nil "'Mount device busy' "
|
|
607 |
'File exists'
|
|
608 |
nil "'Cross-device link' "
|
|
609 |
'No such device'
|
|
610 |
'Not a directory'
|
|
611 |
'Is a directory'
|
|
612 |
nil 'Invalid argument'
|
|
613 |
'File table overflow'
|
|
614 |
'Too many open files'
|
|
615 |
nil "'Not a typewriter' "
|
|
616 |
'Text file busy'
|
|
617 |
'File too large'
|
|
618 |
'No space left on device'
|
|
619 |
'Illegal seek'
|
|
620 |
'Read only file system'
|
|
621 |
'Too many links'
|
|
622 |
'Broken pipe'
|
|
623 |
'Math arg out of domain of func'
|
|
624 |
'Math result not representable')
|
|
625 |
].
|
|
626 |
|
|
627 |
(errNr between:1 and:messages size) ifTrue:[
|
|
628 |
msg := messages at:errNr
|
|
629 |
].
|
|
630 |
msg isNil ifTrue:[
|
|
631 |
^ ('ErrorNr: ' , errNr printString)
|
|
632 |
].
|
|
633 |
^ msg
|
|
634 |
! !
|
|
635 |
|
|
636 |
!OperatingSystem class methodsFor:'interrupts'!
|
|
637 |
|
10
|
638 |
blockInterrupts
|
|
639 |
"needed, for proper semaphore handling"
|
|
640 |
%{
|
|
641 |
BLOCKINTERRUPTS();
|
|
642 |
%}
|
|
643 |
!
|
|
644 |
|
|
645 |
unblockInterrupts
|
|
646 |
"needed, for proper semaphore handling"
|
|
647 |
%{
|
|
648 |
UNBLOCKINTERRUPTS();
|
|
649 |
%}
|
|
650 |
!
|
|
651 |
|
1
|
652 |
enableUserInterrupts
|
|
653 |
"enable userInterrupt (^C) handling;
|
|
654 |
after enabling, ^C will send the message 'userInterrupt'
|
|
655 |
to the UserInterruptHandler object."
|
|
656 |
|
|
657 |
%{ /* NOCONTEXT */
|
10
|
658 |
extern void userInterrupt();
|
1
|
659 |
|
|
660 |
signal(SIGINT, userInterrupt);
|
|
661 |
/* signal(SIGQUIT, userInterrupt); */
|
|
662 |
%}
|
|
663 |
!
|
|
664 |
|
|
665 |
enableFpExceptionInterrupts
|
|
666 |
"enable floating point exception interrupts (if the
|
|
667 |
architecture supports it).
|
|
668 |
after enabling, fpu-exceptions will send the message
|
|
669 |
'fpuExceptionInterrupt' to the FPUExceptionInterruptHandler object."
|
|
670 |
|
|
671 |
%{ /* NOCONTEXT */
|
|
672 |
extern void fpExceptionInterrupt();
|
|
673 |
|
|
674 |
signal(SIGFPE, fpExceptionInterrupt);
|
|
675 |
%}
|
|
676 |
!
|
|
677 |
|
|
678 |
enableSignalInterrupts
|
|
679 |
"enable signal exception interrupts (trap, buserror & segm. violation).
|
|
680 |
after enabling, these exceptions will send the message
|
|
681 |
'signalInterrupt' to the SignalInterruptHandler object."
|
|
682 |
|
|
683 |
%{ /* NOCONTEXT */
|
|
684 |
extern void signalPIPEInterrupt();
|
|
685 |
extern void signalBUSInterrupt();
|
|
686 |
extern void signalSEGVInterrupt();
|
|
687 |
|
|
688 |
signal(SIGPIPE, signalPIPEInterrupt);
|
|
689 |
#ifdef SIGBUS
|
|
690 |
signal(SIGBUS, signalBUSInterrupt);
|
|
691 |
#endif
|
|
692 |
signal(SIGSEGV, signalSEGVInterrupt);
|
|
693 |
%}
|
|
694 |
!
|
|
695 |
|
10
|
696 |
enableIOInterruptsOn:fd
|
|
697 |
"turn on IO interrupts for a filedescriptor"
|
1
|
698 |
|
|
699 |
%{ /* NOCONTEXT */
|
10
|
700 |
|
|
701 |
int ret, flags;
|
1
|
702 |
extern void ioInterrupt();
|
|
703 |
|
10
|
704 |
#if defined(F_GETFL) && defined(F_SETFL)
|
|
705 |
# if defined(FASYNC)
|
|
706 |
if (_isSmallInteger(fd)) {
|
|
707 |
# ifdef SIGPOLL
|
|
708 |
signal(SIGPOLL, ioInterrupt);
|
|
709 |
# endif
|
|
710 |
# ifdef SIGIO
|
|
711 |
signal(SIGIO, ioInterrupt);
|
|
712 |
# endif
|
|
713 |
flags = fcntl(_intVal(fd), F_GETFL, 0);
|
|
714 |
ret = fcntl(_intVal(fd), F_SETFL, flags | FASYNC);
|
|
715 |
if (ret >= 0) ret = flags;
|
|
716 |
RETURN ( _MKSMALLINT(ret) );
|
|
717 |
}
|
|
718 |
# endif
|
1
|
719 |
#endif
|
13
|
720 |
#ifdef SIGURG
|
|
721 |
signal(SIGURG, ioInterrupt);
|
|
722 |
#endif
|
1
|
723 |
%}
|
10
|
724 |
.
|
|
725 |
self primitiveFailed
|
|
726 |
!
|
|
727 |
|
|
728 |
disableIOInterruptsOn:fd
|
|
729 |
"turn off IO interrupts for a filedescriptor"
|
|
730 |
|
|
731 |
%{ /* NOCONTEXT */
|
|
732 |
|
|
733 |
int ret, flags;
|
|
734 |
|
|
735 |
#if defined(F_GETFL) && defined(F_SETFL)
|
|
736 |
# if defined(FASYNC)
|
|
737 |
if (_isSmallInteger(fd)) {
|
|
738 |
flags = fcntl(_intVal(fd), F_GETFL, 0);
|
|
739 |
ret = fcntl(_intVal(fd), F_SETFL, flags & ~FASYNC);
|
|
740 |
if (ret >= 0) ret = flags;
|
|
741 |
RETURN ( _MKSMALLINT(ret) );
|
|
742 |
}
|
|
743 |
# endif
|
|
744 |
#endif
|
|
745 |
%}
|
|
746 |
.
|
|
747 |
self primitiveFailed
|
1
|
748 |
!
|
|
749 |
|
2
|
750 |
enableChildSignalInterrupts
|
|
751 |
"enable childSignal interrupts
|
|
752 |
(SIGCHLD, if the architecture supports it).
|
|
753 |
after enabling, these signals will send the message
|
|
754 |
'childSignalInterrupt' to the ChildSignalInterruptHandler object."
|
|
755 |
|
|
756 |
%{ /* NOCONTEXT */
|
|
757 |
extern void signalChildInterrupt();
|
|
758 |
|
|
759 |
#ifdef SIGCHLD
|
|
760 |
signal(SIGCHLD, signalChildInterrupt);
|
13
|
761 |
RETURN(true);
|
2
|
762 |
#else
|
|
763 |
# ifdef SIGCLD
|
|
764 |
signal(SIGCLD, signalChildInterrupt);
|
13
|
765 |
RETURN(true);
|
2
|
766 |
# endif
|
|
767 |
#endif
|
|
768 |
%}
|
13
|
769 |
.
|
|
770 |
^ false
|
2
|
771 |
!
|
|
772 |
|
1
|
773 |
startSpyTimer
|
|
774 |
"trigger a spyInterrupt, to be signalled after some (short) time.
|
|
775 |
This is used by MessageTally for profiling."
|
|
776 |
|
|
777 |
%{ /* NOCONTEXT */
|
|
778 |
|
|
779 |
extern void spyInterrupt();
|
10
|
780 |
#if defined(ITIMER_VIRTUAL)
|
1
|
781 |
struct itimerval dt;
|
|
782 |
|
|
783 |
dt.it_interval.tv_sec = 0;
|
|
784 |
dt.it_interval.tv_usec = 0;
|
|
785 |
dt.it_value.tv_sec = 0;
|
2
|
786 |
dt.it_value.tv_usec = 1000; /* 1000 Hz */
|
1
|
787 |
setitimer(ITIMER_VIRTUAL, &dt, 0);
|
42
|
788 |
#ifndef SYSV4
|
|
789 |
# if defined(BSD) || defined(HAS_SIGSETMASK)
|
1
|
790 |
sigsetmask(0);
|
|
791 |
# endif
|
|
792 |
# endif
|
|
793 |
|
13
|
794 |
# ifdef SIGVTALRM
|
1
|
795 |
signal(SIGVTALRM, spyInterrupt);
|
13
|
796 |
# else
|
1
|
797 |
signal(SIGALRM, spyInterrupt);
|
13
|
798 |
# endif
|
|
799 |
|
|
800 |
RETURN (true);
|
1
|
801 |
#endif
|
|
802 |
%}
|
13
|
803 |
.
|
|
804 |
^ false
|
1
|
805 |
!
|
|
806 |
|
|
807 |
stopSpyTimer
|
|
808 |
"stop spy timing"
|
|
809 |
|
|
810 |
%{ /* NOCONTEXT */
|
|
811 |
|
10
|
812 |
#if defined(ITIMER_VIRTUAL)
|
1
|
813 |
struct itimerval dt;
|
|
814 |
|
|
815 |
dt.it_interval.tv_sec = 0;
|
|
816 |
dt.it_interval.tv_usec = 0;
|
|
817 |
dt.it_value.tv_sec = 0;
|
|
818 |
dt.it_value.tv_usec = 0;
|
|
819 |
setitimer(ITIMER_VIRTUAL, &dt, 0);
|
13
|
820 |
RETURN (true);
|
10
|
821 |
#endif
|
|
822 |
%}
|
13
|
823 |
.
|
|
824 |
^ false
|
10
|
825 |
!
|
|
826 |
|
|
827 |
enableTimer:millis
|
|
828 |
"trigger a timerInterrupt, to be signalled after some time."
|
|
829 |
|
|
830 |
%{ /* NOCONTEXT */
|
|
831 |
|
|
832 |
extern void timerInterrupt();
|
|
833 |
#if defined(ITIMER_REAL)
|
|
834 |
struct itimerval dt;
|
|
835 |
|
|
836 |
dt.it_interval.tv_sec = 0;
|
|
837 |
dt.it_interval.tv_usec = 0;
|
|
838 |
dt.it_value.tv_sec = _intVal(millis) / 1000;
|
|
839 |
dt.it_value.tv_usec = (_intVal(millis) % 1000) * 1000;
|
|
840 |
setitimer(ITIMER_REAL, &dt, 0);
|
42
|
841 |
#ifndef SYSV4
|
|
842 |
# if defined(BSD) || defined(HAS_SIGSETMASK)
|
10
|
843 |
sigsetmask(0);
|
|
844 |
# endif
|
1
|
845 |
# endif
|
13
|
846 |
signal(SIGALRM, timerInterrupt);
|
10
|
847 |
|
13
|
848 |
RETURN (true);
|
|
849 |
#endif
|
10
|
850 |
%}
|
13
|
851 |
.
|
|
852 |
^ false
|
10
|
853 |
!
|
|
854 |
|
|
855 |
disableTimer
|
|
856 |
"disable timer interrupt"
|
|
857 |
|
|
858 |
%{ /* NOCONTEXT */
|
|
859 |
|
|
860 |
#if defined(ITIMER_REAL)
|
|
861 |
struct itimerval dt;
|
|
862 |
|
|
863 |
dt.it_interval.tv_sec = 0;
|
|
864 |
dt.it_interval.tv_usec = 0;
|
|
865 |
dt.it_value.tv_sec = 0;
|
|
866 |
dt.it_value.tv_usec = 0;
|
|
867 |
setitimer(ITIMER_REAL, &dt, 0);
|
13
|
868 |
RETURN (true);
|
10
|
869 |
#endif
|
1
|
870 |
%}
|
13
|
871 |
.
|
|
872 |
^ false
|
1
|
873 |
! !
|
|
874 |
|
|
875 |
!OperatingSystem class methodsFor:'time and date'!
|
|
876 |
|
|
877 |
getTimeLow
|
|
878 |
"return low 16 bits of current time.
|
|
879 |
Obsolete: Dont use this method, use getTimeParts below.
|
|
880 |
This method will not always return the correct time
|
|
881 |
if used together with getTimeHi.
|
|
882 |
(a wrap between the two getTimeXXX calls could occur)"
|
|
883 |
|
|
884 |
%{ /* NOCONTEXT */
|
|
885 |
|
|
886 |
RETURN ( _MKSMALLINT(time(0) & 0xFFFF) );
|
|
887 |
%}
|
|
888 |
.
|
|
889 |
self primitiveFailed
|
|
890 |
|
|
891 |
"OperatingSystem getTimeLow"
|
|
892 |
!
|
|
893 |
|
|
894 |
getTimeHi
|
|
895 |
"return hi 16 bits of current time.
|
|
896 |
Obsolete: Dont use this method, use getTimeParts below.
|
|
897 |
This method will NOT always return the correct time
|
|
898 |
if used together with getTimeHi.
|
|
899 |
(a wrap between the two getTimeXXX calls could occur)"
|
|
900 |
|
|
901 |
%{ /* NOCONTEXT */
|
|
902 |
|
|
903 |
RETURN ( _MKSMALLINT((time(0) >> 16) & 0xFFFF) );
|
|
904 |
%}
|
|
905 |
.
|
|
906 |
self primitiveFailed
|
|
907 |
|
|
908 |
"OperatingSystem getTimeHi"
|
|
909 |
!
|
|
910 |
|
|
911 |
getTimeInto:aBlock
|
|
912 |
"evaluate the argument aBlock, passing the time-parts of
|
|
913 |
the current time as arguments."
|
|
914 |
|
|
915 |
|low hi|
|
|
916 |
%{
|
|
917 |
int now;
|
|
918 |
|
|
919 |
now = time(0);
|
|
920 |
hi = _MKSMALLINT((now >> 16) & 0xFFFF);
|
|
921 |
low = _MKSMALLINT(now & 0xFFFF);
|
|
922 |
%}
|
|
923 |
.
|
|
924 |
aBlock value:low value:hi
|
|
925 |
|
|
926 |
"OperatingSystem getTimeTimeInto:[:low :hi | low printNewline. hi printNewline]"
|
|
927 |
!
|
|
928 |
|
|
929 |
getTime
|
|
930 |
"return current Time (in seconds since 1970).
|
|
931 |
This might return a LargeInteger some time."
|
|
932 |
|
|
933 |
^ self getTimeHi * 16r10000 + self getTimeLow
|
|
934 |
|
|
935 |
"OperatingSystem getTime"
|
|
936 |
!
|
|
937 |
|
|
938 |
computeDatePartsOf:timeLow and:timeHi for:aBlock
|
|
939 |
"compute year, month and day from the time-parts timeLow and
|
|
940 |
timeHi and evaluate the argument, a 3-arg block with these.
|
|
941 |
This method was added to avoid LargeInteger arithmetic; the time-parts
|
|
942 |
are those returned by getTimeLow and getTimeHi."
|
|
943 |
|
|
944 |
|year month day|
|
|
945 |
|
|
946 |
((timeLow isMemberOf:SmallInteger) and:[timeHi isMemberOf:SmallInteger])
|
|
947 |
ifFalse:[
|
|
948 |
^ self primitiveFailed
|
|
949 |
].
|
|
950 |
%{
|
|
951 |
struct tm *tmPtr;
|
|
952 |
long t;
|
|
953 |
|
|
954 |
t = (_intVal(timeHi) << 16) | _intVal(timeLow);
|
|
955 |
tmPtr = localtime(&t);
|
|
956 |
year = _MKSMALLINT(tmPtr->tm_year + 1900);
|
|
957 |
month = _MKSMALLINT(tmPtr->tm_mon + 1);
|
|
958 |
day = _MKSMALLINT(tmPtr->tm_mday);
|
|
959 |
%}
|
|
960 |
.
|
|
961 |
aBlock value:year value:month value:day
|
|
962 |
!
|
|
963 |
|
|
964 |
computeTimePartsOf:timeLow and:timeHi for:aBlock
|
|
965 |
"compute hours, minutes and seconds from the time-parts timeLow and
|
|
966 |
timeHi and evaluate the argument, a 3-arg block with these."
|
|
967 |
|
|
968 |
|hours minutes seconds|
|
|
969 |
|
|
970 |
((timeLow isMemberOf:SmallInteger) and:[timeHi isMemberOf:SmallInteger])
|
|
971 |
ifFalse:[
|
|
972 |
^ self primitiveFailed
|
|
973 |
].
|
|
974 |
%{
|
|
975 |
struct tm *tmPtr;
|
|
976 |
long t;
|
|
977 |
|
|
978 |
t = (_intVal(timeHi) << 16) | _intVal(timeLow);
|
|
979 |
tmPtr = localtime(&t);
|
|
980 |
hours = _MKSMALLINT(tmPtr->tm_hour);
|
|
981 |
minutes = _MKSMALLINT(tmPtr->tm_min);
|
|
982 |
seconds = _MKSMALLINT(tmPtr->tm_sec);
|
|
983 |
%}
|
|
984 |
.
|
|
985 |
aBlock value:hours value:minutes value:seconds
|
|
986 |
!
|
|
987 |
|
|
988 |
getMillisecondTime
|
|
989 |
"since range is limited to 0..1ffffff and value is wrapping around
|
|
990 |
at 1fffffff, this can only be used for relative time deltas.
|
|
991 |
Use methods below to compare and add time deltas (should move to Time)"
|
|
992 |
|
|
993 |
%{ /* NOCONTEXT */
|
|
994 |
|
|
995 |
long t;
|
|
996 |
#ifdef SYSV
|
|
997 |
# ifdef HZ
|
|
998 |
/* sys5 time */
|
|
999 |
long ticks;
|
|
1000 |
struct tms tb;
|
|
1001 |
|
|
1002 |
ticks = times(&tb);
|
|
1003 |
t = (ticks * 1000) / HZ;
|
|
1004 |
# endif
|
|
1005 |
#else
|
|
1006 |
/* bsd time */
|
|
1007 |
struct timeval tb;
|
|
1008 |
struct timezone tzb;
|
|
1009 |
|
|
1010 |
gettimeofday(&tb, &tzb);
|
|
1011 |
t = tb.tv_sec*1000 + tb.tv_usec/1000;
|
|
1012 |
#endif
|
|
1013 |
RETURN ( _MKSMALLINT(t & 0x0FFFFFFF) );
|
|
1014 |
%}
|
|
1015 |
.
|
|
1016 |
self error:'time not available'
|
|
1017 |
!
|
|
1018 |
|
|
1019 |
millisecondTimeDeltaBetween:msTime1 and:msTime2
|
|
1020 |
"subtract two millisecond times (such as returned getMillisecondTime).
|
|
1021 |
The returned value is msTime1 - msTime2 where a wrap occurs at:16r0FFFFFFF."
|
|
1022 |
|
|
1023 |
(msTime1 > msTime2) ifTrue:[
|
|
1024 |
^ msTime1 - msTime2
|
|
1025 |
].
|
|
1026 |
^ msTime1 + 16r10000000 - msTime2
|
|
1027 |
!
|
|
1028 |
|
|
1029 |
millisecondTime:msTime1 isAfter:msTime2
|
|
1030 |
"return true if msTime1 is after msTime2, false if not.
|
|
1031 |
handling wrap at 16r0FFFFFFF. The two arguments are
|
|
1032 |
millisecond times (such as returned getMillisecondTime)."
|
|
1033 |
|
|
1034 |
(msTime1 > msTime2) ifTrue:[
|
|
1035 |
((msTime1 - msTime2) > 16r08000000) ifTrue:[
|
|
1036 |
^ false
|
|
1037 |
].
|
|
1038 |
^ true
|
|
1039 |
].
|
|
1040 |
((msTime2 - msTime1) > 16r08000000) ifTrue:[
|
|
1041 |
^ true
|
|
1042 |
].
|
|
1043 |
^ false
|
|
1044 |
!
|
|
1045 |
|
|
1046 |
millisecondTimeAdd:msTime1 and:msTime2
|
|
1047 |
"add two millisecond times (such as returned getMillisecondTime).
|
|
1048 |
The returned value is msTime1 + msTime2 where a wrap occurs at:16r0FFFFFFF."
|
|
1049 |
|
|
1050 |
|sum|
|
|
1051 |
|
|
1052 |
sum := msTime1 + msTime2.
|
|
1053 |
(sum > 16r0FFFFFFF) ifTrue:[^ sum - 16r10000000].
|
|
1054 |
(sum < 0) ifTrue:[^ sum + 16r10000000].
|
|
1055 |
^ sum
|
|
1056 |
!
|
|
1057 |
|
|
1058 |
millisecondDelay:millis
|
|
1059 |
"delay execution for millis milliseconds."
|
|
1060 |
|
10
|
1061 |
self selectOn:nil withTimeOut:millis
|
1
|
1062 |
|
10
|
1063 |
"OperatingSystem millisecondDelay:2000"
|
1
|
1064 |
!
|
|
1065 |
|
|
1066 |
sleep:numberOfSeconds
|
|
1067 |
"cease any action for some time.
|
|
1068 |
Not really useful since not even low-prio processes and interrupt
|
|
1069 |
handling will run during the sleep - use millisecondDelay:."
|
|
1070 |
|
|
1071 |
%{ /* NOCONTEXT */
|
|
1072 |
|
|
1073 |
if (_isSmallInteger(numberOfSeconds)) {
|
|
1074 |
sleep(_intVal(numberOfSeconds));
|
|
1075 |
RETURN ( self );
|
|
1076 |
}
|
|
1077 |
%}
|
|
1078 |
.
|
|
1079 |
self primitiveFailed
|
10
|
1080 |
! !
|
|
1081 |
|
|
1082 |
!OperatingSystem class methodsFor:'waiting for events'!
|
|
1083 |
|
|
1084 |
setBlocking:aBoolean on:fd
|
|
1085 |
"set/clear the blocking attribute - if set (which is the default)
|
|
1086 |
a read on the fileDescriptor will block until data is available.
|
|
1087 |
If cleared, a read operation will immediately return with a value of
|
|
1088 |
nil."
|
|
1089 |
|
|
1090 |
%{ /* NOCONTEXT */
|
|
1091 |
|
|
1092 |
int ret, flags;
|
|
1093 |
int savInt;
|
|
1094 |
|
|
1095 |
#if defined(F_GETFL) && defined(F_SETFL)
|
|
1096 |
# if defined(FNDELAY)
|
|
1097 |
if (_isSmallInteger(fd)) {
|
|
1098 |
flags = fcntl(_intVal(fd), F_GETFL, 0);
|
|
1099 |
if (aBoolean == true) {
|
|
1100 |
ret = fcntl(_intVal(fd), F_SETFL, flags & ~FNDELAY);
|
|
1101 |
} else {
|
|
1102 |
ret = fcntl(_intVal(fd), F_SETFL, flags | FNDELAY);
|
|
1103 |
}
|
|
1104 |
if (ret >= 0) ret = flags;
|
|
1105 |
RETURN ( _MKSMALLINT(ret) );
|
|
1106 |
}
|
|
1107 |
# endif
|
|
1108 |
#endif
|
|
1109 |
%}
|
|
1110 |
.
|
|
1111 |
self primitiveFailed
|
1
|
1112 |
!
|
|
1113 |
|
10
|
1114 |
readCheck:fd
|
|
1115 |
"return true, if data is available on a filedescriptor"
|
|
1116 |
|
|
1117 |
(self selectOnAnyReadable:(Array with:fd)
|
|
1118 |
writable:nil
|
|
1119 |
error:nil
|
|
1120 |
withTimeOut:0) == fd
|
|
1121 |
ifTrue:[^ true].
|
|
1122 |
^ false
|
|
1123 |
!
|
|
1124 |
|
|
1125 |
writeCheck:fd
|
|
1126 |
"return true, if filedescriptor can be written without blocking"
|
|
1127 |
|
|
1128 |
(self selectOnAnyReadable:nil
|
|
1129 |
writable:(Array with:fd)
|
|
1130 |
error:nil
|
|
1131 |
withTimeOut:0) == fd
|
|
1132 |
ifTrue:[^ true].
|
|
1133 |
^ false
|
|
1134 |
!
|
|
1135 |
|
|
1136 |
selectOn:fd withTimeOut:millis
|
|
1137 |
"wait for aFileDesriptor to become ready; timeout after t milliseconds.
|
1
|
1138 |
Return true, if i/o ok, false if timed-out or interrupted.
|
|
1139 |
With 0 as timeout argument, this can be used to check for availability
|
|
1140 |
of read-data.
|
|
1141 |
Experimental."
|
|
1142 |
|
3
|
1143 |
^ self selectOnAnyReadable:(Array with:fd)
|
|
1144 |
writable:(Array with:fd)
|
|
1145 |
error:nil
|
10
|
1146 |
withTimeOut:millis
|
1
|
1147 |
!
|
|
1148 |
|
10
|
1149 |
selectOn:fd1 and:fd2 withTimeOut:millis
|
|
1150 |
"wait for any fd to become ready; timeout after t milliseconds.
|
1
|
1151 |
Return fd if i/o ok, nil if timed-out or interrupted.
|
|
1152 |
Experimental."
|
|
1153 |
|
3
|
1154 |
^ self selectOnAnyReadable:(Array with:fd1 with:fd2)
|
|
1155 |
writable:(Array with:fd1 with:fd2)
|
|
1156 |
error:nil
|
10
|
1157 |
withTimeOut:millis
|
1
|
1158 |
!
|
|
1159 |
|
10
|
1160 |
selectOnAnyReadable:fdArray withTimeOut:millis
|
3
|
1161 |
"wait for any fd in fdArray (an Array of integers) to become ready for reading;
|
10
|
1162 |
timeout after t milliseconds. An empty set will always wait.
|
3
|
1163 |
Return first ready fd if i/o ok, nil if timed-out or interrupted.
|
|
1164 |
Experimental."
|
|
1165 |
|
|
1166 |
^ self selectOnAnyReadable:fdArray
|
|
1167 |
writable:nil
|
|
1168 |
error:nil
|
10
|
1169 |
withTimeOut:millis
|
3
|
1170 |
!
|
|
1171 |
|
10
|
1172 |
selectOnAny:fdArray withTimeOut:millis
|
1
|
1173 |
"wait for any fd in fdArray (an Array of integers) to become ready;
|
10
|
1174 |
timeout after t milliseconds. An empty set will always wait.
|
1
|
1175 |
Return first ready fd if i/o ok, nil if timed-out or interrupted.
|
|
1176 |
Experimental."
|
|
1177 |
|
3
|
1178 |
^ self selectOnAnyReadable:fdArray
|
|
1179 |
writable:fdArray
|
|
1180 |
error:nil
|
10
|
1181 |
withTimeOut:millis
|
3
|
1182 |
!
|
|
1183 |
|
10
|
1184 |
selectOnAnyReadable:readFdArray writable:writeFdArray error:errorFdArray withTimeOut:millis
|
3
|
1185 |
"wait for any fd in readFdArray (an Array of integers) to become ready for reading,
|
|
1186 |
writeFdArray to become ready for writing.
|
10
|
1187 |
timeout after t milliseconds. Empty sets will always wait.
|
3
|
1188 |
Return first ready fd if i/o ok, nil if timed-out or interrupted.
|
|
1189 |
Experimental."
|
|
1190 |
|
10
|
1191 |
|rcount wcount ecount|
|
1
|
1192 |
|
51
|
1193 |
(readFdArray notNil and:[readFdArray class ~~ Array]) ifTrue:[
|
|
1194 |
^ self error:'argument must be nil or an Array'
|
3
|
1195 |
].
|
51
|
1196 |
(writeFdArray notNil and:[writeFdArray class ~~ Array]) ifTrue:[
|
|
1197 |
^ self error:'argument must be nil or an Array'
|
1
|
1198 |
].
|
51
|
1199 |
(errorFdArray notNil and:[errorFdArray class ~~ Array]) ifTrue:[
|
|
1200 |
^ self error:'argument must be nil or an Array'
|
3
|
1201 |
].
|
|
1202 |
rcount := readFdArray size.
|
|
1203 |
wcount := writeFdArray size.
|
|
1204 |
ecount := errorFdArray size.
|
1
|
1205 |
%{
|
|
1206 |
fd_set rset, wset, eset;
|
|
1207 |
int t, f, maxF, i, lX, bX;
|
|
1208 |
struct timeval wt;
|
|
1209 |
OBJ fd, retFd;
|
|
1210 |
|
|
1211 |
if (_isSmallInteger(millis)) {
|
|
1212 |
FD_ZERO(&rset);
|
|
1213 |
FD_ZERO(&wset);
|
|
1214 |
FD_ZERO(&eset);
|
|
1215 |
|
51
|
1216 |
maxF = -1;
|
3
|
1217 |
for (i=0; i<_intVal(rcount);i++) {
|
|
1218 |
fd = _ArrayInstPtr(readFdArray)->a_element[i];
|
1
|
1219 |
if (fd != nil) {
|
|
1220 |
f = _intVal(fd);
|
|
1221 |
if ((f >= 0) && (f < FD_SETSIZE)) {
|
|
1222 |
FD_SET(f, &rset);
|
3
|
1223 |
if (f > maxF) maxF = f;
|
|
1224 |
}
|
|
1225 |
}
|
|
1226 |
}
|
|
1227 |
for (i=0; i<_intVal(wcount);i++) {
|
|
1228 |
fd = _ArrayInstPtr(writeFdArray)->a_element[i];
|
|
1229 |
if (fd != nil) {
|
|
1230 |
f = _intVal(fd);
|
|
1231 |
if ((f >= 0) && (f < FD_SETSIZE)) {
|
|
1232 |
FD_SET(f, &wset);
|
|
1233 |
if (f > maxF) maxF = f;
|
|
1234 |
}
|
|
1235 |
}
|
|
1236 |
}
|
|
1237 |
for (i=0; i<_intVal(ecount);i++) {
|
|
1238 |
fd = _ArrayInstPtr(errorFdArray)->a_element[i];
|
|
1239 |
if (fd != nil) {
|
|
1240 |
f = _intVal(fd);
|
|
1241 |
if ((f >= 0) && (f < FD_SETSIZE)) {
|
|
1242 |
FD_SET(f, &eset);
|
1
|
1243 |
if (f > maxF) maxF = f;
|
|
1244 |
}
|
|
1245 |
}
|
|
1246 |
}
|
|
1247 |
t = _intVal(millis);
|
|
1248 |
wt.tv_sec = t / 1000;
|
|
1249 |
wt.tv_usec = (t % 1000) * 1000;
|
51
|
1250 |
|
1
|
1251 |
if (select(maxF+1, &rset, &wset, &eset, &wt)) {
|
|
1252 |
for (i=0; i <= maxF; i++) {
|
|
1253 |
if (FD_ISSET(i, &rset)
|
3
|
1254 |
|| FD_ISSET(i, &wset)
|
|
1255 |
|| FD_ISSET(i, &eset)) {
|
1
|
1256 |
RETURN ( _MKSMALLINT(i) );
|
|
1257 |
}
|
|
1258 |
}
|
|
1259 |
}
|
|
1260 |
RETURN ( nil );
|
|
1261 |
}
|
|
1262 |
%}
|
|
1263 |
.
|
|
1264 |
self primitiveFailed
|
|
1265 |
! !
|
|
1266 |
|
|
1267 |
!OperatingSystem class methodsFor:'executing commands'!
|
|
1268 |
|
|
1269 |
fork
|
|
1270 |
"fork a new process"
|
|
1271 |
|
|
1272 |
%{ /* NOCONTEXT */
|
|
1273 |
|
|
1274 |
int pid;
|
|
1275 |
|
|
1276 |
pid = fork();
|
|
1277 |
RETURN ( _MKSMALLINT(pid) );
|
|
1278 |
%}
|
|
1279 |
.
|
|
1280 |
self primitiveFailed
|
|
1281 |
!
|
|
1282 |
|
|
1283 |
exec:aPath withArguments:argArray
|
|
1284 |
"execute the unix command specified by the argument, aPath, with
|
|
1285 |
arguments in argArray.
|
|
1286 |
If successful, this method does not return and smalltalk is gone.
|
|
1287 |
If not sucessfull, false is returned. Normal use is with fork."
|
|
1288 |
|
|
1289 |
%{
|
|
1290 |
char *argv[64];
|
|
1291 |
int nargs, i;
|
|
1292 |
OBJ arg;
|
|
1293 |
|
|
1294 |
if (_isString(aPath) && _isArray(argArray)) {
|
2
|
1295 |
nargs = _arraySize(argArray);
|
1
|
1296 |
for (i=0; i < nargs; i++) {
|
|
1297 |
arg = _ArrayInstPtr(argArray)->a_element[i];
|
2
|
1298 |
if (_isString(arg)) {
|
1
|
1299 |
argv[i] = (char *) _stringVal(arg);
|
2
|
1300 |
}
|
1
|
1301 |
}
|
|
1302 |
argv[i] = NULL;
|
|
1303 |
execv(_stringVal(aPath), argv);
|
|
1304 |
/* should not be reached */
|
|
1305 |
RETURN ( false );
|
|
1306 |
}
|
|
1307 |
%}
|
|
1308 |
.
|
|
1309 |
self primitiveFailed
|
|
1310 |
!
|
|
1311 |
|
|
1312 |
executeCommand:aCommandString
|
|
1313 |
"execute the unix command specified by the argument, aCommandString.
|
|
1314 |
Return true if successful, false otherwise. Smalltalk is suspended,
|
|
1315 |
while the command is executing."
|
|
1316 |
|
|
1317 |
%{ /* NOCONTEXT */
|
|
1318 |
|
|
1319 |
int status;
|
|
1320 |
extern OBJ ErrorNumber;
|
|
1321 |
|
|
1322 |
if (_isString(aCommandString)) {
|
|
1323 |
status = system((char *) _stringVal(aCommandString));
|
|
1324 |
if (status == 0) {
|
|
1325 |
RETURN ( true );
|
|
1326 |
}
|
|
1327 |
ErrorNumber = _MKSMALLINT(errno);
|
|
1328 |
RETURN ( false );
|
|
1329 |
}
|
|
1330 |
%}
|
|
1331 |
.
|
|
1332 |
self primitiveFailed
|
|
1333 |
|
|
1334 |
"OperatingSystem executeCommand:'pwd'"
|
|
1335 |
"OperatingSystem executeCommand:'ls -l'"
|
|
1336 |
"OperatingSystem executeCommand:'invalidCommand'"
|
|
1337 |
! !
|
|
1338 |
|
|
1339 |
!OperatingSystem class methodsFor:'file access'!
|
|
1340 |
|
10
|
1341 |
getCharacter
|
|
1342 |
"read a character from keyboard - this is a blocking low-level
|
|
1343 |
read provided for debugger and fatal conditions. Use Stdin or
|
|
1344 |
(even better) the event mechanisms provided."
|
|
1345 |
|
|
1346 |
%{ /* NOCONTEXT */
|
|
1347 |
|
|
1348 |
RETURN ( _MKSMALLINT(getchar()) );
|
|
1349 |
%}
|
|
1350 |
!
|
|
1351 |
|
2
|
1352 |
fileSeparator
|
|
1353 |
"return the character used to separate names in a path.
|
|
1354 |
This character differs for MSDOS and other systems,
|
|
1355 |
(but those are currently not supported)"
|
|
1356 |
|
|
1357 |
^ $/
|
|
1358 |
!
|
|
1359 |
|
|
1360 |
baseNameOf:aPathString
|
|
1361 |
"return the baseName of the argument, aPathString
|
1
|
1362 |
- thats the file/directory name without leading parent-dirs
|
|
1363 |
(i.e. OperatingSystem baseNameOf:'/usr/lib/st/file' -> 'file'
|
|
1364 |
and OperatingSystem baseNameOf:'/usr/lib' -> lib).
|
2
|
1365 |
This method does not check if the path is valid
|
|
1366 |
(i.e. if these directories really exist)."
|
|
1367 |
|
|
1368 |
|prev index sep|
|
1
|
1369 |
|
2
|
1370 |
sep := self fileSeparator.
|
|
1371 |
((aPathString size == 1) and:[(aPathString at:1) == sep]) ifTrue:[
|
|
1372 |
^ aPathString
|
|
1373 |
].
|
1
|
1374 |
prev := 1.
|
|
1375 |
[true] whileTrue:[
|
10
|
1376 |
index := aPathString indexOf:sep startingAt:prev.
|
2
|
1377 |
index == 0 ifTrue:[
|
|
1378 |
^ aPathString copyFrom:prev
|
|
1379 |
].
|
1
|
1380 |
prev := index + 1
|
|
1381 |
]
|
2
|
1382 |
|
|
1383 |
"OperatingSystem baseNameOf:'/fee/foo/bar'"
|
|
1384 |
"OperatingSystem baseNameOf:'foo/bar'"
|
|
1385 |
"OperatingSystem baseNameOf:'../../foo/bar'"
|
1
|
1386 |
!
|
|
1387 |
|
2
|
1388 |
directoryNameOf:aPathString
|
1
|
1389 |
"return the directoryName of the argument, aPath
|
|
1390 |
- thats the name of the directory where aPath is
|
|
1391 |
(i.e. OperatingSystem directoryNameOf:'/usr/lib/st/file' -> '/usr/lib/st'
|
|
1392 |
and OperatingSystem directoryNameOf:'/usr/lib' -> /usr').
|
|
1393 |
This method does not check if the path is valid (i.e. if these directories
|
|
1394 |
really exist)."
|
|
1395 |
|
2
|
1396 |
|last index sep sepString|
|
1
|
1397 |
|
2
|
1398 |
sep := self fileSeparator.
|
|
1399 |
sepString := sep asString.
|
|
1400 |
(aPathString = sepString) ifTrue:[
|
|
1401 |
^ aPathString
|
|
1402 |
].
|
|
1403 |
(aPathString startsWith:sepString) ifFalse:[
|
|
1404 |
(aPathString endsWith:sepString) ifTrue:[
|
|
1405 |
^ aPathString copyFrom:1 to:(aPathString size - 1)
|
1
|
1406 |
].
|
|
1407 |
].
|
|
1408 |
last := 1.
|
|
1409 |
[true] whileTrue:[
|
10
|
1410 |
index := aPathString indexOf:sep startingAt:(last + 1).
|
2
|
1411 |
index == 0 ifTrue:[
|
|
1412 |
(last == 1) ifTrue:[^ sepString].
|
|
1413 |
^ aPathString copyFrom:1 to:(last - 1)
|
|
1414 |
].
|
|
1415 |
last := index.
|
1
|
1416 |
]
|
|
1417 |
|
|
1418 |
"OperatingSystem directoryNameOf:'/fee/foo/bar'"
|
|
1419 |
"OperatingSystem directoryNameOf:'foo/bar'"
|
|
1420 |
"OperatingSystem directoryNameOf:'../../foo/bar'"
|
|
1421 |
!
|
|
1422 |
|
|
1423 |
isValidPath:aPathName
|
|
1424 |
"return true, if 'aPathName' is a valid path name
|
|
1425 |
(i.e. the file or directory exists)"
|
|
1426 |
|
|
1427 |
%{ /* NOCONTEXT */
|
|
1428 |
|
|
1429 |
struct stat buf;
|
10
|
1430 |
int ret;
|
|
1431 |
extern errno;
|
1
|
1432 |
|
|
1433 |
if (_isString(aPathName)) {
|
17
|
1434 |
do {
|
10
|
1435 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
17
|
1436 |
} while (ret < 0 && errno == EINTR);
|
10
|
1437 |
RETURN ( ret ? false : true );
|
1
|
1438 |
}
|
|
1439 |
%}
|
|
1440 |
.
|
|
1441 |
self primitiveFailed
|
|
1442 |
!
|
|
1443 |
|
|
1444 |
isDirectory:aPathName
|
|
1445 |
"return true, if 'aPathName' is a valid directory path name.
|
|
1446 |
(i.e. exists and is a directory)"
|
|
1447 |
|
|
1448 |
%{ /* NOCONTEXT */
|
|
1449 |
|
|
1450 |
struct stat buf;
|
10
|
1451 |
int ret;
|
|
1452 |
extern errno;
|
1
|
1453 |
|
|
1454 |
if (_isString(aPathName)) {
|
17
|
1455 |
do {
|
10
|
1456 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
17
|
1457 |
} while (ret < 0 && errno == EINTR);
|
10
|
1458 |
if ((ret < 0) || ((buf.st_mode & S_IFMT) != S_IFDIR)) {
|
1
|
1459 |
RETURN ( false );
|
|
1460 |
}
|
|
1461 |
RETURN ( true );
|
|
1462 |
}
|
|
1463 |
%}
|
|
1464 |
.
|
|
1465 |
self primitiveFailed
|
|
1466 |
!
|
|
1467 |
|
|
1468 |
isReadable:aPathName
|
|
1469 |
"return true, if the file/dir 'aPathName' is readable."
|
|
1470 |
|
|
1471 |
%{ /* NOCONTEXT */
|
|
1472 |
|
|
1473 |
extern OBJ ErrorNumber;
|
|
1474 |
|
|
1475 |
if (_isString(aPathName)) {
|
|
1476 |
if (access(_stringVal(aPathName), R_OK) == 0) {
|
|
1477 |
RETURN ( true );
|
|
1478 |
}
|
|
1479 |
ErrorNumber = _MKSMALLINT(errno);
|
|
1480 |
RETURN ( false );
|
|
1481 |
}
|
|
1482 |
%}
|
|
1483 |
.
|
|
1484 |
self primitiveFailed
|
|
1485 |
!
|
|
1486 |
|
|
1487 |
isWritable:aPathName
|
|
1488 |
"return true, if the given file is writable"
|
|
1489 |
|
|
1490 |
%{ /* NOCONTEXT */
|
|
1491 |
|
|
1492 |
extern OBJ ErrorNumber;
|
|
1493 |
|
|
1494 |
if (_isString(aPathName)) {
|
|
1495 |
if (access(_stringVal(aPathName), W_OK) == 0) {
|
|
1496 |
RETURN ( true );
|
|
1497 |
}
|
|
1498 |
ErrorNumber = _MKSMALLINT(errno);
|
|
1499 |
RETURN ( false );
|
|
1500 |
}
|
|
1501 |
%}
|
|
1502 |
.
|
|
1503 |
self primitiveFailed
|
|
1504 |
!
|
|
1505 |
|
|
1506 |
isExecutable:aPathName
|
|
1507 |
"return true, if the given file is executable"
|
|
1508 |
|
|
1509 |
%{ /* NOCONTEXT */
|
|
1510 |
|
|
1511 |
extern OBJ ErrorNumber;
|
|
1512 |
|
|
1513 |
if (_isString(aPathName)) {
|
|
1514 |
if (access(_stringVal(aPathName), X_OK) == 0) {
|
|
1515 |
RETURN ( true );
|
|
1516 |
}
|
|
1517 |
ErrorNumber = _MKSMALLINT(errno);
|
|
1518 |
RETURN ( false );
|
|
1519 |
}
|
|
1520 |
%}
|
|
1521 |
.
|
|
1522 |
self primitiveFailed
|
|
1523 |
!
|
|
1524 |
|
|
1525 |
infoOf:aPathName
|
|
1526 |
"return an dictionary filled with info for the file 'aPathName';
|
|
1527 |
info is: (type->t mode->n uid->u gid->g size->s id->ino).
|
|
1528 |
return nil if such a file does not exist. A dictionary is returned,
|
|
1529 |
since we might need to add more info in the future without affecting
|
|
1530 |
existing applications."
|
|
1531 |
|
2
|
1532 |
|info type mode uid gid size id atimeLow atimeHi mtimeLow mtimeHi|
|
1
|
1533 |
|
|
1534 |
"{ Symbol: directory }"
|
|
1535 |
"{ Symbol: regular }"
|
|
1536 |
"{ Symbol: characterSpecial }"
|
|
1537 |
"{ Symbol: blockSpecial }"
|
|
1538 |
"{ Symbol: fifo }"
|
|
1539 |
"{ Symbol: socket }"
|
|
1540 |
"{ Symbol: symbolicLink }"
|
|
1541 |
"{ Symbol: unknown }"
|
|
1542 |
|
|
1543 |
%{
|
|
1544 |
struct stat buf;
|
10
|
1545 |
int ret;
|
|
1546 |
extern errno;
|
1
|
1547 |
|
|
1548 |
if (_isString(aPathName)) {
|
17
|
1549 |
do {
|
10
|
1550 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
17
|
1551 |
} while (ret < 0 && errno == EINTR);
|
10
|
1552 |
if (ret < 0) {
|
17
|
1553 |
ErrorNumber = _MKSMALLINT(errno);
|
1
|
1554 |
RETURN ( nil );
|
|
1555 |
}
|
|
1556 |
switch (buf.st_mode & S_IFMT) {
|
|
1557 |
case S_IFDIR:
|
|
1558 |
type = _directory;
|
|
1559 |
break;
|
|
1560 |
case S_IFCHR:
|
|
1561 |
type = _characterSpecial;
|
|
1562 |
break;
|
|
1563 |
case S_IFBLK:
|
|
1564 |
type = _blockSpecial;
|
|
1565 |
break;
|
|
1566 |
case S_IFREG:
|
|
1567 |
type = _regular;
|
|
1568 |
break;
|
|
1569 |
#ifdef S_IFLNK
|
|
1570 |
case S_IFLNK:
|
|
1571 |
type = _symbolicLink;
|
|
1572 |
break;
|
|
1573 |
#endif
|
|
1574 |
#ifdef S_IFSOCK
|
|
1575 |
case S_IFSOCK:
|
|
1576 |
type = _socket;
|
|
1577 |
break;
|
|
1578 |
#endif
|
|
1579 |
#ifdef S_IFIFO
|
|
1580 |
case S_IFIFO:
|
|
1581 |
type = _fifo;
|
|
1582 |
break;
|
|
1583 |
#endif
|
|
1584 |
default:
|
|
1585 |
type = _unknown;
|
|
1586 |
break;
|
|
1587 |
}
|
|
1588 |
mode = _MKSMALLINT(buf.st_mode & 0777);
|
|
1589 |
uid = _MKSMALLINT(buf.st_uid);
|
|
1590 |
gid = _MKSMALLINT(buf.st_gid);
|
|
1591 |
size = _MKSMALLINT(buf.st_size);
|
|
1592 |
id = _MKSMALLINT(buf.st_ino);
|
2
|
1593 |
atimeLow = _MKSMALLINT(buf.st_atime & 0xFFFF);
|
|
1594 |
atimeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF);
|
|
1595 |
mtimeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF);
|
|
1596 |
mtimeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF);
|
1
|
1597 |
}
|
|
1598 |
%}
|
|
1599 |
.
|
|
1600 |
mode notNil ifTrue:[
|
|
1601 |
info := IdentityDictionary new.
|
|
1602 |
info at:#type put:type.
|
|
1603 |
info at:#mode put:mode.
|
|
1604 |
info at:#uid put:uid.
|
|
1605 |
info at:#gid put:gid.
|
|
1606 |
info at:#size put:size.
|
|
1607 |
info at:#id put:id.
|
2
|
1608 |
info at:#accessTime put:(Time fromUnixTimeLow:atimeLow and:atimeHi).
|
|
1609 |
info at:#modificationTime put:(Time fromUnixTimeLow:mtimeLow and:mtimeHi).
|
1
|
1610 |
^ info
|
|
1611 |
].
|
|
1612 |
self primitiveFailed
|
|
1613 |
|
|
1614 |
"OperatingSystem infoOf:'/'"
|
|
1615 |
"(OperatingSystem infoOf:'/') at:#uid"
|
|
1616 |
!
|
|
1617 |
|
|
1618 |
accessModeOf:aPathName
|
|
1619 |
"return a number representing access rights rwxrwxrwx for owner,
|
|
1620 |
group and others. return nil if such a file does not exist."
|
|
1621 |
|
|
1622 |
"
|
|
1623 |
this could have been implemented as:
|
|
1624 |
(self infoOf:aPathName) at:#mode
|
|
1625 |
but for huge directory searches the code below is faster
|
|
1626 |
"
|
|
1627 |
|
|
1628 |
%{ /* NOCONTEXT */
|
|
1629 |
|
|
1630 |
struct stat buf;
|
10
|
1631 |
int ret;
|
|
1632 |
extern errno;
|
1
|
1633 |
|
|
1634 |
if (_isString(aPathName)) {
|
17
|
1635 |
do {
|
10
|
1636 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
17
|
1637 |
} while (ret < 0 && errno == EINTR);
|
10
|
1638 |
if (ret < 0) {
|
17
|
1639 |
ErrorNumber = _MKSMALLINT(errno);
|
1
|
1640 |
RETURN ( nil );
|
|
1641 |
}
|
|
1642 |
RETURN ( _MKSMALLINT(buf.st_mode & 0777) );
|
|
1643 |
}
|
|
1644 |
%}
|
|
1645 |
.
|
|
1646 |
self primitiveFailed
|
|
1647 |
|
|
1648 |
"(OperatingSystem accessModeOf:'/') printStringRadix:8"
|
|
1649 |
!
|
|
1650 |
|
|
1651 |
changeAccessModeOf:aPathName to:modeBits
|
|
1652 |
"change the access rights rwxrwxrwx for owner,
|
|
1653 |
group and others of aPathName. return true if changed, false
|
|
1654 |
if such a file does not exist or change was not allowd."
|
|
1655 |
|
|
1656 |
%{ /* NOCONTEXT */
|
|
1657 |
|
|
1658 |
if (_isString(aPathName) && _isSmallInteger(modeBits)) {
|
|
1659 |
RETURN ( (chmod((char *) _stringVal(aPathName), _intVal(modeBits) ) < 0) ?
|
|
1660 |
false : true );
|
|
1661 |
}
|
|
1662 |
%}
|
|
1663 |
.
|
|
1664 |
self primitiveFailed
|
|
1665 |
!
|
|
1666 |
|
|
1667 |
timeOfLastChange:aPathName
|
2
|
1668 |
"return the time, when the file was last changed"
|
1
|
1669 |
|
|
1670 |
|timeLow timeHi|
|
|
1671 |
%{
|
|
1672 |
struct stat buf;
|
10
|
1673 |
int ret;
|
|
1674 |
extern errno;
|
1
|
1675 |
time_t mtime;
|
|
1676 |
|
|
1677 |
if (_isString(aPathName)) {
|
17
|
1678 |
do {
|
10
|
1679 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
17
|
1680 |
} while (ret < 0 && errno == EINTR);
|
10
|
1681 |
if (ret >= 0) {
|
1
|
1682 |
timeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF);
|
|
1683 |
timeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF);
|
|
1684 |
}
|
17
|
1685 |
ErrorNumber = _MKSMALLINT(errno);
|
1
|
1686 |
}
|
|
1687 |
%}
|
|
1688 |
.
|
|
1689 |
timeLow notNil ifTrue:[^ Time fromUnixTimeLow:timeLow and:timeHi].
|
|
1690 |
self primitiveFailed
|
|
1691 |
|
|
1692 |
"OperatingSystem timeOfLastChange:'/'"
|
|
1693 |
!
|
|
1694 |
|
2
|
1695 |
timeOfLastAccess:aPathName
|
|
1696 |
"return the time, when the file was last accessed"
|
|
1697 |
|
|
1698 |
|timeLow timeHi|
|
|
1699 |
%{
|
|
1700 |
struct stat buf;
|
|
1701 |
time_t mtime;
|
10
|
1702 |
int ret;
|
|
1703 |
extern errno;
|
2
|
1704 |
|
|
1705 |
if (_isString(aPathName)) {
|
17
|
1706 |
do {
|
10
|
1707 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
17
|
1708 |
} while (ret < 0 && errno == EINTR);
|
10
|
1709 |
if (ret >= 0) {
|
2
|
1710 |
timeLow = _MKSMALLINT(buf.st_atime & 0xFFFF);
|
|
1711 |
timeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF);
|
|
1712 |
}
|
17
|
1713 |
ErrorNumber = _MKSMALLINT(errno);
|
2
|
1714 |
}
|
|
1715 |
%}
|
|
1716 |
.
|
|
1717 |
timeLow notNil ifTrue:[^ Time fromUnixTimeLow:timeLow and:timeHi].
|
|
1718 |
self primitiveFailed
|
|
1719 |
|
|
1720 |
"OperatingSystem timeOfLastAccess:'/'"
|
|
1721 |
!
|
|
1722 |
|
1
|
1723 |
idOf:aPathName
|
|
1724 |
"return the fileNumber (i.e. inode number) of a file"
|
|
1725 |
|
|
1726 |
"
|
|
1727 |
this could have been implemented as:
|
|
1728 |
(self infoOf:aPathName) at:#id
|
|
1729 |
but for huge directory searches the code below is faster
|
|
1730 |
"
|
|
1731 |
|
|
1732 |
%{ /* NOCONTEXT */
|
|
1733 |
|
|
1734 |
struct stat buf;
|
10
|
1735 |
int ret;
|
|
1736 |
extern errno;
|
1
|
1737 |
|
|
1738 |
if (_isString(aPathName)) {
|
17
|
1739 |
do {
|
10
|
1740 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
17
|
1741 |
} while (ret < 0 && errno == EINTR);
|
10
|
1742 |
if (ret >= 0) {
|
1
|
1743 |
RETURN (_MKSMALLINT(buf.st_ino));
|
|
1744 |
}
|
17
|
1745 |
ErrorNumber = _MKSMALLINT(errno);
|
1
|
1746 |
}
|
|
1747 |
%}
|
|
1748 |
.
|
|
1749 |
self primitiveFailed
|
|
1750 |
|
|
1751 |
"OperatingSystem idOf:'/'"
|
|
1752 |
!
|
|
1753 |
|
|
1754 |
typeOf:aPathName
|
|
1755 |
"return the type of a file as a symbol"
|
|
1756 |
|
|
1757 |
"
|
|
1758 |
this could have been implemented as:
|
|
1759 |
(self infoOf:aPathName) at:#type
|
|
1760 |
but for huge directory searches the code below is faster
|
|
1761 |
"
|
|
1762 |
|
|
1763 |
%{ /* NOCONTEXT */
|
|
1764 |
|
|
1765 |
struct stat buf;
|
10
|
1766 |
int ret;
|
|
1767 |
extern errno;
|
1
|
1768 |
|
|
1769 |
if (_isString(aPathName)) {
|
17
|
1770 |
do {
|
10
|
1771 |
ret = stat((char *) _stringVal(aPathName), &buf);
|
17
|
1772 |
} while (ret < 0 && errno == EINTR);
|
10
|
1773 |
if (ret < 0) {
|
17
|
1774 |
ErrorNumber = _MKSMALLINT(errno);
|
1
|
1775 |
RETURN ( nil );
|
|
1776 |
}
|
|
1777 |
switch (buf.st_mode & S_IFMT) {
|
|
1778 |
case S_IFDIR:
|
|
1779 |
RETURN ( _directory );
|
|
1780 |
case S_IFCHR:
|
|
1781 |
RETURN ( _characterSpecial );
|
|
1782 |
case S_IFBLK:
|
|
1783 |
RETURN ( _blockSpecial );
|
|
1784 |
case S_IFREG:
|
|
1785 |
RETURN ( _regular );
|
|
1786 |
#ifdef S_IFLNK
|
|
1787 |
case S_IFLNK:
|
|
1788 |
RETURN ( _symbolicLink );
|
|
1789 |
#endif
|
|
1790 |
#ifdef S_IFSOCK
|
|
1791 |
case S_IFSOCK:
|
|
1792 |
RETURN ( _socket );
|
|
1793 |
#endif
|
|
1794 |
#ifdef S_IFIFO
|
|
1795 |
case S_IFIFO:
|
|
1796 |
RETURN ( _fifo );
|
|
1797 |
#endif
|
|
1798 |
default:
|
|
1799 |
RETURN ( _unknown );
|
|
1800 |
}
|
|
1801 |
}
|
|
1802 |
%}
|
|
1803 |
.
|
|
1804 |
self primitiveFailed
|
|
1805 |
|
|
1806 |
"OperatingSystem typeOf:'/'"
|
|
1807 |
!
|
|
1808 |
|
|
1809 |
createDirectory:newPathName
|
|
1810 |
"create a new directory with name 'newPathName'.
|
|
1811 |
Return true if successful, false if failed."
|
|
1812 |
|
|
1813 |
"since createDirectory is not used too often,
|
|
1814 |
you'll forgive me using mkdir ..."
|
|
1815 |
|
|
1816 |
^ self executeCommand:('mkdir ' , newPathName)
|
|
1817 |
|
|
1818 |
"OperatingSystem createDirectory:'foo'"
|
|
1819 |
!
|
|
1820 |
|
|
1821 |
recursiveCreateDirectory:dirName
|
|
1822 |
"create a directory - with all parent dirs if needed.
|
|
1823 |
Return true if successful, false otherwise. If false
|
|
1824 |
is returned, a partial created tree may be left,
|
|
1825 |
which is not cleaned-up here."
|
|
1826 |
|
|
1827 |
self createDirectory:dirName.
|
|
1828 |
(self isDirectory:dirName) ifFalse:[
|
|
1829 |
(self recursiveCreateDirectory:(self directoryNameOf:dirName)) ifFalse:[^ false].
|
|
1830 |
^ self createDirectory:dirName
|
|
1831 |
].
|
|
1832 |
^ (self isDirectory:dirName)
|
|
1833 |
|
|
1834 |
"OperatingSystem recursiveCreateDirectory:'foo/bar/baz'"
|
|
1835 |
!
|
|
1836 |
|
|
1837 |
removeFile:fullPathName
|
|
1838 |
"remove the file named 'fullPathName'; return true if successful"
|
|
1839 |
|
|
1840 |
%{ /* NOCONTEXT */
|
|
1841 |
|
|
1842 |
if (_isString(fullPathName)) {
|
|
1843 |
RETURN ( (unlink((char *) _stringVal(fullPathName)) >= 0) ? true : false );
|
|
1844 |
}
|
|
1845 |
%}
|
|
1846 |
.
|
|
1847 |
self primitiveFailed
|
|
1848 |
!
|
|
1849 |
|
|
1850 |
removeDirectory:fullPathName
|
|
1851 |
"remove the directory named 'fullPathName'.
|
|
1852 |
Return true if successful, false if directory is not empty or no permission"
|
|
1853 |
|
|
1854 |
%{ /* NOCONTEXT */
|
|
1855 |
|
|
1856 |
if (_isString(fullPathName)) {
|
|
1857 |
RETURN ( (rmdir((char *) _stringVal(fullPathName)) >= 0) ? true : false );
|
|
1858 |
}
|
|
1859 |
%}
|
|
1860 |
.
|
|
1861 |
self primitiveFailed
|
|
1862 |
!
|
|
1863 |
|
18
|
1864 |
recursiveRemoveDirectory:fullPathName
|
|
1865 |
"remove the directory named 'fullPathName' and all contained files/directories.
|
|
1866 |
Return true if successful."
|
|
1867 |
|
|
1868 |
^ self executeCommand:('rm -rf ' , fullPathName)
|
|
1869 |
!
|
|
1870 |
|
1
|
1871 |
link:oldPath to:newPath
|
|
1872 |
"link the file 'oldPath' to 'newPath'. The link will be a hard link.
|
|
1873 |
Return true if successful, false if not."
|
|
1874 |
|
|
1875 |
%{ /* NOCONTEXT */
|
|
1876 |
|
|
1877 |
if (_isString(oldPath) && _isString(newPath)) {
|
|
1878 |
RETURN ( (link((char *) _stringVal(oldPath), (char *) _stringVal(newPath)) >= 0) ?
|
|
1879 |
true : false );
|
|
1880 |
}
|
|
1881 |
%}
|
|
1882 |
.
|
|
1883 |
self primitiveFailed
|
|
1884 |
|
|
1885 |
"OperatingSystem link:'foo' to:'bar'"
|
|
1886 |
!
|
|
1887 |
|
|
1888 |
rename:oldPath to:newPath
|
|
1889 |
"rename the file 'oldPath' to 'newPath'.
|
|
1890 |
Return true if sucessfull, false if not"
|
|
1891 |
|
|
1892 |
%{ /* NOCONTEXT */
|
|
1893 |
|
|
1894 |
if (_isString(oldPath) && _isString(newPath)) {
|
|
1895 |
#if defined(BSD)
|
|
1896 |
if (rename((char *) _stringVal(oldPath), (char *) _stringVal(newPath)) >= 0) {
|
|
1897 |
RETURN ( true );
|
|
1898 |
}
|
|
1899 |
#else
|
|
1900 |
if (link((char *) _stringVal(oldPath), (char *) _stringVal(newPath)) >= 0) {
|
|
1901 |
if (unlink((char *) _stringVal(oldPath)) >= 0) {
|
|
1902 |
RETURN ( true );
|
|
1903 |
}
|
|
1904 |
unlink((char *) _stringVal(newPath));
|
|
1905 |
}
|
|
1906 |
#endif
|
|
1907 |
RETURN ( false );
|
|
1908 |
}
|
|
1909 |
%}
|
|
1910 |
.
|
|
1911 |
self primitiveFailed
|
|
1912 |
|
|
1913 |
"OperatingSystem rename:'foo' to:'bar'"
|
|
1914 |
! !
|