Differences From Artifact [aa73e544ea]:
- File src/OFTarArchiveEntry.m — part of check-in [c7f0229795] at 2020-01-02 01:51:34 on branch trunk — Update copyright (user: js, size: 7989) [annotate] [blame] [check-ins using] [more...]
To Artifact [5e09222260]:
- File
src/OFTarArchiveEntry.m
— part of check-in
[25c985fec1]
at
2020-08-25 00:11:24
on branch trunk
— OFNumber: Remove (u)int{8,16,32,64} methods
Since C guarantees minimum sizes for char, short, int, long and long
long, these can be used instead. (user: js, size: 8110) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
49 50 51 52 53 54 55 | memcpy(buffer, [string cStringWithEncoding: encoding], cStringLength); for (size_t i = cStringLength; i < length; i++) buffer[i] = '\0'; } | | | > | | | | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | memcpy(buffer, [string cStringWithEncoding: encoding], cStringLength); for (size_t i = cStringLength; i < length; i++) buffer[i] = '\0'; } static unsigned long long octalValueFromBuffer(const unsigned char *buffer, size_t length, unsigned long long max) { unsigned long long value = 0; if (length == 0) return 0; if (buffer[0] == 0x80) { for (size_t i = 1; i < length; i++) value = (value << 8) | buffer[i]; } else value = [stringFromBuffer(buffer, length, OF_STRING_ENCODING_ASCII) unsignedLongLongValueWithBase: 8]; if (value > max) @throw [OFOutOfRangeException exception]; return value; } |
︙ | ︙ | |||
91 92 93 94 95 96 97 | self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *targetFileName; _fileName = [stringFromBuffer(header, 100, encoding) copy]; | | | | | | | | | | | | | | | 92 93 94 95 96 97 98 99 100 101 102 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 | self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *targetFileName; _fileName = [stringFromBuffer(header, 100, encoding) copy]; _mode = (unsigned long)octalValueFromBuffer( header + 100, 8, ULONG_MAX); _UID = (unsigned long)octalValueFromBuffer( header + 108, 8, ULONG_MAX); _GID = (unsigned long)octalValueFromBuffer( header + 116, 8, ULONG_MAX); _size = (unsigned long long)octalValueFromBuffer( header + 124, 12, ULLONG_MAX); _modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: (of_time_interval_t)octalValueFromBuffer( header + 136, 12, ULLONG_MAX)]; _type = header[156]; targetFileName = stringFromBuffer(header + 157, 100, encoding); if (targetFileName.length > 0) _targetFileName = [targetFileName copy]; if (_type == '\0') _type = OF_TAR_ARCHIVE_ENTRY_TYPE_FILE; if (memcmp(header + 257, "ustar\0" "00", 8) == 0) { OFString *prefix; _owner = [stringFromBuffer(header + 265, 32, encoding) copy]; _group = [stringFromBuffer(header + 297, 32, encoding) copy]; _deviceMajor = (unsigned long)octalValueFromBuffer( header + 329, 8, ULONG_MAX); _deviceMinor = (unsigned long)octalValueFromBuffer( header + 337, 8, ULONG_MAX); prefix = stringFromBuffer(header + 345, 155, encoding); if (prefix.length > 0) { OFString *fileName = [OFString stringWithFormat: @"%@/%@", prefix, _fileName]; [_fileName release]; |
︙ | ︙ | |||
204 205 206 207 208 209 210 | } - (OFString *)fileName { return _fileName; } | | | | | | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | } - (OFString *)fileName { return _fileName; } - (unsigned long)mode { return _mode; } - (unsigned long)UID { return _UID; } - (unsigned long)GID { return _GID; } - (unsigned long long)size { return _size; } - (OFDate *)modificationDate { return _modificationDate; |
︙ | ︙ | |||
249 250 251 252 253 254 255 | } - (OFString *)group { return _group; } | | | | 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | } - (OFString *)group { return _group; } - (unsigned long)deviceMajor { return _deviceMajor; } - (unsigned long)deviceMinor { return _deviceMinor; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); |
︙ | ︙ | |||
290 291 292 293 294 295 296 | return [ret autorelease]; } - (void)of_writeToStream: (OFStream *)stream encoding: (of_string_encoding_t)encoding { unsigned char buffer[512]; | | | | 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | return [ret autorelease]; } - (void)of_writeToStream: (OFStream *)stream encoding: (of_string_encoding_t)encoding { unsigned char buffer[512]; unsigned long long modificationDate; uint16_t checksum = 0; stringToBuffer(buffer, _fileName, 100, encoding); stringToBuffer(buffer + 100, [OFString stringWithFormat: @"%06" PRIo16 " ", _mode], 8, OF_STRING_ENCODING_ASCII); stringToBuffer(buffer + 108, [OFString stringWithFormat: @"%06" PRIo16 " ", _UID], 8, OF_STRING_ENCODING_ASCII); stringToBuffer(buffer + 116, [OFString stringWithFormat: @"%06" PRIo16 " ", _GID], 8, OF_STRING_ENCODING_ASCII); stringToBuffer(buffer + 124, [OFString stringWithFormat: @"%011" PRIo64 " ", _size], 12, OF_STRING_ENCODING_ASCII); modificationDate = _modificationDate.timeIntervalSince1970; stringToBuffer(buffer + 136, [OFString stringWithFormat: @"%011llo", modificationDate], 12, OF_STRING_ENCODING_ASCII); /* * During checksumming, the checksum field is expected to be set to 8 * spaces. */ memset(buffer + 148, ' ', 8); |
︙ | ︙ |