@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2023 Jonathan Schleifer + * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -642,15 +642,15 @@ readdirMutex = [[OFMutex alloc] init]; atexit(releaseReaddirMutex); #endif #ifdef OF_WINDOWS - if ((module = LoadLibrary("msvcrt.dll")) != NULL) + if ((module = GetModuleHandle("msvcrt.dll")) != NULL) _wutime64FuncPtr = (int (*)(const wchar_t *, struct __utimbuf64 *))GetProcAddress(module, "_wutime64"); - if ((module = LoadLibrary("kernel32.dll")) != NULL) { + if ((module = GetModuleHandleA("kernel32.dll")) != NULL) { createSymbolicLinkWFuncPtr = (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, DWORD)) GetProcAddress(module, "CreateSymbolicLinkW"); createHardLinkWFuncPtr = (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, @@ -677,13 +677,23 @@ } - (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); - OFFile *file = [[OFFile alloc] - initWithPath: IRI.fileSystemRepresentation - mode: mode]; + OFFile *file; + + @try { + file = [OFFile fileWithPath: IRI.fileSystemRepresentation + mode: mode]; + } @catch (OFOpenItemFailedException *e) { + /* The thrown one has a path instead of an IRI set. */ + @throw [OFOpenItemFailedException exceptionWithIRI: IRI + mode: mode + errNo: e.errNo]; + } + + [file retain]; objc_autoreleasePoolPop(pool); return [file autorelease]; } @@ -1586,13 +1596,19 @@ # if defined(OF_LINUX) ssize_t size = lgetxattr(cPath, cName, NULL, 0); # elif defined(OF_MACOS) ssize_t size = getxattr(cPath, cName, NULL, 0, 0, XATTR_NOFOLLOW); # endif - void *value = OFAllocMemory(1, size); + void *value; OFData *data; + if (size < 0) + @throw [OFGetItemAttributesFailedException + exceptionWithIRI: IRI + errNo: errno]; + + value = OFAllocMemory(1, size); @try { # if defined(OF_LINUX) if ((size = lgetxattr(cPath, cName, value, size)) < 0) # elif defined(OF_MACOS) if ((size = getxattr(cPath, cName, value, size, 0,