63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#ifdef OF_WINDOWS
# include <windows.h>
# include <direct.h>
# include <ntdef.h>
#endif
#ifdef OF_AMIGAOS
# include <proto/dos.h>
# include <proto/locale.h>
#endif
#if defined(OF_WINDOWS)
typedef struct __stat64 of_stat_t;
#elif defined(OF_AMIGAOS)
typedef struct {
of_offset_t st_size;
|
>
>
>
>
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#ifdef OF_WINDOWS
# include <windows.h>
# include <direct.h>
# include <ntdef.h>
#endif
#ifdef OF_AMIGAOS
# define __USE_INLINE__
# include <proto/dos.h>
# include <proto/locale.h>
# ifdef OF_AMIGAOS4
# define DeleteFile(path) Delete(path)
# endif
#endif
#if defined(OF_WINDOWS)
typedef struct __stat64 of_stat_t;
#elif defined(OF_AMIGAOS)
typedef struct {
of_offset_t st_size;
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
static int
of_stat(OFString *path, of_stat_t *buffer)
{
#if defined(OF_WINDOWS)
return _wstat64([path UTF16String], buffer);
#elif defined(OF_AMIGAOS)
BPTR lock;
struct FileInfoBlock fib;
of_time_interval_t timeInterval;
struct Locale *locale;
if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]],
SHARED_LOCK)) == 0) {
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
case ERROR_DISK_NOT_VALIDATED:
errno = EBUSY;
break;
case ERROR_OBJECT_NOT_FOUND:
errno = ENOENT;
break;
default:
errno = 0;
break;
}
return -1;
}
# ifdef OF_MORPHOS
if (!Examine64(lock, &fib, TAG_DONE)) {
# else
if (!Examine(lock, &fib)) {
# endif
UnLock(lock);
errno = 0;
return -1;
}
UnLock(lock);
# ifdef OF_MORPHOS
buffer->st_size = fib.fib_Size64;
# else
buffer->st_size = fib.fib_Size;
# endif
buffer->st_mode = (fib.fib_DirEntryType > 0 ? S_IFDIR : S_IFREG);
timeInterval = 252460800; /* 1978-01-01 */
locale = OpenLocale(NULL);
/*
* FIXME: This does not take DST into account. But unfortunately, there
* is no way to figure out if DST was in effect when the file was
* modified.
*/
timeInterval += locale->loc_GMTOffset * 60.0;
CloseLocale(locale);
timeInterval += fib.fib_Date.ds_Days * 86400.0;
timeInterval += fib.fib_Date.ds_Minute * 60.0;
timeInterval +=
fib.fib_Date.ds_Tick / (of_time_interval_t)TICKS_PER_SECOND;
buffer->st_atime = buffer->st_mtime = buffer->st_ctime = timeInterval;
return 0;
#elif defined(OF_HAVE_OFF64_T)
return stat64([path cStringWithEncoding: [OFLocale encoding]], buffer);
#else
return stat([path cStringWithEncoding: [OFLocale encoding]], buffer);
#endif
|
>
>
>
>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
|
>
|
|
|
>
>
>
>
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
static int
of_stat(OFString *path, of_stat_t *buffer)
{
#if defined(OF_WINDOWS)
return _wstat64([path UTF16String], buffer);
#elif defined(OF_AMIGAOS)
BPTR lock;
# ifdef OF_AMIGAOS4
struct ExamineData *ed;
# else
struct FileInfoBlock fib;
# endif
of_time_interval_t timeInterval;
struct Locale *locale;
struct DateStamp *date;
if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]],
SHARED_LOCK)) == 0) {
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
case ERROR_DISK_NOT_VALIDATED:
errno = EBUSY;
break;
case ERROR_OBJECT_NOT_FOUND:
errno = ENOENT;
break;
default:
errno = 0;
break;
}
return -1;
}
# if defined(OF_MORPHOS)
if (!Examine64(lock, &fib, TAG_DONE)) {
# elif defined(OF_AMIGAOS4)
if ((ed = ExamineObjectTags(EX_FileLockInput, lock, TAG_END)) == NULL) {
# else
if (!Examine(lock, &fib)) {
# endif
UnLock(lock);
errno = 0;
return -1;
}
UnLock(lock);
# if defined(OF_MORPHOS)
buffer->st_size = fib.fib_Size64;
# elif defined(OF_AMIGAOS4)
buffer->st_size = ed->FileSize;
# else
buffer->st_size = fib.fib_Size;
# endif
# ifdef OF_AMIGAOS4
buffer->st_mode = (EXD_IS_DIRECTORY(ed) ? S_IFDIR : S_IFREG);
# else
buffer->st_mode = (fib.fib_DirEntryType > 0 ? S_IFDIR : S_IFREG);
# endif
timeInterval = 252460800; /* 1978-01-01 */
locale = OpenLocale(NULL);
/*
* FIXME: This does not take DST into account. But unfortunately, there
* is no way to figure out if DST was in effect when the file was
* modified.
*/
timeInterval += locale->loc_GMTOffset * 60.0;
CloseLocale(locale);
# ifdef OF_AMIGAOS4
date = &ed->Date;
# else
date = &fib.fib_Date;
# endif
timeInterval += date->ds_Days * 86400.0;
timeInterval += date->ds_Minute * 60.0;
timeInterval += date->ds_Tick / (of_time_interval_t)TICKS_PER_SECOND;
buffer->st_atime = buffer->st_mtime = buffer->st_ctime = timeInterval;
# ifdef OF_AMIGAOS4
FreeDosObject(DOS_EXAMINEDATA, ed);
# endif
return 0;
#elif defined(OF_HAVE_OFF64_T)
return stat64([path cStringWithEncoding: [OFLocale encoding]], buffer);
#else
return stat([path cStringWithEncoding: [OFLocale encoding]], buffer);
#endif
|
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
|
errNo: EIO];
} @finally {
FindClose(handle);
}
#elif defined(OF_AMIGAOS)
of_string_encoding_t encoding = [OFLocale encoding];
BPTR lock;
struct FileInfoBlock fib;
if ((lock = Lock([path cStringWithEncoding: encoding],
SHARED_LOCK)) == 0) {
int errNo;
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
|
<
|
788
789
790
791
792
793
794
795
796
797
798
799
800
801
|
errNo: EIO];
} @finally {
FindClose(handle);
}
#elif defined(OF_AMIGAOS)
of_string_encoding_t encoding = [OFLocale encoding];
BPTR lock;
if ((lock = Lock([path cStringWithEncoding: encoding],
SHARED_LOCK)) == 0) {
int errNo;
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
|
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
|
@throw [OFOpenItemFailedException exceptionWithURL: URL
mode: nil
errNo: errNo];
}
@try {
if (!Examine(lock, &fib))
@throw [OFOpenItemFailedException
exceptionWithURL: URL
mode: nil
errNo: 0];
while (ExNext(lock, &fib)) {
OFString *file;
file = [[OFString alloc]
initWithCString: fib.fib_FileName
encoding: encoding];
@try {
[files addObject: file];
} @finally {
[file release];
}
}
if (IoErr() != ERROR_NO_MORE_ENTRIES)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: 0
errNo: EIO];
} @finally {
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
<
>
>
|
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
|
@throw [OFOpenItemFailedException exceptionWithURL: URL
mode: nil
errNo: errNo];
}
@try {
# ifdef OF_AMIGAOS4
struct ExamineData *ed;
APTR context;
if ((context = ObtainDirContextTags(EX_FileLockInput, lock,
EX_DoCurrentDir, TRUE, EX_DataFields, EXF_NAME,
TAG_END)) == NULL)
@throw [OFOpenItemFailedException
exceptionWithURL: URL
mode: nil
errNo: 0];
@try {
while ((ed = ExamineDir(context)) != NULL) {
OFString *file = [[OFString alloc]
initWithCString: ed->Name
encoding: encoding];
@try {
[files addObject: file];
} @finally {
[file release];
}
}
} @finally {
ReleaseDirContext(context);
}
# else
struct FileInfoBlock fib;
if (!Examine(lock, &fib))
@throw [OFOpenItemFailedException
exceptionWithURL: URL
mode: nil
errNo: 0];
while (ExNext(lock, &fib)) {
OFString *file = [[OFString alloc]
initWithCString: fib.fib_FileName
encoding: encoding];
@try {
[files addObject: file];
} @finally {
[file release];
}
}
# endif
if (IoErr() != ERROR_NO_MORE_ENTRIES)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: 0
errNo: EIO];
} @finally {
|