269 extern errno; |
269 extern errno; |
270 |
270 |
271 if (_INST(filePointer) == nil) { |
271 if (_INST(filePointer) == nil) { |
272 path = _INST(pathName); |
272 path = _INST(pathName); |
273 if (path != nil |
273 if (path != nil |
274 && ((_qClass(path)==String) || (_qClass(path) == Filename))) { |
274 && ((_qClass(path)==String) || (_qClass(path) == Filename))) { |
275 do { |
275 do { |
|
276 #ifdef LINUX |
|
277 /* LINUX returns a non-NULL f even when interrupted */ |
|
278 errno = 0; |
276 f = (FILE *)fopen((char *) _stringVal(path), (char *) _stringVal(openmode)); |
279 f = (FILE *)fopen((char *) _stringVal(path), (char *) _stringVal(openmode)); |
277 } while ((f == NULL) && (errno == EINTR)); |
280 if (errno == EINTR) |
|
281 f = NULL; |
|
282 #else |
|
283 |
|
284 f = (FILE *)fopen((char *) _stringVal(path), (char *) _stringVal(openmode)); |
|
285 #endif |
|
286 } while ((f == NULL) && (errno == EINTR)); |
278 if (f == NULL) { |
287 if (f == NULL) { |
279 ErrorNumber = _MKSMALLINT(errno); |
288 ErrorNumber = _MKSMALLINT(errno); |
280 _INST(position) = nil; |
289 _INST(position) = nil; |
281 } else { |
290 } else { |
282 _INST(filePointer) = _MKSMALLINT((int)f); |
291 _INST(filePointer) = _MKSMALLINT((int)f); |
340 "sent after snapin to reopen streams" |
349 "sent after snapin to reopen streams" |
341 |
350 |
342 filePointer notNil ifTrue:[ |
351 filePointer notNil ifTrue:[ |
343 "it was open, when snapped-out" |
352 "it was open, when snapped-out" |
344 filePointer := nil. |
353 filePointer := nil. |
|
354 lobby unregister:self. |
345 self open. |
355 self open. |
346 filePointer isNil ifTrue:[ |
356 filePointer isNil ifTrue:[ |
|
357 "this happens, if after a restart, the file is no longer accessable ..." |
|
358 |
347 ('could not reopen file: ', pathName) printNewline. |
359 ('could not reopen file: ', pathName) printNewline. |
348 lobby unregister:self |
|
349 ] ifFalse:[ |
360 ] ifFalse:[ |
350 self position:position. |
361 self position:position. |
351 lobby changed:self |
|
352 ] |
362 ] |
353 ] |
363 ] |
354 ! |
364 ! |
355 |
365 |
356 size |
366 size |
375 extern errno; |
385 extern errno; |
376 extern OBJ ErrorNumber; |
386 extern OBJ ErrorNumber; |
377 |
387 |
378 if (_INST(filePointer) != nil) { |
388 if (_INST(filePointer) != nil) { |
379 f = (FILE *)_intVal(_INST(filePointer)); |
389 f = (FILE *)_intVal(_INST(filePointer)); |
380 do { |
390 do { |
381 ret = fstat(fileno(f), &buf); |
391 ret = fstat(fileno(f), &buf); |
382 } while ((ret < 0) && (errno == EINTR)); |
392 } while ((ret < 0) && (errno == EINTR)); |
383 if (ret >= 0) { |
393 if (ret >= 0) { |
384 RETURN ( _MKSMALLINT(buf.st_size) ); |
394 RETURN ( _MKSMALLINT(buf.st_size) ); |
385 } |
395 } |
386 ErrorNumber = _MKSMALLINT(errno); |
396 ErrorNumber = _MKSMALLINT(errno); |
387 } |
397 } |
388 #endif |
398 #endif |
389 %} |
399 %} |
390 . |
400 . |
391 "could add a fall-back here: |
401 "could add a fall-back here: |
411 extern errno; |
421 extern errno; |
412 extern OBJ ErrorNumber; |
422 extern OBJ ErrorNumber; |
413 |
423 |
414 if (_INST(filePointer) != nil) { |
424 if (_INST(filePointer) != nil) { |
415 f = (FILE *)_intVal(_INST(filePointer)); |
425 f = (FILE *)_intVal(_INST(filePointer)); |
416 do { |
426 do { |
417 if (_INST(buffered) == true) { |
427 if (_INST(buffered) == true) { |
418 currentPosition = ftell(f); |
428 currentPosition = ftell(f); |
419 } else { |
429 } else { |
420 currentPosition = (long)lseek(fileno(f), SEEK_CUR, 0); |
430 currentPosition = (long)lseek(fileno(f), SEEK_CUR, 0); |
421 } |
431 } |
422 } while ((currentPosition < 0) && (errno == EINTR)); |
432 } while ((currentPosition < 0) && (errno == EINTR)); |
423 if (currentPosition >= 0) { |
433 if (currentPosition >= 0) { |
424 /* |
434 /* |
425 * notice: Smalltalk index starts at 1 |
435 * notice: Smalltalk index starts at 1 |
426 */ |
436 */ |
427 RETURN ( _MKSMALLINT(currentPosition + 1) ); |
437 RETURN ( _MKSMALLINT(currentPosition + 1) ); |
428 } |
438 } |
429 ErrorNumber = _MKSMALLINT(errno); |
439 ErrorNumber = _MKSMALLINT(errno); |
430 } |
440 } |
431 %} |
441 %} |
432 . |
442 . |
433 filePointer isNil ifTrue:[^ self errorNotOpen]. |
443 filePointer isNil ifTrue:[^ self errorNotOpen]. |
434 ^ self primitiveFailed |
444 ^ self primitiveFailed |
448 if (_isSmallInteger(newPos)) { |
458 if (_isSmallInteger(newPos)) { |
449 f = (FILE *)_intVal(_INST(filePointer)); |
459 f = (FILE *)_intVal(_INST(filePointer)); |
450 /* |
460 /* |
451 * notice: Smalltalk index starts at 1 |
461 * notice: Smalltalk index starts at 1 |
452 */ |
462 */ |
453 do { |
463 do { |
454 if (_INST(buffered) == true) { |
464 if (_INST(buffered) == true) { |
455 ret = fseek(f, _intVal(newPos) - 1, 0); |
465 ret = fseek(f, _intVal(newPos) - 1, 0); |
456 } else { |
466 } else { |
457 ret = lseek(fileno(f), (long)_intVal(newPos) - 1, SEEK_SET); |
467 ret = lseek(fileno(f), (long)_intVal(newPos) - 1, SEEK_SET); |
458 } |
468 } |
459 } while ((ret < 0) && (errno == EINTR)); |
469 } while ((ret < 0) && (errno == EINTR)); |
460 if (ret >= 0) { |
470 if (ret >= 0) { |
461 _INST(position) = newPos; |
471 _INST(position) = newPos; |
462 RETURN ( self ); |
472 RETURN ( self ); |
463 } |
473 } |
464 ErrorNumber = _MKSMALLINT(errno); |
474 ErrorNumber = _MKSMALLINT(errno); |