Index: src/OFFileURLHandler.m ================================================================== --- src/OFFileURLHandler.m +++ src/OFFileURLHandler.m @@ -16,10 +16,11 @@ */ #include "config.h" #include +#include #ifdef HAVE_DIRENT_H # include #endif #include "unistd_wrapper.h" @@ -149,10 +150,54 @@ } errno = 0; } #endif + +#ifdef OF_AMIGAOS +static void +setErrno(void) +{ + switch (IoErr()) { + case ERROR_DELETE_PROTECTED: + case ERROR_READ_PROTECTED: + case ERROR_WRITE_PROTECTED: + errno = EACCES; + break; + case ERROR_DISK_NOT_VALIDATED: + case ERROR_OBJECT_IN_USE: + errno = EBUSY; + break; + case ERROR_OBJECT_EXISTS: + errno = EEXIST; + break; + case ERROR_DIR_NOT_FOUND: + case ERROR_NO_MORE_ENTRIES: + case ERROR_OBJECT_NOT_FOUND: + errno = ENOENT; + break; + case ERROR_NO_FREE_STORE: + errno = ENOMEM; + break; + case ERROR_DISK_FULL: + errno = ENOSPC; + break; + case ERROR_DIRECTORY_NOT_EMPTY: + errno = ENOTEMPTY; + break; + case ERROR_DISK_WRITE_PROTECTED: + errno = EROFS; + break; + case ERROR_RENAME_ACROSS_DEVICES: + errno = EXDEV; + break; + default: + errno = 0; + break; + } +} +#endif static int of_stat(OFString *path, of_stat_t *buffer) { #if defined(OF_WINDOWS) @@ -229,23 +274,11 @@ 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; - } - + setErrno(); return -1; } # ifdef OF_AMIGAOS4 if ((ed = ExamineObjectTags(EX_FileLockInput, lock, TAG_END)) == NULL) { @@ -621,11 +654,11 @@ if (lastAccessDate == nil) lastAccessDate = modificationDate; if (modificationDate == nil) modificationDate = lastAccessDate; -#ifdef OF_WINDOWS +#if defined(OF_WINDOWS) if (func__wutime64 != NULL) { struct __utimbuf64 times = { .actime = (__time64_t)lastAccessDate.timeIntervalSince1970, .modtime = @@ -657,10 +690,45 @@ @throw [OFSetItemAttributesFailedException exceptionWithURL: URL attributes: attributes failedAttribute: attributeKey errNo: errno]; + } +#elif defined(OF_AMIGAOS) + /* AmigaOS does not support access time. */ + of_time_interval_t modificationTime = + modificationDate.timeIntervalSince1970; + struct Locale *locale; + struct DateStamp date; + + modificationTime -= 252460800; /* 1978-01-01 */ + + if (modificationTime < 0) + @throw [OFOutOfRangeException exception]; + + locale = OpenLocale(NULL); + /* + * FIXME: This does not take DST into account. But unfortunately, there + * is no way to figure out if DST should be in effect for the + * timestamp. + */ + modificationTime -= locale->loc_GMTOffset * 60.0; + CloseLocale(locale); + + date.ds_Days = modificationTime / 86400; + date.ds_Minute = ((LONG)modificationTime % 86400) / 60; + date.ds_Tick = fmod(modificationTime, 60) * TICKS_PER_SECOND; + + if (!SetFileDate([path cStringWithEncoding: [OFLocale encoding]], + &date) != 0) { + setErrno(); + + @throw [OFSetItemAttributesFailedException + exceptionWithURL: URL + attributes: attributes + failedAttribute: attributeKey + errNo: errno]; } #else of_time_interval_t lastAccessTime = lastAccessDate.timeIntervalSince1970; of_time_interval_t modificationTime = @@ -917,38 +985,15 @@ #elif defined(OF_AMIGAOS) BPTR lock; if ((lock = CreateDir( [path cStringWithEncoding: [OFLocale encoding]])) == 0) { - int errNo; - - switch (IoErr()) { - case ERROR_NO_FREE_STORE: - case ERROR_DISK_FULL: - errNo = ENOSPC; - break; - case ERROR_OBJECT_IN_USE: - case ERROR_DISK_NOT_VALIDATED: - errNo = EBUSY; - break; - case ERROR_OBJECT_EXISTS: - errNo = EEXIST; - break; - case ERROR_OBJECT_NOT_FOUND: - errNo = ENOENT; - break; - case ERROR_DISK_WRITE_PROTECTED: - errNo = EROFS; - break; - default: - errNo = 0; - break; - } + setErrno(); @throw [OFCreateDirectoryFailedException exceptionWithURL: URL - errNo: errNo]; + errNo: errno]; } UnLock(lock); #else if (mkdir([path cStringWithEncoding: [OFLocale encoding]], 0777) != 0) @@ -1069,28 +1114,15 @@ 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: - case ERROR_DISK_NOT_VALIDATED: - errNo = EBUSY; - break; - case ERROR_OBJECT_NOT_FOUND: - errNo = ENOENT; - break; - default: - errNo = 0; - break; - } + setErrno(); @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil - errNo: errNo]; + errNo: errno]; } @try { # ifdef OF_AMIGAOS4 struct ExamineData *ed; @@ -1305,33 +1337,14 @@ #endif } #ifdef OF_AMIGAOS if (!DeleteFile([path cStringWithEncoding: [OFLocale encoding]])) { - int errNo; - - switch (IoErr()) { - case ERROR_OBJECT_IN_USE: - case ERROR_DISK_NOT_VALIDATED: - errNo = EBUSY; - break; - case ERROR_OBJECT_NOT_FOUND: - errNo = ENOENT; - break; - case ERROR_DISK_WRITE_PROTECTED: - errNo = EROFS; - break; - case ERROR_DELETE_PROTECTED: - errNo = EACCES; - break; - default: - errNo = 0; - break; - } + setErrno(); @throw [OFRemoveItemFailedException exceptionWithURL: URL - errNo: errNo]; + errNo: errno]; } #endif objc_autoreleasePoolPop(pool); } @@ -1441,38 +1454,16 @@ if (!Rename([source.fileSystemRepresentation cStringWithEncoding: encoding], [destination.fileSystemRepresentation cStringWithEncoding: encoding])) { - int errNo; - - switch (IoErr()) { - case ERROR_RENAME_ACROSS_DEVICES: - errNo = EXDEV; - break; - case ERROR_OBJECT_IN_USE: - case ERROR_DISK_NOT_VALIDATED: - errNo = EBUSY; - break; - case ERROR_OBJECT_EXISTS: - errNo = EEXIST; - break; - case ERROR_OBJECT_NOT_FOUND: - errNo = ENOENT; - break; - case ERROR_DISK_WRITE_PROTECTED: - errNo = EROFS; - break; - default: - errNo = 0; - break; - } + setErrno(); @throw [OFMoveItemFailedException exceptionWithSourceURL: source destinationURL: destination - errNo: errNo]; + errNo: errno]; } #else int status; # ifdef OF_WINDOWS Index: src/OFHTTPResponse.h ================================================================== --- src/OFHTTPResponse.h +++ src/OFHTTPResponse.h @@ -72,11 +72,17 @@ @end #ifdef __cplusplus extern "C" { #endif +/*! + * @brief Returns a description string for the specified HTTP status code. + * + * @param code The HTTP status code to return a description string for + * @return A description string for the specified HTTP status code + */ extern OFString *_Nonnull of_http_status_code_to_string(short code); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END Index: src/OFRunLoop.h ================================================================== --- src/OFRunLoop.h +++ src/OFRunLoop.h @@ -47,11 +47,11 @@ extern "C" { #endif /*! * @brief The default mode for an OFRunLoop. */ -extern of_run_loop_mode_t of_run_loop_mode_default; +extern const of_run_loop_mode_t of_run_loop_mode_default; #ifdef __cplusplus } #endif /*! Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -43,11 +43,11 @@ #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveFailedException.h" -of_run_loop_mode_t of_run_loop_mode_default = @"of_run_loop_mode_default"; +const of_run_loop_mode_t of_run_loop_mode_default = @"of_run_loop_mode_default"; static OFRunLoop *mainRunLoop = nil; @interface OFRunLoopState: OFObject #ifdef OF_HAVE_SOCKETS Index: src/pbkdf2.h ================================================================== --- src/pbkdf2.h +++ src/pbkdf2.h @@ -32,25 +32,24 @@ #ifdef __cplusplus extern "C" { #endif /*! - * @brief Derive a key from a password and a salt. + * @brief Derives a key from a password and a salt using PBKDF2. * - * @note This will call @ref OFHMAC::reset on the @ref OFHMAC first, making it - * possible to reuse the @ref OFHMAC, but also meaning all previous - * results from the @ref OFHMAC get invalidated if they have not been - * copied. + * @note This will call @ref OFHMAC::reset on the `HMAC` first, making it + * possible to reuse the `HMAC`, but also meaning all previous results + * from the `HMAC` get invalidated if they have not been copied. * * @param HMAC The HMAC to use to derive a key * @param iterations The number of iterations to perform * @param salt The salt to derive a key with * @param saltLength The length of the salt * @param password The password to derive a key from * @param passwordLength The length of the password * @param key The buffer to write the key to - * @param keyLength The desired length for the derived key (key needs to have + * @param keyLength The desired length for the derived key (`key` needs to have * enough storage) * @param allowsSwappableMemory Whether data may be stored in swappable memory */ extern void of_pbkdf2(OFHMAC *HMAC, size_t iterations, const unsigned char *salt, size_t saltLength, Index: src/scrypt.h ================================================================== --- src/scrypt.h +++ src/scrypt.h @@ -36,14 +36,30 @@ extern void of_salsa20_8_core(uint32_t buffer[_Nonnull 16]); extern void of_scrypt_block_mix(uint32_t *output, const uint32_t *input, size_t blockSize); extern void of_scrypt_romix(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp); + +/*! + * @brief Derives a key from a password and a salt using scrypt. + * + * @param blockSize The block size to use + * @param costFactor The CPU/memory cost factor to use + * @param parallelization The parallelization to use + * @param salt The salt to derive a key with + * @param saltLength The length of the salt + * @param password The password to derive a key from + * @param passwordLength The length of the password + * @param key The buffer to write the key to + * @param keyLength The desired length for the derived key (`key` needs to have + * enough storage) + * @param allowsSwappableMemory Whether data may be stored in swappable memory + */ extern void of_scrypt(size_t blockSize, size_t costFactor, size_t parallelization, const unsigned char *salt, size_t saltLength, const char *password, size_t passwordLength, unsigned char *key, size_t keyLength, bool allowsSwappableMemory); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END