33
33
static const size_t FIRCLSStringBufferLength = 16 ;
34
34
const size_t FIRCLSWriteBufferLength = 1000 ;
35
35
36
- static bool FIRCLSFileInit (FIRCLSFile* file, int fdm, bool appendMode, bool bufferWrites);
36
+ static bool FIRCLSFileInit (
37
+ FIRCLSFile* file, const char * path, int fdm, bool appendMode, bool bufferWrites);
37
38
38
39
static void FIRCLSFileWriteToFileDescriptorOrBuffer (FIRCLSFile* file,
39
40
const char * string,
@@ -55,7 +56,8 @@ static void FIRCLSFileWriteToFileDescriptorOrBuffer(FIRCLSFile* file,
55
56
#define CLS_FILE_DEBUG_LOGGING 0
56
57
57
58
#pragma mark - File Structure
58
- static bool FIRCLSFileInit (FIRCLSFile* file, int fd, bool appendMode, bool bufferWrites) {
59
+ static bool FIRCLSFileInit (
60
+ FIRCLSFile* file, const char * path, int fd, bool appendMode, bool bufferWrites) {
59
61
if (!file) {
60
62
FIRCLSSDKLog (" Error: file is null\n " );
61
63
return false ;
@@ -83,9 +85,16 @@ static bool FIRCLSFileInit(FIRCLSFile* file, int fd, bool appendMode, bool buffe
83
85
84
86
file->writtenLength = 0 ;
85
87
if (appendMode) {
86
- struct stat fileStats;
87
- fstat (fd, &fileStats);
88
- off_t currentFileSize = fileStats.st_size ;
88
+ NSError * attributesError;
89
+ NSString * objCPath = [NSString stringWithCString: path encoding: NSUTF8StringEncoding];
90
+ NSDictionary * fileAttributes =
91
+ [[NSFileManager defaultManager ] attributesOfItemAtPath: objCPath error: &attributesError];
92
+ if (attributesError != nil ) {
93
+ FIRCLSErrorLog (@" Failed to read filesize from %@ with error %@ " , objCPath, attributesError);
94
+ return false ;
95
+ }
96
+ NSNumber * fileSizeNumber = [fileAttributes objectForKey: NSFileSize ];
97
+ long long currentFileSize = [fileSizeNumber longLongValue ];
89
98
if (currentFileSize > 0 ) {
90
99
file->writtenLength += currentFileSize;
91
100
}
@@ -133,7 +142,7 @@ bool FIRCLSFileInitWithPathMode(FIRCLSFile* file,
133
142
}
134
143
}
135
144
136
- return FIRCLSFileInit (file, fd, appendMode, bufferWrites);
145
+ return FIRCLSFileInit (file, path, fd, appendMode, bufferWrites);
137
146
}
138
147
139
148
bool FIRCLSFileClose (FIRCLSFile* file) {
0 commit comments