632 currentPosition = ftell(f); |
643 currentPosition = ftell(f); |
633 } else { |
644 } else { |
634 currentPosition = lseek(fileno(f), 0L, SEEK_CUR); |
645 currentPosition = lseek(fileno(f), 0L, SEEK_CUR); |
635 } |
646 } |
636 #endif |
647 #endif |
637 } while ((currentPosition < 0) && (errno == EINTR)); |
648 } while ((currentPosition < 0) && (__threadErrno == EINTR)); |
638 if (currentPosition >= 0) { |
649 if (currentPosition >= 0) { |
639 /* |
650 /* |
640 * notice: Smalltalk index starts at 1 |
651 * notice: Smalltalk index starts at 1 |
641 */ |
652 */ |
642 RETURN ( __MKSMALLINT(currentPosition + 1) ); |
653 RETURN ( __MKSMALLINT(currentPosition + 1) ); |
643 } |
654 } |
644 __INST(lastErrorNumber) = __MKSMALLINT(errno); |
655 __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
645 } |
656 } |
646 %}. |
657 %}. |
647 lastErrorNumber notNil ifTrue:[^ self ioError]. |
658 lastErrorNumber notNil ifTrue:[^ self ioError]. |
648 filePointer isNil ifTrue:[^ self errorNotOpen]. |
659 filePointer isNil ifTrue:[^ self errorNotOpen]. |
649 ^ self primitiveFailed |
660 ^ self primitiveFailed |
679 ret = fseek(f, nP, SEEK_SET); |
690 ret = fseek(f, nP, SEEK_SET); |
680 } else { |
691 } else { |
681 ret = lseek(fileno(f), nP, SEEK_SET); |
692 ret = lseek(fileno(f), nP, SEEK_SET); |
682 } |
693 } |
683 #endif |
694 #endif |
684 } while ((ret < 0) && (errno == EINTR)); |
695 } while ((ret < 0) && (__threadErrno == EINTR)); |
685 if (ret >= 0) { |
696 if (ret >= 0) { |
686 __INST(position) = newPos; |
697 __INST(position) = newPos; |
687 /* |
698 /* |
688 * just to make certain ... |
699 * just to make certain ... |
689 */ |
700 */ |
690 __INST(hitEOF) = false; |
701 __INST(hitEOF) = false; |
691 RETURN ( self ); |
702 RETURN ( self ); |
692 } |
703 } |
693 __INST(lastErrorNumber) = __MKSMALLINT(errno); |
704 __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
694 } |
705 } |
695 } |
706 } |
696 } |
707 } |
697 %}. |
708 %}. |
698 canPosition == false ifTrue:[ |
709 canPosition == false ifTrue:[ |
730 ret = fseek(f, 0L, SEEK_END); |
741 ret = fseek(f, 0L, SEEK_END); |
731 } else { |
742 } else { |
732 ret = lseek(fileno(f), 0L, SEEK_END); |
743 ret = lseek(fileno(f), 0L, SEEK_END); |
733 } |
744 } |
734 #endif |
745 #endif |
735 } while ((ret < 0) && (errno == EINTR)); |
746 } while ((ret < 0) && (__threadErrno == EINTR)); |
736 if (ret >= 0) { |
747 if (ret >= 0) { |
737 RETURN ( self ); |
748 RETURN ( self ); |
738 } |
749 } |
739 __INST(lastErrorNumber) = __MKSMALLINT(errno); |
750 __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
740 } |
751 } |
741 %}. |
752 %}. |
742 lastErrorNumber notNil ifTrue:[^ self ioError]. |
753 lastErrorNumber notNil ifTrue:[^ self ioError]. |
743 filePointer isNil ifTrue:[^ self errorNotOpen]. |
754 filePointer isNil ifTrue:[^ self errorNotOpen]. |
744 ^ self primitiveFailed |
755 ^ self primitiveFailed |
1053 f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
1064 f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
1054 __END_INTERRUPTABLE__ |
1065 __END_INTERRUPTABLE__ |
1055 # endif /* use_STDIO */ |
1066 # endif /* use_STDIO */ |
1056 /* must refetch - could be GC'd */ |
1067 /* must refetch - could be GC'd */ |
1057 path = __INST(pathName); |
1068 path = __INST(pathName); |
1058 } while ((f == NULL) && (errno == EINTR)); |
1069 } while ((f == NULL) && (__threadErrno == EINTR)); |
1059 |
1070 |
1060 # else /* not WIN32 */ |
1071 # else /* not WIN32 */ |
1061 |
1072 |
1062 do { |
1073 do { |
1063 __BEGIN_INTERRUPTABLE__ |
1074 __BEGIN_INTERRUPTABLE__ |
1064 # ifdef LINUX |
1075 # ifdef LINUX |
1065 /* |
1076 /* |
1066 * LINUX may ret a non-NULL f even when interrupted. |
1077 * LINUX may ret a non-NULL f even when interrupted. |
1067 * Therefore, check errno and fake a null-ret. |
1078 * Therefore, check errno and fake a null-ret. |
1068 */ |
1079 */ |
1069 errno = 0; |
1080 __threadErrno = 0; |
1070 f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
1081 f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
1071 if (errno == EINTR) |
1082 if (__threadErrno == EINTR) |
1072 f = NULL; |
1083 f = NULL; |
1073 # else /* not LINUX */ |
1084 # else /* not LINUX */ |
1074 f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
1085 f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
1075 # endif /* not LINUX */ |
1086 # endif /* not LINUX */ |
1076 __END_INTERRUPTABLE__ |
1087 __END_INTERRUPTABLE__ |
1077 /* must refetch - could be GC'd */ |
1088 /* must refetch - could be GC'd */ |
1078 path = __INST(pathName); |
1089 path = __INST(pathName); |
1079 } while ((f == NULL) && (errno == EINTR)); |
1090 } while ((f == NULL) && (__threadErrno == EINTR)); |
1080 |
1091 |
1081 # endif /* not WIN32 */ |
1092 # endif /* not WIN32 */ |
1082 #endif /* not VMS */ |
1093 #endif /* not VMS */ |
1083 |
1094 |
1084 if (f == NULL) { |
1095 if (f == NULL) { |
1085 /* |
1096 /* |
1086 * If no filedescriptors available, try to finalize |
1097 * If no filedescriptors available, try to finalize |
1087 * possibly collected fd's and try again. |
1098 * possibly collected fd's and try again. |
1088 */ |
1099 */ |
1089 if (pass == 0 && (errno == ENFILE || errno == EMFILE)) { |
1100 if (pass == 0 && (__threadErrno == ENFILE || __threadErrno == EMFILE)) { |
1090 pass = 1; |
1101 pass = 1; |
1091 __SSEND0(@global(ObjectMemory), @symbol(scavenge), 0); |
1102 __SSEND0(@global(ObjectMemory), @symbol(scavenge), 0); |
1092 __SSEND0(@global(ObjectMemory), @symbol(finalize), 0); |
1103 __SSEND0(@global(ObjectMemory), @symbol(finalize), 0); |
1093 goto retry; |
1104 goto retry; |
1094 } |
1105 } |
1095 getOutOfHere: ; |
1106 getOutOfHere: ; |
1096 __INST(lastErrorNumber) = __MKSMALLINT(errno); |
1107 __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
1097 __INST(position) = nil; |
1108 __INST(position) = nil; |
1098 } else { |
1109 } else { |
1099 #ifdef __VMS__ |
1110 #ifdef __VMS__ |
1100 /* |
1111 /* |
1101 * check to see if this is positionable ... |
1112 * check to see if this is positionable ... |
1216 if (__INST(filePointer) != nil) { |
1227 if (__INST(filePointer) != nil) { |
1217 f = __FILEVal(__INST(filePointer)); |
1228 f = __FILEVal(__INST(filePointer)); |
1218 fd = fileno(f); |
1229 fd = fileno(f); |
1219 do { |
1230 do { |
1220 ret = fstat(fd, &buf); |
1231 ret = fstat(fd, &buf); |
1221 } while ((ret < 0) && (errno == EINTR)); |
1232 } while ((ret < 0) && (__threadErrno == EINTR)); |
1222 if (ret >= 0) { |
1233 if (ret >= 0) { |
1223 RETURN ( __MKSMALLINT(buf.st_size) ); |
1234 RETURN ( __MKSMALLINT(buf.st_size) ); |
1224 } |
1235 } |
1225 __INST(lastErrorNumber) = __MKSMALLINT(errno); |
1236 __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
1226 } |
1237 } |
1227 #endif |
1238 #endif |
1228 %}. |
1239 %}. |
1229 |
1240 |
1230 "could add a fall-back here: |
1241 "could add a fall-back here: |