419 ! |
419 ! |
420 |
420 |
421 openWithMode:openmode |
421 openWithMode:openmode |
422 "open the file; openmode is the string defining the way to open" |
422 "open the file; openmode is the string defining the way to open" |
423 |
423 |
424 |retVal| |
424 |retVal laspass| |
425 |
425 |
426 filePointer notNil ifTrue:[^ self errorOpen]. |
426 filePointer notNil ifTrue:[^ self errorOpen]. |
427 %{ |
427 %{ |
428 FILE *f; |
428 FILE *f; |
429 OBJ path, fp; |
429 OBJ path, fp; |
430 |
430 int pass = 0; |
|
431 |
|
432 retry: |
431 path = __INST(pathName); |
433 path = __INST(pathName); |
432 if (__isNonNilObject(path) && (__qClass(path)==String)) { |
434 if (__isNonNilObject(path) && (__qClass(path)==String)) { |
433 __BEGIN_INTERRUPTABLE__ |
435 __BEGIN_INTERRUPTABLE__ |
434 do { |
436 do { |
435 #ifdef LINUX |
437 #ifdef LINUX |
436 /* LINUX returns a non-NULL f even when interrupted */ |
438 /* LINUX returns a non-NULL f even when interrupted */ |
437 errno = 0; |
439 errno = 0; |
438 f = (FILE *) fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
440 f = (FILE *) fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
439 if (errno == EINTR) |
441 if (errno == EINTR) |
440 f = NULL; |
442 f = NULL; |
441 #else |
443 #else |
442 |
444 |
443 f = (FILE *) fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
445 f = (FILE *) fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
444 #endif |
446 #endif |
445 } while ((f == NULL) && (errno == EINTR)); |
447 } while ((f == NULL) && (errno == EINTR)); |
446 __END_INTERRUPTABLE__ |
448 __END_INTERRUPTABLE__ |
447 if (f == NULL) { |
449 if (f == NULL) { |
448 __INST(lastErrorNumber) = __MKSMALLINT(errno); |
450 /* |
449 __INST(position) = nil; |
451 * If no filedescriptors available, try to finalize |
450 } else { |
452 * possibly collected fd's and try again. |
451 __INST(filePointer) = fp = __MKOBJ((int)f); __STORE(self, fp); |
453 */ |
452 __INST(position) = __MKSMALLINT(1); |
454 |
453 retVal = self; |
455 if (pass == 0 && (errno == ENFILE || errno == EMFILE)) { |
454 } |
456 pass = 1; |
|
457 %}. |
|
458 ObjectMemory scavenge; finalize. |
|
459 %{ |
|
460 goto retry; |
|
461 } |
|
462 __INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
463 __INST(position) = nil; |
|
464 } else { |
|
465 __INST(filePointer) = fp = __MKOBJ((int)f); __STORE(self, fp); |
|
466 __INST(position) = __MKSMALLINT(1); |
|
467 retVal = self; |
|
468 } |
455 } |
469 } |
456 %}. |
470 %}. |
457 retVal notNil ifTrue:[ |
471 retVal notNil ifTrue:[ |
458 buffered := true. "default is buffered" |
472 buffered := true. "default is buffered" |
459 Lobby register:self |
473 Lobby register:self. |
|
474 ^ retVal |
|
475 ] ifFalse:[ |
|
476 " |
|
477 the open failed for some reason ... |
|
478 " |
|
479 ^ self openError |
460 ]. |
480 ]. |
461 lastErrorNumber notNil ifTrue:[ |
481 |
462 " |
|
463 the open failed for some reason ... |
|
464 " |
|
465 ^ self openError |
|
466 ]. |
|
467 ^ retVal |
|
468 ! |
482 ! |
469 |
483 |
470 pathName:filename |
484 pathName:filename |
471 "set the pathname" |
485 "set the pathname" |
472 |
486 |