ExternalStream.st
changeset 14438 a4280b8038c0
parent 14068 46a8289bf92a
child 14440 88e708da1ae1
equal deleted inserted replaced
14437:3a983b537183 14438:a4280b8038c0
  2436 openError
  2436 openError
  2437     "report an error, that the open failed"
  2437     "report an error, that the open failed"
  2438 
  2438 
  2439     "{ Pragma: +optSpace }"
  2439     "{ Pragma: +optSpace }"
  2440 
  2440 
  2441     |exClass|
  2441     ^ self openError:lastErrorNumber.
  2442 
       
  2443     exClass := (lastErrorNumber == (OperatingSystem errorNumberFor:#ERROR_FILE_NOT_FOUND))
       
  2444 	ifTrue:[ FileDoesNotExistException ]
       
  2445 	ifFalse:[ OpenError ].
       
  2446 
       
  2447     ^ exClass newException
       
  2448 	errorCode:lastErrorNumber;
       
  2449 	errorString:(' : ' , (OperatingSystem errorTextForNumber:lastErrorNumber));
       
  2450 	parameter:self;
       
  2451 	raiseRequest
       
  2452 
       
  2453     "Modified: / 28-01-1998 / 14:37:42 / stefan"
       
  2454     "Modified: / 09-09-2011 / 09:16:40 / cg"
       
  2455 !
  2442 !
  2456 
  2443 
  2457 openError:errorNumber
  2444 openError:errorNumber
  2458     "report an error, that the open failed"
  2445     "report an error, that the open failed"
  2459 
  2446 
  2460     "{ Pragma: +optSpace }"
  2447     "{ Pragma: +optSpace }"
  2461 
  2448 
  2462     |exClass|
  2449     |exClass|
  2463 
  2450 
  2464     exClass := (errorNumber == OperatingSystem errorNumberFor:#ERROR_FILE_NOT_FOUND)
  2451     exClass := (errorNumber == (OperatingSystem errorNumberFor:#ERROR_FILE_NOT_FOUND))
  2465 	ifTrue:[ FileDoesNotExistException ]
  2452         ifTrue:[ FileDoesNotExistException ]
  2466 	ifFalse:[ OpenError ].
  2453         ifFalse:[ OpenError ].
  2467 
  2454 
  2468     ^ exClass newException
  2455     ^ exClass newException
  2469 	errorCode:errorNumber;
  2456         errorCode:errorNumber;
  2470 	errorString:(' : ' , (OperatingSystem errorTextForNumber:errorNumber));
  2457         errorString:(' : ' , (OperatingSystem errorTextForNumber:errorNumber));
  2471 	parameter:self;
  2458         parameter:self;
  2472 	raiseRequest
  2459         raiseRequest
  2473 	"/ in:thisContext sender
  2460         "/ in:thisContext sender
  2474 
  2461 
  2475     "Modified: / 09-09-2011 / 07:22:49 / cg"
  2462     "Modified: / 09-09-2011 / 07:22:49 / cg"
  2476 !
  2463 !
  2477 
  2464 
  2478 readError
  2465 readError
  4443     if (__isStringLike(aPath) && __isStringLike(openModeString)) {
  4430     if (__isStringLike(aPath) && __isStringLike(openModeString)) {
  4444 #ifdef WIN32
  4431 #ifdef WIN32
  4445 # if 1
  4432 # if 1
  4446        f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
  4433        f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
  4447 # else
  4434 # else
  4448 	__BEGIN_INTERRUPTABLE__
  4435         __BEGIN_INTERRUPTABLE__
  4449 	do {
  4436         do {
  4450 	    f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
  4437             f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
  4451 	} while ((f == NULL) && (__threadErrno == EINTR));
  4438         } while ((f == NULL) && (__threadErrno == EINTR));
  4452 	__END_INTERRUPTABLE__
  4439         __END_INTERRUPTABLE__
  4453 # endif
  4440 # endif
  4454 #else /* UNIX */
  4441 #else /* UNIX */
  4455 	__BEGIN_INTERRUPTABLE__
  4442         __BEGIN_INTERRUPTABLE__
  4456 	do {
  4443         do {
  4457 	    f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
  4444             f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
  4458 	} while ((f == NULL) && (__threadErrno == EINTR));
  4445         } while ((f == NULL) && (__threadErrno == EINTR));
  4459 	__END_INTERRUPTABLE__
  4446         __END_INTERRUPTABLE__
  4460 #endif /* UNIX */
  4447 #endif /* UNIX */
  4461 	if (f == NULL) {
  4448         if (f == NULL) {
  4462 	    __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
  4449             __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
  4463 	} else {
  4450         } else {
  4464 	    if (@global(FileOpenTrace) == true) {
  4451             if (@global(FileOpenTrace) == true) {
  4465 		fprintf(stderr, "fopen %s [ExternalStream] -> %x\n", __stringVal(aPath), f);
  4452                 fprintf(stderr, "fopen %s [ExternalStream] -> %x\n", __stringVal(aPath), f);
  4466 	    }
  4453             }
  4467 	    fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
  4454             fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
  4468 	    __INST(handleType) = @symbol(filePointer);
  4455             __INST(handleType) = @symbol(filePointer);
  4469 	    ok = true;
  4456             ok = true;
  4470 	}
  4457         }
  4471     }
  4458     }
  4472 %}.
  4459 %}.
  4473     ok ifFalse:[
  4460     ok ifFalse:[
  4474 	"
  4461         "
  4475 	 the open failed for some reason ...
  4462          the open failed for some reason ...
  4476 	"
  4463         "
  4477 	^ self openError
  4464         ^ self openError:lastErrorNumber.
  4478     ].
  4465     ].
  4479     position := ZeroPosition.
  4466     position := ZeroPosition.
  4480     Lobby register:self.
  4467     Lobby register:self.
  4481 !
  4468 !
  4482 
  4469 
  5704 ! !
  5691 ! !
  5705 
  5692 
  5706 !ExternalStream class methodsFor:'documentation'!
  5693 !ExternalStream class methodsFor:'documentation'!
  5707 
  5694 
  5708 version
  5695 version
  5709     ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.349 2012-03-26 17:02:56 cg Exp $'
  5696     ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.350 2012-10-26 09:55:43 stefan Exp $'
  5710 !
  5697 !
  5711 
  5698 
  5712 version_CVS
  5699 version_CVS
  5713     ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.349 2012-03-26 17:02:56 cg Exp $'
  5700     ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.350 2012-10-26 09:55:43 stefan Exp $'
  5714 ! !
  5701 ! !
  5715 
  5702 
  5716 ExternalStream initialize!
  5703 ExternalStream initialize!