663 ! |
663 ! |
664 |
664 |
665 position:newPos |
665 position:newPos |
666 "set the read/write position in the file" |
666 "set the read/write position in the file" |
667 |
667 |
|
668 |rslt| |
668 %{ |
669 %{ |
669 |
670 |
670 HFILE f; |
671 HFILE f; |
671 long ret; |
672 long ret; |
672 OBJ fp; |
673 OBJ fp; |
673 long nP; |
674 long nP; |
674 |
675 |
675 if ((__INST(canPosition) != false) |
676 if ((__INST(canPosition) != false) |
676 || (newPos == __MKSMALLINT(1))) { |
677 || (newPos == __MKSMALLINT(1))) { |
677 if ((fp = __INST(filePointer)) != nil) { |
678 if ((fp = __INST(filePointer)) != nil) { |
678 if (__isSmallInteger(newPos)) { |
679 if (__isSmallInteger(newPos)) { |
679 f = __FILEVal(fp); |
680 f = __FILEVal(fp); |
680 nP = (long)__intVal(newPos); |
681 nP = (long)__intVal(newPos); |
681 |
682 |
682 /* |
683 /* |
683 * notice: Smalltalk index starts at 1 |
684 * notice: Smalltalk index starts at 1 |
684 */ |
685 */ |
685 nP--; |
686 nP--; |
686 |
687 |
687 do { |
688 do { |
688 #ifdef WIN32 |
689 #ifdef WIN32 |
689 SEEK(ret,f,nP,__INST(buffered) == true); |
690 SEEK(ret,f,nP,__INST(buffered) == true); |
690 #else |
691 #else |
691 if (__INST(buffered) == true) { |
692 if (__INST(buffered) == true) { |
692 ret = fseek(f, nP, SEEK_SET); |
693 ret = fseek(f, nP, SEEK_SET); |
693 } else { |
694 } else { |
694 ret = lseek(fileno(f), nP, SEEK_SET); |
695 ret = lseek(fileno(f), nP, SEEK_SET); |
695 } |
696 } |
696 #endif |
697 #endif |
697 } while ((ret < 0) && (__threadErrno == EINTR)); |
698 } while ((ret < 0) && (__threadErrno == EINTR)); |
698 if (ret >= 0) { |
699 if (ret >= 0) { |
699 __INST(position) = newPos; |
700 __INST(position) = newPos; |
700 /* |
701 /* |
701 * just to make certain ... |
702 * just to make certain ... |
702 */ |
703 */ |
703 __INST(hitEOF) = false; |
704 __INST(hitEOF) = false; |
704 RETURN ( self ); |
705 RETURN ( self ); |
705 } |
706 } |
706 __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
707 __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
707 } |
708 } |
708 } |
709 } |
709 } |
710 } |
710 %}. |
711 %}. |
711 canPosition == false ifTrue:[ |
712 canPosition == false ifTrue:[ |
712 "/ position by rewinding & re-reading everything up-to |
713 "/ position by rewinding & re-reading everything up-to |
713 "/ that point. |
714 "/ that point. |
714 ^ self slowPosition:newPos |
715 ^ self slowPosition:newPos |
715 ]. |
716 ]. |
716 lastErrorNumber notNil ifTrue:[ |
717 lastErrorNumber notNil ifTrue:[ |
717 (OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[ |
718 (OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[ |
718 "/ invalid position |
719 "/ invalid position |
719 ^ self positionError |
720 ^ self positionError |
720 ]. |
721 ]. |
721 "/ assume I/O error |
722 "/ assume I/O error |
722 ^ self ioError |
723 ^ self ioError |
723 ]. |
724 ]. |
724 filePointer isNil ifTrue:[^ self errorNotOpen]. |
725 filePointer isNil ifTrue:[^ self errorNotOpen]. |
725 ^ self primitiveFailed |
726 rslt := self positionFile:filePointer position:newPos. |
|
727 rslt >= 0 ifTrue:[ |
|
728 position := newPos. |
|
729 ] ifFalse:[ |
|
730 hitEOF := true. |
|
731 ] |
726 ! |
732 ! |
727 |
733 |
728 setToEnd |
734 setToEnd |
729 "set the read/write position in the file to be at the end of the file" |
735 "set the read/write position in the file to be at the end of the file" |
730 |
736 |
1279 ^ self fileSize. |
1285 ^ self fileSize. |
1280 |
1286 |
1281 "Modified: 4.10.1997 / 18:01:09 / cg" |
1287 "Modified: 4.10.1997 / 18:01:09 / cg" |
1282 ! ! |
1288 ! ! |
1283 |
1289 |
|
1290 !FileStream methodsFor:'rel5 protocol'! |
|
1291 |
|
1292 positionFile:filePointer position:newPos |
|
1293 "for migration to rel5 only" |
|
1294 |
|
1295 self primitiveFailed |
|
1296 |
|
1297 |
|
1298 ! ! |
|
1299 |
1284 !FileStream methodsFor:'testing'! |
1300 !FileStream methodsFor:'testing'! |
1285 |
1301 |
1286 isFileStream |
1302 isFileStream |
1287 "return true, if the receiver is some kind of fileStream. |
1303 "return true, if the receiver is some kind of fileStream. |
1288 redefined from Object" |
1304 redefined from Object" |