# HG changeset patch # Parent 1a7f899b9a2ab01a0d8246ae77879f12fe24e671 Add wrapper stub for missing CreateHardLinkW() function. * lib/hardlink.c: New file; it generically implements... (hardlink-ascii.$OBJEXT, hardlink-utf16.$OBJEXT): ...these; they provide wrapper stubs for delayed run-time link resolution for... (CreateHardLinkA, CreateHardLinkW): ...these, respectively. * include/legacy.h (__legacy_failure, __legacy_fail_to_zero): New in-line functions; implement them for "always in-line" expansion. * lib/kernel32.def (CreateHardLinkW@12): Occlude reference. * Makefile.in (libkernel32.a): Add dependency reference for... (hardlink-utf16.$OBJEXT): ...this; add build rule. diff --git a/w32api/Makefile.in b/w32api/Makefile.in --- a/w32api/Makefile.in +++ b/w32api/Makefile.in @@ -5,11 +5,11 @@ PACKAGE_TARNAME := @PACKAGE_TARNAME@ PACKAGE_VERSION := @PACKAGE_VERSION@ # Written by Keith Marshall -# Copyright (C) 2014-2017, 2021, 2022, MinGW.OSDN Project +# Copyright (C) 2014-2017, 2021, 2022, 2024, MinGW.OSDN Project # # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation @@ -123,20 +123,23 @@ all-w32api-libs install-w32api-libs: lib lib%.a: %.def $(DLLTOOL) --as=$(AS) -k --output-lib $@ --def $< $(if $(filter-out $<,$^),$(AR) $(ARFLAGS) $@ $(filter-out $<,$^)) vpath %.c ${srcdir}/lib -libkernel32.a: $(addsuffix .$(OBJEXT),k32entry bound osvercmp) +libkernel32.a: $(addsuffix .$(OBJEXT),k32entry bound osvercmp hardlink-utf16) NO_ALIGN_FLAGS := -fno-align-jumps -fno-align-functions bound.$(OBJEXT) unbound.$(OBJEXT): %.$(OBJEXT): availapi.c $(CC) -c $(ALL_CFLAGS) $(NO_ALIGN_FLAGS) -D_$* $< -o $@ bound_dll_api_list := k32entry $(addsuffix .$(OBJEXT),$(bound_dll_api_list)): %.$(OBJEXT): availapi.c $(CC) -c $(ALL_CFLAGS) $(NO_ALIGN_FLAGS) -D_bound -D_lib=$* $< -o $@ +hardlink-utf16.$(OBJEXT): %.$(OBJEXT): hardlink.c + $(CC) -c -D_UNICODE $(ALL_CFLAGS) $(NO_ALIGN_FLAGS) $< -o $@ + libuuid.a: ativscp-uuid.$(OBJEXT) cguid-uuid.$(OBJEXT) libuuid.a: comcat-uuid.$(OBJEXT) devguid.$(OBJEXT) docobj-uuid.$(OBJEXT) libuuid.a: exdisp-uuid.$(OBJEXT) extras-uuid.$(OBJEXT) hlguids-uuid.$(OBJEXT) libuuid.a: hlink-uuid.$(OBJEXT) mlang-uuid.$(OBJEXT) mshtml-uuid.$(OBJEXT) libuuid.a: msxml-uuid.$(OBJEXT) oaidl-uuid.$(OBJEXT) objidl-uuid.$(OBJEXT) diff --git a/w32api/include/legacy.h b/w32api/include/legacy.h --- a/w32api/include/legacy.h +++ b/w32api/include/legacy.h @@ -6,11 +6,11 @@ * action, when running on legacy Windows versions. * * $Id$ * * Written by Keith Marshall - * Copyright (C) 2021, 2022, MinGW.OSDN Project + * Copyright (C) 2021, 2022, 2024, MinGW.OSDN Project * * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation @@ -91,8 +91,18 @@ void *__unbound_dll_entry_point (void *, * while also setting said code as Windows last error. */ __CRT_ALIAS int __legacy_support( int status ) { SetLastError( status ); return status; } +/* Alternatively, provide a similar mechanism for setting the error + * status code, while returning a distinct but arbitrary value, (which + * may often be required to be zero). + */ +__CRT_ALIAS int __legacy_failure( int code, int error_status ) +{ SetLastError( error_status ); return code; } + +__CRT_ALIAS int __legacy_fail_to_zero( int status ) +{ return __legacy_failure( 0, status ); } + _END_C_DECLS #endif /* !_LEGACY_H: $RCSfile$: end of file */ diff --git a/w32api/lib/hardlink.c b/w32api/lib/hardlink.c new file mode 100644 --- /dev/null +++ b/w32api/lib/hardlink.c @@ -0,0 +1,78 @@ +/* + * hardlink.c + * + * Provides wrapper functions, suitable for inclusion in libkernel32.a, + * such that calls to the CreateHardLink() functions may be successfully + * linked, and appropriately handled, regardless of whether the platform's + * native version of kernel32.dll actually supports the call, or not. + * + * $Id$ + * + * Written by Keith Marshall + * Copyright (C) 2024, MinGW.OSDN Project + * + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * + * Compile with -D_UNICODE, to generate a wrapper for CreateHardLinkW(): + * + * gcc -c -D_UNICODE -O3 hardlink.c -o hardlink-utf16.o + * + * Alternatively, compiling without the -D_UNICODE option will generate + * a wrapper for CreateHardLinkA(): + * + * gcc -c -O3 hardlink.c -o hardlink-ascii.o + * + */ +#include "legacy.h" + +#include +#include + +/* Wrapper function implementation; we need the generic function name + * to expand to either its "ANSI" suffixed, or to its UNICODE suffixed + * variant, but we cannot guarantee that a suitably qualified generic + * definition will be in scope, regardless of NTDDI_VERSION setting, + * so override any prior definition, and explicitly expand here. + */ +#undef CreateHardLink +WINBASEAPI BOOL WINAPI __AW_SUFFIXED__(CreateHardLink) +(LPCTSTR NewFile, LPCTSTR ToFile, LPSECURITY_ATTRIBUTES attrib) +{ + typedef BOOL WINAPI (*api)( LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES ); + + /* Initially, availability of the requested function is unknown; + * probe the DLL, to determine this for this, and subsequent calls... + */ + static void *call = API_UNCHECKED; + return ((call = __kernel32_entry_point( call, __FUNCTION__ )) != NULL) + /* + * ...then redirect the call to the DLL entry point, when this is + * found to be supported, (as a DLL export)... + */ + ? ((api)(call))( NewFile, ToFile, attrib ) + /* + * ...otherwise, fail with an "unsupported" error status. + */ + : __legacy_fail_to_zero( ERROR_OLD_WIN_VERSION ); +} + +/* $RCSfile$: end of file */ diff --git a/w32api/lib/kernel32.def b/w32api/lib/kernel32.def --- a/w32api/lib/kernel32.def +++ b/w32api/lib/kernel32.def @@ -151,11 +151,13 @@ CreateFileTransactedA@40 CreateFileTransactedW@40 CreateFileW@28 CreateHardLinkA@12 CreateHardLinkTransactedA@16 CreateHardLinkTransactedW@16 -CreateHardLinkW@12 +;Gratuitously called from libstdc++-6.dll, +;but unsupported by Win9x, or by WinNT prior to Win2K +;CreateHardLinkW@12 CreateIoCompletionPort@16 CreateJobObjectA@8 CreateJobObjectW@8 CreateJobSet@12 CreateMailslotA@16