[Libreoffice-commits] core.git: configure.ac download.lst external/mdnsresponder external/Module_external.mk Makefile.fetch RepositoryExternal.mk sd/CppunitTest_sd_uimpress.mk sd/Library_sd.mk sd/source
Michael Stahl
mstahl at redhat.com
Mon Nov 30 05:11:53 PST 2015
Makefile.fetch | 1
RepositoryExternal.mk | 12
configure.ac | 5
download.lst | 2
external/Module_external.mk | 1
external/mdnsresponder/Makefile | 7
external/mdnsresponder/Module_mdnsresponder.mk | 20
external/mdnsresponder/README | 4
external/mdnsresponder/StaticLibrary_mDNSResponder.mk | 37
external/mdnsresponder/UnpackedTarball_mDNSResponder.mk | 14
sd/CppunitTest_sd_uimpress.mk | 1
sd/Library_sd.mk | 9
sd/source/ui/remotecontrol/WINNetworkService.cxx | 1
sd/source/ui/remotecontrol/WINNetworkService.hxx | 2
sd/source/ui/remotecontrol/mDNSResponder/CommonServices.h | 1213 ----
sd/source/ui/remotecontrol/mDNSResponder/DebugServices.c | 2978 ------------
sd/source/ui/remotecontrol/mDNSResponder/DebugServices.h | 1576 ------
sd/source/ui/remotecontrol/mDNSResponder/GenLinkedList.c | 319 -
sd/source/ui/remotecontrol/mDNSResponder/GenLinkedList.h | 90
sd/source/ui/remotecontrol/mDNSResponder/dllmain.c | 113
sd/source/ui/remotecontrol/mDNSResponder/dns_sd.h | 2459 ---------
sd/source/ui/remotecontrol/mDNSResponder/dnssd_clientlib.c | 366 -
sd/source/ui/remotecontrol/mDNSResponder/dnssd_clientstub.c | 2219 --------
sd/source/ui/remotecontrol/mDNSResponder/dnssd_ipc.c | 161
sd/source/ui/remotecontrol/mDNSResponder/dnssd_ipc.h | 222
25 files changed, 105 insertions(+), 11727 deletions(-)
New commits:
commit 9ec0e6d9cbb0b61e5cf37917baee31f2af1a2897
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Nov 27 23:54:40 2015 +0100
sd: replace embedded mDNSResponder code with proper external tarball
The diff against the 379.37 release is 2500 lines, one of which
actually does anything at runtime (missing va_end()).
Change-Id: I1824e61fd4ac6c3ce28084913a2661134a03fd51
Reviewed-on: https://gerrit.libreoffice.org/20248
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Michael Stahl <mstahl at redhat.com>
diff --git a/Makefile.fetch b/Makefile.fetch
index 8b2da4e..cbc51b2 100644
--- a/Makefile.fetch
+++ b/Makefile.fetch
@@ -165,6 +165,7 @@ $(WORKDIR)/download: $(BUILDDIR)/config_host.mk $(SRCDIR)/download.lst $(SRCDIR)
$(call fetch_Optional,LPSOLVE,LPSOLVE_TARBALL) \
$(call fetch_Optional,MARIADB,MARIADB_TARBALL) \
$(call fetch_Optional,MDDS,MDDS_TARBALL) \
+ $(call fetch_Optional,MDNSRESPONDER,MDNSRESPONDER_TARBALL) \
$(call fetch_Optional,MORE_FONTS,FONT_CALADEA_TARBALL) \
$(call fetch_Optional,MORE_FONTS,FONT_CARLITO_TARBALL) \
$(call fetch_Optional,MORE_FONTS,FONT_DEJAVU_TARBALL) \
diff --git a/RepositoryExternal.mk b/RepositoryExternal.mk
index 2c00a33..cba5316 100644
--- a/RepositoryExternal.mk
+++ b/RepositoryExternal.mk
@@ -2442,6 +2442,18 @@ gb_LinkTarget__use_coinmp :=
endif # ENABLE_COINMP
+ifneq (,$(filter MDNSRESPONDER,$(BUILD_TYPE)))
+
+define gb_LinkTarget__use_mDNSResponder
+$(call gb_LinkTarget_set_include,$(1),\
+ -I$(call gb_UnpackedTarball_get_dir,mDNSResponder)/mDNSShared \
+ $$(INCLUDE) \
+)
+$(call gb_LinkTarget_use_static_libraries,$(1),mDNSResponder)
+endef
+
+endif # MDNSRESPONDER
+
ifeq ($(ENABLE_GIO),TRUE)
define gb_LinkTarget__use_gio
diff --git a/configure.ac b/configure.ac
index 9a13921..eb569d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11805,7 +11805,10 @@ AC_SUBST(CAIRO_LIBS)
dnl ===================================================================
dnl Test whether to use avahi
dnl ===================================================================
-if test "$_os" != "WINNT" -a "$_os" != "Darwin" -a "$enable_avahi" = "yes"; then
+if test "$_os" = "WINNT"; then
+ # Windows uses bundled mDNSResponder
+ BUILD_TYPE="$BUILD_TYPE MDNSRESPONDER"
+elif test "$_os" != "Darwin" -a "$enable_avahi" = "yes"; then
PKG_CHECK_MODULES([AVAHI], [avahi-client >= 0.6.10],
[ENABLE_AVAHI="TRUE"])
AC_DEFINE(HAVE_FEATURE_AVAHI)
diff --git a/download.lst b/download.lst
index 8774343..0201a61e 100755
--- a/download.lst
+++ b/download.lst
@@ -95,6 +95,8 @@ export LPSOLVE_TARBALL := 26b3e95ddf3d9c077c480ea45874b3b8-lp_solve_5.5.tar.gz
export MARIADB_TARBALL := a233181e03d3c307668b4c722d881661-mariadb_client-2.0.0-src.tar.gz
export MDDS_MD5SUM := 74e0a81c5af4137285fe6a52217f71e4
export MDDS_TARBALL := mdds_1.0.0.tar.bz2
+export MDNSRESPONDER_MD5SUM := dd557e1058b51ac2f29cd01d67be0145
+export MDNSRESPONDER_TARBALL := mDNSResponder-379.37.tar.gz
export MSPUB_MD5SUM := ff9d0f9dd8fbc523408ea1953d5bde41
export MSPUB_TARBALL := libmspub-0.1.2.tar.bz2
export MWAW_MD5SUM := 4a8a53a9d997cf0e2bd208178797dbfb
diff --git a/external/Module_external.mk b/external/Module_external.mk
index 7c78c7d..ccd758c 100644
--- a/external/Module_external.mk
+++ b/external/Module_external.mk
@@ -68,6 +68,7 @@ $(eval $(call gb_Module_add_moduledirs,external,\
$(call gb_Helper_optional,LPSOLVE,lpsolve) \
$(call gb_Helper_optional,MARIADB,libmariadb) \
$(call gb_Helper_optional,MDDS,mdds) \
+ $(call gb_Helper_optional,MDNSRESPONDER,mdnsresponder) \
$(if $(WITH_EXTRA_EXTENSIONS),misc_extensions) \
$(call gb_Helper_optional,MORE_FONTS,more_fonts) \
$(call gb_Helper_optional,MSPUB,libmspub) \
diff --git a/external/mdnsresponder/Makefile b/external/mdnsresponder/Makefile
new file mode 100644
index 0000000..e4968cf
--- /dev/null
+++ b/external/mdnsresponder/Makefile
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+
+module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
+
+include $(module_directory)/../../solenv/gbuild/partial_build.mk
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/mdnsresponder/Module_mdnsresponder.mk b/external/mdnsresponder/Module_mdnsresponder.mk
new file mode 100644
index 0000000..b299684
--- /dev/null
+++ b/external/mdnsresponder/Module_mdnsresponder.mk
@@ -0,0 +1,20 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Module_Module,mdnsresponder))
+
+$(eval $(call gb_Module_add_targets,mdnsresponder,\
+ UnpackedTarball_mDNSResponder \
+))
+
+$(eval $(call gb_Module_add_targets,mdnsresponder,\
+ StaticLibrary_mDNSResponder \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/mdnsresponder/README b/external/mdnsresponder/README
new file mode 100644
index 0000000..d263b05
--- /dev/null
+++ b/external/mdnsresponder/README
@@ -0,0 +1,4 @@
+Apple's ZeroConf Multicast DNS implementation
+
+https://developer.apple.com/bonjour/
+http://www.opensource.apple.com/tarballs/mDNSResponder/
diff --git a/external/mdnsresponder/StaticLibrary_mDNSResponder.mk b/external/mdnsresponder/StaticLibrary_mDNSResponder.mk
new file mode 100644
index 0000000..196b0c7
--- /dev/null
+++ b/external/mdnsresponder/StaticLibrary_mDNSResponder.mk
@@ -0,0 +1,37 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_StaticLibrary_StaticLibrary,mDNSResponder))
+
+$(eval $(call gb_StaticLibrary_set_warnings_not_errors,mDNSResponder))
+
+$(eval $(call gb_StaticLibrary_use_unpacked,mDNSResponder,mDNSResponder))
+
+$(eval $(call gb_StaticLibrary_set_include,mDNSResponder,\
+ -I$(call gb_UnpackedTarball_get_dir,mDNSResponder)/mDNSShared \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_StaticLibrary_add_defs,mDNSResponder,\
+ -DWIN32_LEAN_AND_MEAN \
+ -D_WINSOCK_DEPRECATED_NO_WARNINGS \
+ -DUSE_TCP_LOOPBACK \
+ -DNOT_HAVE_SA_LEN \
+))
+
+$(eval $(call gb_StaticLibrary_add_generated_cobjects,mDNSResponder,\
+ UnpackedTarball/mDNSResponder/mDNSShared/DebugServices \
+ UnpackedTarball/mDNSResponder/mDNSShared/GenLinkedList \
+ UnpackedTarball/mDNSResponder/mDNSShared/dnssd_clientlib \
+ UnpackedTarball/mDNSResponder/mDNSShared/dnssd_clientstub \
+ UnpackedTarball/mDNSResponder/mDNSShared/dnssd_ipc \
+ UnpackedTarball/mDNSResponder/mDNSWindows/DLL/dllmain \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/mdnsresponder/UnpackedTarball_mDNSResponder.mk b/external/mdnsresponder/UnpackedTarball_mDNSResponder.mk
new file mode 100644
index 0000000..9b436b2
--- /dev/null
+++ b/external/mdnsresponder/UnpackedTarball_mDNSResponder.mk
@@ -0,0 +1,14 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_UnpackedTarball_UnpackedTarball,mDNSResponder))
+
+$(eval $(call gb_UnpackedTarball_set_tarball,mDNSResponder,$(MDNSRESPONDER_TARBALL)))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sd/CppunitTest_sd_uimpress.mk b/sd/CppunitTest_sd_uimpress.mk
index a94b131..78e9f90 100644
--- a/sd/CppunitTest_sd_uimpress.mk
+++ b/sd/CppunitTest_sd_uimpress.mk
@@ -79,6 +79,7 @@ $(eval $(call gb_CppunitTest_use_externals,sd_uimpress,\
$(if $(ENABLE_AVAHI), \
avahi \
) \
+ $(if $(filter WNT,$(OS)),mDNSResponder) \
libxml2 \
))
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index b86c51c..66dca43 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -529,14 +529,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\
sd/source/ui/remotecontrol/WINNetworkService \
))
-$(eval $(call gb_Library_add_cobjects,sd,\
- sd/source/ui/remotecontrol/mDNSResponder/DebugServices \
- sd/source/ui/remotecontrol/mDNSResponder/dnssd_clientlib \
- sd/source/ui/remotecontrol/mDNSResponder/dnssd_clientstub \
- sd/source/ui/remotecontrol/mDNSResponder/dnssd_ipc \
- sd/source/ui/remotecontrol/mDNSResponder/GenLinkedList \
- sd/source/ui/remotecontrol/mDNSResponder/dllmain \
-))
+$(eval $(call gb_Library_use_external,sd,mDNSResponder))
endif # OS=WNT
diff --git a/sd/source/ui/remotecontrol/WINNetworkService.cxx b/sd/source/ui/remotecontrol/WINNetworkService.cxx
index 3643e1d..faedcf4 100644
--- a/sd/source/ui/remotecontrol/WINNetworkService.cxx
+++ b/sd/source/ui/remotecontrol/WINNetworkService.cxx
@@ -1,7 +1,6 @@
#include <string>
#include <iostream>
#include "WINNetworkService.hxx"
-#include "mDNSResponder/dns_sd.h"
#include <sal/log.hxx>
void sd::WINNetworkService::setup()
diff --git a/sd/source/ui/remotecontrol/WINNetworkService.hxx b/sd/source/ui/remotecontrol/WINNetworkService.hxx
index 0ca284f..1e32274 100644
--- a/sd/source/ui/remotecontrol/WINNetworkService.hxx
+++ b/sd/source/ui/remotecontrol/WINNetworkService.hxx
@@ -4,7 +4,7 @@
#include <string>
#undef WB_LEFT
#undef WB_RIGHT
-#include "mDNSResponder/dns_sd.h"
+#include <dns_sd.h>
#include "ZeroconfService.hxx"
namespace sd{
diff --git a/sd/source/ui/remotecontrol/mDNSResponder/CommonServices.h b/sd/source/ui/remotecontrol/mDNSResponder/CommonServices.h
deleted file mode 100644
index 1c1ae68..0000000
--- a/sd/source/ui/remotecontrol/mDNSResponder/CommonServices.h
+++ /dev/null
@@ -1,1213 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/*! @header CommonServices
-
- Common Services for Mac OS X, Linux, Palm, VxWorks, Windows, and Windows CE.
- */
-
-#ifndef __COMMON_SERVICES__
-#define __COMMON_SERVICES__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if 0
-#pragma mark == Target ==
-#endif
-
-
-// Target
-// Macintosh
-#if ( !defined( TARGET_OS_MAC ) )
- #if ( ( macintosh || __MACH__ ) && !KERNEL )
- // ConditionalMacros.h in CoreServices will define this TARGET_* flag.
- #else
- #define TARGET_OS_MAC 0
- #endif
-#endif
-
-#if ( !defined( TARGET_API_MAC_OSX_KERNEL ) )
- #if ( __MACH__ && KERNEL )
- #define TARGET_API_MAC_OSX_KERNEL 1
- #else
- #define TARGET_API_MAC_OSX_KERNEL 0
- #endif
-#endif
-
-// FreeBSD
-#if ( !defined( TARGET_OS_FREEBSD ) )
- #if ( defined( __FreeBSD__ ) )
- #define TARGET_OS_FREEBSD 1
- #else
- #define TARGET_OS_FREEBSD 0
- #endif
-#endif
-
-// Linux
-#if ( !defined( TARGET_OS_LINUX ) )
- #if ( defined( __linux__ ) )
- #define TARGET_OS_LINUX 1
- #else
- #define TARGET_OS_LINUX 0
- #endif
-#endif
-
-// Solaris
-#if ( !defined( TARGET_OS_SOLARIS ) )
- #if ( defined(solaris) || (defined(__SVR4) && defined(sun)) )
- #define TARGET_OS_SOLARIS 1
- #else
- #define TARGET_OS_SOLARIS 0
- #endif
-#endif
-
-// Palm
-#if ( !defined( TARGET_OS_PALM ) )
- #if ( defined( __PALMOS_TRAPS__ ) || defined( __PALMOS_ARMLET__ ) )
- #define TARGET_OS_PALM 1
- #else
- #define TARGET_OS_PALM 0
- #endif
-#endif
-
-// VxWorks
-#if ( !defined( TARGET_OS_VXWORKS ) )
-
-// No predefined macro for VxWorks so just assume VxWorks if nothing else is set.
-
- #if ( !macintosh && !__MACH__ && !defined( __FreeBSD__ ) && !defined( __linux__ ) && !defined ( __SVR4 ) && !defined ( __sun ) && !defined( __PALMOS_TRAPS__ ) && !defined( __PALMOS_ARMLET__ ) && !defined( _WIN32 ) )
- #define TARGET_OS_VXWORKS 1
- #else
- #define TARGET_OS_VXWORKS 0
- #endif
-#endif
-
-// Windows
-#if ( !defined( TARGET_OS_WIN32 ) )
- #if ( macintosh || __MACH__ )
-// ConditionalMacros.h in CoreServices will define this TARGET_* flag.
- #else
- #if ( defined( _WIN32 ) )
- #define TARGET_OS_WIN32 1
- #else
- #define TARGET_OS_WIN32 0
- #endif
- #endif
-#endif
-
-// Windows CE
-#if ( !defined( TARGET_OS_WINDOWS_CE ) )
- #if ( defined( _WIN32_WCE ) )
- #define TARGET_OS_WINDOWS_CE 1
- #else
- #define TARGET_OS_WINDOWS_CE 0
- #endif
-#endif
-
-#if 0
-#pragma mark == Includes ==
-#endif
-
-
-// Includes
-#if ( !KERNEL )
- #if defined(WIN32) && !defined(_WSPIAPI_COUNTOF)
- #define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0]))
- #endif
- #include <stddef.h>
-#endif
-
-#if ( ( macintosh || __MACH__ ) && !KERNEL )
-
- #if ( defined( __MWERKS__ ) )
- #if ( __option( c9x ) )
- #include <stdbool.h>
- #endif
- #else
- #include <stdbool.h>
- #endif
-
- #include <stdint.h>
-
- #if ( __MACH__ )
-
-// Mac OS X
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <fcntl.h>
- #include <pthread.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <unistd.h>
-
- #else
-
-// Classic Mac OS
- #include <ConditionalMacros.h>
- #include <MacTypes.h>
-
- #endif
-
-#elif ( KERNEL )
-
-// Mac OS X Kernel
- #include <stdint.h>
-
- #include <libkern/OSTypes.h>
- #include <sys/types.h>
-
-#elif ( TARGET_OS_FREEBSD )
-
-// FreeBSD
- #include <stdint.h>
- #include <pthread.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <sys/socket.h>
-
-#elif ( TARGET_OS_LINUX )
-
-// Linux
- #include <stdint.h>
- #include <arpa/inet.h>
-
-#elif ( TARGET_OS_SOLARIS )
-
-// Solaris
- #include <stdint.h>
-
- #include <arpa/inet.h>
- #include <arpa/nameser.h>
-
- #if ( defined( BYTE_ORDER ) && defined( LITTLE_ENDIAN ) && ( BYTE_ORDER == LITTLE_ENDIAN ) )
- #define TARGET_RT_LITTLE_ENDIAN 1
- #endif
- #if ( defined( BYTE_ORDER ) && defined( BIG_ENDIAN ) && ( BYTE_ORDER == BIG_ENDIAN ) )
- #define TARGET_RT_BIG_ENDIAN 1
- #endif
-
-#elif ( TARGET_OS_PALM )
-
-// Palm (no special includes yet).
-
-#elif ( TARGET_OS_VXWORKS )
-
-// VxWorks
- #include "vxWorks.h"
-
-#elif ( TARGET_OS_WIN32 )
-
-// Windows
- #if ( !defined( WIN32_WINDOWS ) )
- #define WIN32_WINDOWS 0x0401
- #endif
-
- #if ( !defined( _WIN32_WINDOWS ) )
- #define _WIN32_WINDOWS 0x0401
- #endif
-
- #if ( !defined( WIN32_LEAN_AND_MEAN ) )
- #define WIN32_LEAN_AND_MEAN // Needed to avoid redefinitions by Windows interfaces.
- #endif
-
- #if ( defined( __MWERKS__ ) )
-
- #if ( __option( c9x ) )
- #include <stdbool.h>
- #endif
-
- #include <stdint.h>
-
- #elif ( defined( _MSC_VER ) )
-
- #pragma warning( disable:4127 ) // Disable "conditional expression is constant" warning for debug macros.
-
- #endif
-
- #include <windows.h>
- #include <winsock2.h>
- #include <ws2tcpip.h>
-
-#else
- #error unknown OS - update this file to support your OS
-#endif
-
-#if ( !defined( TARGET_BUILD_MAIN ) )
- #if ( !TARGET_OS_VXWORKS )
- #define TARGET_BUILD_MAIN 1
- #endif
-#endif
-
-#if ( __GNUC__ || !TARGET_OS_VXWORKS )
- #define TARGET_LANGUAGE_C_LIKE 1
-#else
- #define TARGET_LANGUAGE_C_LIKE 0
-#endif
-
-#if 0
-#pragma mark == CPU ==
-#endif
-
-
-// CPU
-
-// PowerPC
-#if ( !defined( TARGET_CPU_PPC ) )
- #if ( defined( __ppc__ ) || defined( __PPC__ ) || defined( powerpc ) || defined( ppc ) || defined( _M_MPPC ) )
- #define TARGET_CPU_PPC 1
- #else
- #define TARGET_CPU_PPC 0
- #endif
-#endif
-
-// x86
-#if ( !defined( TARGET_CPU_X86 ) )
- #if ( __INTEL__ || defined( __i386__ ) || defined( i386 ) || defined( intel ) || defined( _M_IX86 ) )
- #define TARGET_CPU_X86 1
- #else
- #define TARGET_CPU_X86 0
- #endif
-#endif
-
-// MIPS
-#if ( !defined( TARGET_CPU_MIPS ) )
- #if ( __MIPS__ || defined( MIPS32 ) || defined( R3000 ) || defined( R4000 ) || defined( R4650 ) || defined( _M_MRX000 ) )
- #define TARGET_CPU_MIPS 1
- #else
- #define TARGET_CPU_MIPS 0
- #endif
-#endif
-
-#if ( !defined( TARGET_CPU_PPC ) && !defined( TARGET_CPU_X86 ) && !defined( TARGET_CPU_MIPS ) )
- #error unknown CPU - update this file to support your CPU
-#endif
-
-#if 0
-#pragma mark == Byte Order ==
-#endif
-
-
-// Byte Order
-
-// TARGET_RT_LITTLE_ENDIAN
-#if ( !defined( TARGET_RT_LITTLE_ENDIAN ) )
- #if ( MIPSEL || IL_LITTLE_ENDIAN || defined( __LITTLE_ENDIAN__ ) || \
- ( defined( BYTE_ORDER ) && defined( LITTLE_ENDIAN ) && ( BYTE_ORDER == LITTLE_ENDIAN ) ) || \
- ( defined( _BYTE_ORDER ) && defined( _LITTLE_ENDIAN ) && ( _BYTE_ORDER == _LITTLE_ENDIAN ) ) || \
- ( defined( __BYTE_ORDER ) && defined( __LITTLE_ENDIAN ) && ( __BYTE_ORDER == __LITTLE_ENDIAN ) ) || \
- TARGET_CPU_X86 || ( defined( TARGET_RT_BIG_ENDIAN ) && !TARGET_RT_BIG_ENDIAN ) )
- #define TARGET_RT_LITTLE_ENDIAN 1
- #else
- #define TARGET_RT_LITTLE_ENDIAN 0
- #endif
-#endif
-
-// TARGET_RT_BIG_ENDIAN
-#if ( !defined( TARGET_RT_BIG_ENDIAN ) )
- #if ( MIPSEB || IL_BIG_ENDIAN || defined( __BIG_ENDIAN__ ) || \
- ( defined( BYTE_ORDER ) && defined( BIG_ENDIAN ) && ( BYTE_ORDER == BIG_ENDIAN ) ) || \
- ( defined( _BYTE_ORDER ) && defined( _BIG_ENDIAN ) && ( _BYTE_ORDER == _BIG_ENDIAN ) ) || \
- ( defined( __BYTE_ORDER ) && defined( __BIG_ENDIAN ) && ( __BYTE_ORDER == __BIG_ENDIAN ) ) || \
- ( defined( TARGET_RT_LITTLE_ENDIAN ) && !TARGET_RT_LITTLE_ENDIAN ) )
- #define TARGET_RT_BIG_ENDIAN 1
- #else
- #define TARGET_RT_BIG_ENDIAN 0
- #endif
-#endif
-
-#if ( defined( TARGET_RT_LITTLE_ENDIAN ) && !defined( TARGET_RT_BIG_ENDIAN ) )
- #if ( TARGET_RT_LITTLE_ENDIAN )
- #define TARGET_RT_BIG_ENDIAN 0
- #else
- #define TARGET_RT_BIG_ENDIAN 1
- #endif
-#endif
-
-#if ( defined( TARGET_RT_BIG_ENDIAN ) && !defined( TARGET_RT_LITTLE_ENDIAN ) )
- #if ( TARGET_RT_BIG_ENDIAN )
- #define TARGET_RT_LITTLE_ENDIAN 0
- #else
- #define TARGET_RT_LITTLE_ENDIAN 1
- #endif
-#endif
-
-#if ( !defined( TARGET_RT_LITTLE_ENDIAN ) || !defined( TARGET_RT_BIG_ENDIAN ) )
- #error unknown byte order - update this file to support your byte order
-#endif
-
-// TARGET_RT_BYTE_ORDER
-#if ( !defined( TARGET_RT_BYTE_ORDER_BIG_ENDIAN ) )
- #define TARGET_RT_BYTE_ORDER_BIG_ENDIAN 1234
-#endif
-
-#if ( !defined( TARGET_RT_BYTE_ORDER_LITTLE_ENDIAN ) )
- #define TARGET_RT_BYTE_ORDER_LITTLE_ENDIAN 4321
-#endif
-
-#if ( !defined( TARGET_RT_BYTE_ORDER ) )
- #if ( TARGET_RT_LITTLE_ENDIAN )
- #define TARGET_RT_BYTE_ORDER TARGET_RT_BYTE_ORDER_LITTLE_ENDIAN
- #else
- #define TARGET_RT_BYTE_ORDER TARGET_RT_BYTE_ORDER_BIG_ENDIAN
- #endif
-#endif
-
-#if 0
-#pragma mark == Constants ==
-#endif
-
-
-// Constants
-#if ( !TARGET_OS_MAC )
- #define CR '\r'
-#endif
-
-#define LF '\n'
-#define CRLF "\r\n"
-
-#if 0
-#pragma mark == Compatibility ==
-#endif
-
-
-// Compatibility
-
-// Macros to allow the same code to work on Windows and other sockets API-compatible platforms.
-#if ( TARGET_OS_WIN32 )
- #define close_compat( X ) closesocket( X )
- #define errno_compat() (int) GetLastError()
- #define set_errno_compat( X ) SetLastError( X )
- #define EWOULDBLOCK_compat WSAEWOULDBLOCK
- #define ETIMEDOUT_compat WSAETIMEDOUT
- #define ENOTCONN_compat WSAENOTCONN
- #define IsValidSocket( X ) ( ( X ) != INVALID_SOCKET )
- #define kInvalidSocketRef INVALID_SOCKET
- #if ( TARGET_LANGUAGE_C_LIKE )
-typedef SOCKET SocketRef;
- #endif
-#else
- #define close_compat( X ) close( X )
- #define errno_compat() errno
- #define set_errno_compat( X ) do { errno = ( X ); } while( 0 )
- #define EWOULDBLOCK_compat EWOULDBLOCK
- #define ETIMEDOUT_compat ETIMEDOUT
- #define ENOTCONN_compat ENOTCONN
- #define IsValidSocket( X ) ( ( X ) >= 0 )
- #define kInvalidSocketRef -1
- #if ( TARGET_LANGUAGE_C_LIKE )
-typedef int SocketRef;
- #endif
-#endif
-
-// socklen_t is not defined on the following platforms so emulate it if not defined:
-
-// - Pre-Panther Mac OS X. Panther defines SO_NOADDRERR so trigger off that.
-// - Windows SDK prior to 2003. 2003+ SDK's define EAI_AGAIN so trigger off that.
-// - VxWorks
-
-#if ( TARGET_LANGUAGE_C_LIKE )
- #if ( ( TARGET_OS_MAC && !defined( SO_NOADDRERR ) ) || ( TARGET_OS_WIN32 && !defined( EAI_AGAIN ) ) || TARGET_OS_VXWORKS )
-typedef int socklen_t;
- #endif
-#endif
-
-// ssize_t is not defined on the following platforms so emulate it if not defined:
-
-// - Mac OS X when not building with BSD headers
-// - Windows
-
-#if ( TARGET_LANGUAGE_C_LIKE )
- #if ( !defined(_SSIZE_T) && ( TARGET_OS_WIN32 || !defined( _BSD_SSIZE_T_DEFINED_ ) ) && !TARGET_OS_FREEBSD && !TARGET_OS_LINUX && !TARGET_OS_VXWORKS && !TARGET_OS_MAC && !defined (__MINGW32__))
-typedef int ssize_t;
- #endif
-#endif
-
-// sockaddr_storage is not supported on non-IPv6 machines so alias it to an IPv4-compatible structure.
-
-#if ( TARGET_LANGUAGE_C_LIKE )
- #if ( !defined( AF_INET6 ) )
- #define sockaddr_storage sockaddr_in
- #define ss_family sin_family
- #endif
-#endif
-
-
-/*! @defined SOCKADDR_IS_IP_LOOPBACK
-
- @abstract Determines if a sockaddr is an IPv4 or IPv6 loopback address (if IPv6 is supported).
- */
-#if ( defined( AF_INET6 ) )
- #define SOCKADDR_IS_IP_LOOPBACK( SA ) \
- ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
- ? ( ( (const struct sockaddr_in *)( SA ) )->sin_addr.s_addr == htonl( INADDR_LOOPBACK ) ) \
- : ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET6 ) \
- ? IN6_IS_ADDR_LOOPBACK( &( (const struct sockaddr_in6 *)( SA ) )->sin6_addr ) \
- : 0
-#else
- #define SOCKADDR_IS_IP_LOOPBACK( SA ) \
- ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
- ? ( ( (const struct sockaddr_in *)( SA ) )->sin_addr.s_addr == htonl( INADDR_LOOPBACK ) ) \
- : 0
-#endif
-
-
-/*! @defined SOCKADDR_IS_IP_LINK_LOCAL
-
- @abstract Determines if a sockaddr is an IPv4 or IPv6 link-local address (if IPv6 is supported).
- */
-#if ( defined( AF_INET6 ) )
- #define SOCKADDR_IS_IP_LINK_LOCAL( SA ) \
- ( ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
- ? ( ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 0 ] == 169 ) && \
- ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 1 ] == 254 ) ) \
- : IN6_IS_ADDR_LOOPBACK( &( (const struct sockaddr_in6 *)( SA ) )->sin6_addr ) )
-#else
- #define SOCKADDR_IS_IP_LINK_LOCAL( SA ) \
- ( ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
- ? ( ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 0 ] == 169 ) && \
- ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 1 ] == 254 ) ) \
- : 0 )
-#endif
-
-// _beginthreadex and _endthreadex are not supported on Windows CE 2.1 or later (the C runtime issues with leaking
-// resources have apparently been resolved and they seem to have just ripped out support for the API) so map it to
-// CreateThread on Windows CE.
-#if ( TARGET_OS_WINDOWS_CE )
- #define _beginthreadex_compat( SECURITY_PTR, STACK_SIZE, START_ADDRESS, ARG_LIST, FLAGS, THREAD_ID_PTR ) \
- (uintptr_t) CreateThread( SECURITY_PTR, STACK_SIZE, (LPTHREAD_START_ROUTINE) START_ADDRESS, ARG_LIST, FLAGS, \
- (LPDWORD) THREAD_ID_PTR )
-
- #define _endthreadex_compat( RESULT ) ExitThread( (DWORD) RESULT )
-#elif ( TARGET_OS_WIN32 )
- #define _beginthreadex_compat _beginthreadex
- #define _endthreadex_compat _endthreadex
-#endif
-
-// The C99 "inline" keyword is not supported by Microsoft compilers, but they do support __inline so map it when needed.
-
-#if ( defined( _MSC_VER ) )
- #define inline_compat __inline
-#else
- #define inline_compat inline
-#endif
-
-// Calling conventions
-
-#if ( !defined( CALLBACK_COMPAT ) )
- #if ( TARGET_OS_WIN32 || TARGET_OS_WINDOWS_CE )
- #define CALLBACK_COMPAT CALLBACK
- #else
- #define CALLBACK_COMPAT
- #endif
-#endif
-
-#if 0
-#pragma mark == Macros ==
-#endif
-
-
-/*! @defined kSizeCString
-
- @abstract A meta-value to pass to supported routines to indicate the size should be calculated with strlen.
- */
-
-#define kSizeCString ( (size_t) -1 )
-
-
-/*! @defined sizeof_array
-
- @abstract Determines the number of elements in an array.
- */
-
-#define sizeof_array( X ) ( sizeof( X ) / sizeof( X[ 0 ] ) )
-
-
-/*! @defined sizeof_element
-
- @abstract Determines the size of an array element.
- */
-
-#define sizeof_element( X ) sizeof( X[ 0 ] )
-
-
-/*! @defined sizeof_string
-
- @abstract Determines the size of a constant C string, excluding the null terminator.
- */
-
-#define sizeof_string( X ) ( sizeof( ( X ) ) - 1 )
-
-
-/*! @defined sizeof_field
-
- @abstract Determines the size of a field of a type.
- */
-
-#define sizeof_field( TYPE, FIELD ) sizeof( ( ( (TYPE *) 0 )->FIELD ) )
-
-
-/*! @function RoundUp
-
- @abstract Rounds X up to a multiple of Y.
- */
-
-#define RoundUp( X, Y ) ( ( X ) + ( ( Y ) -( ( X ) % ( Y ) ) ) )
-
-
-/*! @function IsAligned
-
- @abstract Returns non-zero if X is aligned to a Y byte boundary and 0 if not. Y must be a power of 2.
- */
-
-#define IsAligned( X, Y ) ( ( ( X ) &( ( Y ) -1 ) ) == 0 )
-
-
-/*! @function IsFieldAligned
-
- @abstract Returns non-zero if FIELD of type TYPE is aligned to a Y byte boundary and 0 if not. Y must be a power of 2.
- */
-
-#define IsFieldAligned( X, TYPE, FIELD, Y ) IsAligned( ( (uintptr_t)( X ) ) + offsetof( TYPE, FIELD ), ( Y ) )
-
-
-/*! @function AlignDown
-
- @abstract Aligns X down to a Y byte boundary. Y must be a power of 2.
- */
-
-#define AlignDown( X, Y ) ( ( X ) &~( ( Y ) -1 ) )
-
-
-/*! @function AlignUp
-
- @abstract Aligns X up to a Y byte boundary. Y must be a power of 2.
- */
-
-#define AlignUp( X, Y ) ( ( ( X ) + ( ( Y ) -1 ) ) & ~( ( Y ) -1 ) )
-
-
-/*! @function Min
-
- @abstract Returns the lesser of X and Y.
- */
-
-#if ( !defined( Min ) )
- #define Min( X, Y ) ( ( ( X ) < ( Y ) ) ? ( X ) : ( Y ) )
-#endif
-
-
-/*! @function Max
-
- @abstract Returns the greater of X and Y.
- */
-
-#if ( !defined( Max ) )
- #define Max( X, Y ) ( ( ( X ) > ( Y ) ) ? ( X ) : ( Y ) )
-#endif
-
-
-/*! @function InsertBits
-
- @abstract Inserts BITS (both 0 and 1 bits) into X, controlled by MASK and SHIFT, and returns the result.
-
- @discussion
-
- MASK is the bitmask of the bits in the final position.
- SHIFT is the number of bits to shift left for 1 to reach the first bit position of MASK.
-
- For example, if you wanted to insert 0x3 into the leftmost 4 bits of a 32-bit value:
-
- InsertBits( 0, 0x3, 0xF0000000U, 28 ) == 0x30000000
- */
-
-#define InsertBits( X, BITS, MASK, SHIFT ) ( ( ( X ) &~( MASK ) ) | ( ( ( BITS ) << ( SHIFT ) ) & ( MASK ) ) )
-
-
-/*! @function ExtractBits
-
- @abstract Extracts bits from X, controlled by MASK and SHIFT, and returns the result.
-
- @discussion
-
- MASK is the bitmask of the bits in the final position.
- SHIFT is the number of bits to shift right to right justify MASK.
-
- For example, if you had a 32-bit value (e.g. 0x30000000) wanted the left-most 4 bits (e.g. 3 in this example):
-
- ExtractBits( 0x30000000U, 0xF0000000U, 28 ) == 0x3
- */
-
-#define ExtractBits( X, MASK, SHIFT ) ( ( ( X ) >> ( SHIFT ) ) & ( ( MASK ) >> ( SHIFT ) ) )
-
-
-/*! @function Stringify
-
- @abstract Stringify's an expression.
-
- @discussion
-
- Stringify macros to process raw text passed via -D options to C string constants. The double-wrapping is necessary
- because the C preprocessor doesn't perform its normal argument expansion pre-scan with stringified macros so the
- -D macro needs to be expanded once via the wrapper macro then stringified so the raw text is stringified. Otherwise,
- the replacement value would be used instead of the symbolic name (only for preprocessor symbols like #defines).
-
- For example:
-
- #define kMyConstant 1
-
- printf( "%s", Stringify( kMyConstant ) ); // Prints "kMyConstant"
- printf( "%s", StringifyExpansion( kMyConstant ) ); // Prints "1"
-
- Non-preprocessor symbols do not have this issue. For example:
-
- enum
- {
- kMyConstant = 1
- };
-
- printf( "%s", Stringify( kMyConstant ) ); // Prints "kMyConstant"
- printf( "%s", StringifyExpansion( kMyConstant ) ); // Prints "kMyConstant"
-
- See <http://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html> for more info on C preprocessor pre-scanning.
- */
-
-#define Stringify( X ) # X
-#define StringifyExpansion( X ) Stringify( X )
-
-#if 0
-#pragma mark == Types ==
-#endif
-
-#if ( TARGET_LANGUAGE_C_LIKE )
-
-// Standard Types
-
-
-#if ( !defined( INT8_MIN ) )
-
- #define INT8_MIN SCHAR_MIN
-
- #if ( defined( _MSC_VER ) )
-
-// C99 stdint.h not supported in VC++/VS.NET yet.
-
-typedef INT8 int8_t;
-typedef UINT8 uint8_t;
-typedef INT16 int16_t;
-typedef UINT16 uint16_t;
-typedef INT32 int32_t;
-typedef UINT32 uint32_t;
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
- #elif defined (__MINGW32__)
- # include <stdint.h>
- #elif ( TARGET_OS_VXWORKS && ( TORNADO_VERSION < 220 ) )
-typedef long long int64_t;
-typedef unsigned long long uint64_t;
- #endif
-
-typedef int32_t int_least32_t;
-
-
-
-
- #if ( !defined( _WIN32 ) || TARGET_OS_WINDOWS_CE )
-typedef long int intptr_t;
-typedef unsigned long int uintptr_t;
- #endif
-
-#endif
-
-// Macros for minimum-width integer constants
-
-#if ( !defined( INT8_C ) )
- #define INT8_C( value ) value
-#endif
-
-#if ( !defined( INT16_C ) )
- #define INT16_C( value ) value
-#endif
-
-#if ( !defined( INT32_C ) )
- #define INT32_C( value ) value ## L
-#endif
-
-#if ( !defined( INT64_C ) )
- #if ( defined( _MSC_VER ) )
- #define INT64_C( value ) value ## i64
- #else
- #define INT64_C( value ) value ## LL
- #endif
-#endif
-
-#if ( !defined( UINT8_C ) )
- #define UINT8_C( value ) value ## U
-#endif
-
-#if ( !defined( UINT16_C ) )
- #define UINT16_C( value ) value ## U
-#endif
-
-#if ( !defined( UINT32_C ) )
- #define UINT32_C( value ) value ## UL
-#endif
-
-#if ( !defined( UINT64_C ) )
- #if ( defined( _MSC_VER ) )
- #define UINT64_C( value ) value ## UI64
- #else
- #define UINT64_C( value ) value ## ULL
- #endif
-#endif
-
-#if 0
-#pragma mark == bool ==
-#endif
-
-
-// Boolean Constants and Types
-
-
-// C++ defines bool, true, and false. Metrowerks allows this to be controlled by the "bool" option though.
-// C99 defines __bool_true_false_are_defined when bool, true, and false are defined.
-// MacTypes.h defines true and false (Mac builds only).
-
-// Note: The Metrowerks has to be in its own block because Microsoft Visual Studio .NET does not completely
-// short-circuit and gets confused by the option( bool ) portion of the conditional.
-
-#if ( defined( __MWERKS__ ) )
-
-// Note: The following test is done on separate lines because CodeWarrior doesn't like it all on one line.
-
- #if ( !__bool_true_false_are_defined && ( !defined( __cplusplus ) || !__option( bool ) ) )
- #define COMMON_SERVICES_NEEDS_BOOL 1
- #else
- #define COMMON_SERVICES_NEEDS_BOOL 0
- #endif
-
-// Workaround when building with CodeWarrior, but using the Apple stdbool.h header, which uses _Bool.
-
- #if ( __bool_true_false_are_defined && !defined( __cplusplus ) && !__option( c9x ) )
- #define _Bool int
- #endif
-
-// Workaround when building with CodeWarrior for C++ with bool disabled and using the Apple stdbool.h header,
-// which defines true and false to map to C++ true and false (which are not enabled). Serenity Now!
-
- #if ( __bool_true_false_are_defined && defined( __cplusplus ) && !__option( bool ) )
- #define true 1
- #define false 0
- #endif
-#else
- #define COMMON_SERVICES_NEEDS_BOOL ( !defined( __cplusplus ) && !__bool_true_false_are_defined )
-#endif
-
-#if ( COMMON_SERVICES_NEEDS_BOOL )
-
-typedef int bool;
-
- #define bool bool
-
- #if ( !defined( __MACTYPES__ ) && !defined( true ) && !defined( false ) )
- #define true 1
- #define false 0
- #endif
-
- #define __bool_true_false_are_defined 1
-#endif
-
-// IOKit IOTypes.h typedef's bool if TYPE_BOOL is not defined so define it here to prevent redefinition by IOTypes.h.
-
-#if ( TARGET_API_MAC_OSX_KERNEL )
- #define TYPE_BOOL 1
-#endif
-
-
-/*! @typedef CStr255
-
- @abstract 255 character null-terminated (C-style) string.
- */
-
-#if ( TARGET_LANGUAGE_C_LIKE )
-typedef char CStr255[ 256 ];
-#endif
-
-#endif // TARGET_LANGUAGE_C_LIKE
-
-
-/*! @defined TYPE_LONGLONG_NATIVE
-
- @abstract Defines whether long long (or its equivalent) is natively supported or requires special libraries.
- */
-
-#if ( !defined( TYPE_LONGLONG_NATIVE ) )
- #if ( !TARGET_OS_VXWORKS )
- #define TYPE_LONGLONG_NATIVE 1
- #else
- #define TYPE_LONGLONG_NATIVE 0
- #endif
-#endif
-
-
-/*! @defined long_long_compat
-
- @abstract Compatibility type to map to the closest thing to long long and unsigned long long.
-
- @discussion
-
- Neither long long nor unsigned long long are supported by Microsoft compilers, but they do support proprietary
- "__int64" and "unsigned __int64" equivalents so map to those types if the real long long is not supported.
- */
-
-#if ( TARGET_LANGUAGE_C_LIKE )
- #if ( TARGET_OS_WIN32 )
-typedef __int64 long_long_compat;
-typedef unsigned __int64 unsigned_long_long_compat;
- #else
-typedef signed long long long_long_compat;
-typedef unsigned long long unsigned_long_long_compat;
- #endif
-#endif
-
-#if 0
-#pragma mark == Errors ==
-#endif
-
-
-/*! @enum OSStatus
-
- @abstract Status Code
-
- @constant kNoErr 0 No error occurred.
- @constant kInProgressErr 1 Operation in progress.
- @constant kUnknownErr -6700 Unknown error occurred.
- @constant kOptionErr -6701 Option was not acceptable.
- @constant kSelectorErr -6702 Selector passed in is invalid or unknown.
- @constant kExecutionStateErr -6703 Call made in the wrong execution state (e.g. called at interrupt time).
- @constant kPathErr -6704 Path is invalid, too long, or otherwise not usable.
- @constant kParamErr -6705 Parameter is incorrect, missing, or not appropriate.
- @constant kParamCountErr -6706 Incorrect or unsupported number of parameters.
- @constant kCommandErr -6707 Command invalid or not supported.
- @constant kIDErr -6708 Unknown, invalid, or inappropriate identifier.
- @constant kStateErr -6709 Not in appropriate state to perform operation.
- @constant kRangeErr -6710 Index is out of range or not valid.
- @constant kRequestErr -6711 Request was improperly formed or not appropriate.
- @constant kResponseErr -6712 Response was incorrect or out of sequence.
- @constant kChecksumErr -6713 Checksum does not match the actual data.
- @constant kNotHandledErr -6714 Operation was not handled (or not handled completely).
- @constant kVersionErr -6715 Version is not incorrect or not compatibile.
- @constant kSignatureErr -6716 Signature did not match what was expected.
- @constant kFormatErr -6717 Unknown, invalid, or inappropriate file/data format.
- @constant kNotInitializedErr -6718 Action request before needed services were initialized.
- @constant kAlreadyInitializedErr -6719 Attempt made to initialize when already initialized.
- @constant kNotInUseErr -6720 Object not in use (e.g. cannot abort if not already in use).
- @constant kInUseErr -6721 Object is in use (e.g. cannot reuse active param blocks).
- @constant kTimeoutErr -6722 Timeout occurred.
- @constant kCanceledErr -6723 Operation canceled (successful cancel).
- @constant kAlreadyCanceledErr -6724 Operation has already been canceled.
- @constant kCannotCancelErr -6725 Operation could not be canceled (maybe already done or invalid).
- @constant kDeletedErr -6726 Object has already been deleted.
- @constant kNotFoundErr -6727 Something was not found.
- @constant kNoMemoryErr -6728 Not enough memory was available to perform the operation.
- @constant kNoResourcesErr -6729 Resources unavailable to perform the operation.
- @constant kDuplicateErr -6730 Duplicate found or something is a duplicate.
- @constant kImmutableErr -6731 Entity is not changeable.
- @constant kUnsupportedDataErr -6732 Data is unknown or not supported.
- @constant kIntegrityErr -6733 Data is corrupt.
- @constant kIncompatibleErr -6734 Data is not compatible or it is in an incompatible format.
- @constant kUnsupportedErr -6735 Feature or option is not supported.
- @constant kUnexpectedErr -6736 Error occurred that was not expected.
- @constant kValueErr -6737 Value is not appropriate.
- @constant kNotReadableErr -6738 Could not read or reading is not allowed.
- @constant kNotWritableErr -6739 Could not write or writing is not allowed.
- @constant kBadReferenceErr -6740 An invalid or inappropriate reference was specified.
- @constant kFlagErr -6741 An invalid, inappropriate, or unsupported flag was specified.
- @constant kMalformedErr -6742 Something was not formed correctly.
- @constant kSizeErr -6743 Size was too big, too small, or not appropriate.
- @constant kNameErr -6744 Name was not correct, allowed, or appropriate.
- @constant kNotReadyErr -6745 Device or service is not ready.
- @constant kReadErr -6746 Could not read.
- @constant kWriteErr -6747 Could not write.
- @constant kMismatchErr -6748 Something does not match.
- @constant kDateErr -6749 Date is invalid or out-of-range.
- @constant kUnderrunErr -6750 Less data than expected.
- @constant kOverrunErr -6751 More data than expected.
- @constant kEndingErr -6752 Connection, session, or something is ending.
- @constant kConnectionErr -6753 Connection failed or could not be established.
- @constant kAuthenticationErr -6754 Authentication failed or is not supported.
- @constant kOpenErr -6755 Could not open file, pipe, device, etc.
- @constant kTypeErr -6756 Incorrect or incompatible type (e.g. file, data, etc.).
- @constant kSkipErr -6757 Items should be or was skipped.
- @constant kNoAckErr -6758 No acknowledge.
- @constant kCollisionErr -6759 Collision occurred (e.g. two on bus at same time).
- @constant kBackoffErr -6760 Backoff in progress and operation intentionally failed.
- @constant kNoAddressAckErr -6761 No acknowledge of address.
- @constant kBusyErr -6762 Cannot perform because something is busy.
- @constant kNoSpaceErr -6763 Not enough space to perform operation.
- */
-
-#if ( TARGET_LANGUAGE_C_LIKE )
- #if ( !TARGET_OS_MAC && !TARGET_API_MAC_OSX_KERNEL )
-typedef int32_t OSStatus;
- #endif
-#endif
-
-#define kNoErr 0
-#define kInProgressErr 1
-
-// Generic error codes are in the range -6700 to -6779.
-
-#define kGenericErrorBase -6700 // Starting error code for all generic errors.
-
-#define kUnknownErr -6700
-#define kOptionErr -6701
-#define kSelectorErr -6702
-#define kExecutionStateErr -6703
-#define kPathErr -6704
-#define kParamErr -6705
-#define kParamCountErr -6706
-#define kCommandErr -6707
-#define kIDErr -6708
-#define kStateErr -6709
-#define kRangeErr -6710
-#define kRequestErr -6711
-#define kResponseErr -6712
-#define kChecksumErr -6713
-#define kNotHandledErr -6714
-#define kVersionErr -6715
-#define kSignatureErr -6716
-#define kFormatErr -6717
-#define kNotInitializedErr -6718
-#define kAlreadyInitializedErr -6719
-#define kNotInUseErr -6720
-#define kInUseErr -6721
-#define kTimeoutErr -6722
-#define kCanceledErr -6723
-#define kAlreadyCanceledErr -6724
-#define kCannotCancelErr -6725
-#define kDeletedErr -6726
-#define kNotFoundErr -6727
-#define kNoMemoryErr -6728
-#define kNoResourcesErr -6729
-#define kDuplicateErr -6730
-#define kImmutableErr -6731
-#define kUnsupportedDataErr -6732
-#define kIntegrityErr -6733
-#define kIncompatibleErr -6734
-#define kUnsupportedErr -6735
-#define kUnexpectedErr -6736
-#define kValueErr -6737
-#define kNotReadableErr -6738
-#define kNotWritableErr -6739
-#define kBadReferenceErr -6740
-#define kFlagErr -6741
-#define kMalformedErr -6742
-#define kSizeErr -6743
-#define kNameErr -6744
-#define kNotReadyErr -6745
-#define kReadErr -6746
-#define kWriteErr -6747
-#define kMismatchErr -6748
-#define kDateErr -6749
-#define kUnderrunErr -6750
-#define kOverrunErr -6751
-#define kEndingErr -6752
-#define kConnectionErr -6753
-#define kAuthenticationErr -6754
-#define kOpenErr -6755
-#define kTypeErr -6756
-#define kSkipErr -6757
-#define kNoAckErr -6758
-#define kCollisionErr -6759
-#define kBackoffErr -6760
-#define kNoAddressAckErr -6761
-#define kBusyErr -6762
-#define kNoSpaceErr -6763
-
-#define kGenericErrorEnd -6779 // Last generic error code (inclusive)
-
-#if 0
-#pragma mark == Mac Compatibility ==
-#endif
-
-
-// Mac Compatibility
-
-
-
-/*! @enum Duration
-
- @abstract Type used to specify a duration of time.
-
- @constant kDurationImmediate Indicates no delay/wait time.
- @constant kDurationMicrosecond Microsecond units.
- @constant kDurationMillisecond Millisecond units.
- @constant kDurationSecond Second units.
- @constant kDurationMinute Minute units.
- @constant kDurationHour Hour units.
- @constant kDurationDay Day units.
- @constant kDurationForever Infinite period of time (no timeout).
-
- @discussion
-
- Duration values are intended to be multiplied by the specific interval to achieve an actual duration. For example,
- to wait for 5 seconds you would use "5 * kDurationSecond".
- */
-
-#if ( TARGET_LANGUAGE_C_LIKE )
- #if ( !TARGET_OS_MAC )
-typedef int32_t Duration;
- #endif
-#endif
-
-#define kDurationImmediate 0L
-#define kDurationMicrosecond -1L
-#define kDurationMillisecond 1L
-#define kDurationSecond ( 1000L * kDurationMillisecond )
-#define kDurationMinute ( 60L * kDurationSecond )
-#define kDurationHour ( 60L * kDurationMinute )
-#define kDurationDay ( 24L * kDurationHour )
-#define kDurationForever 0x7FFFFFFFL
-
-// Seconds <-> Minutes <-> Hours <-> Days <-> Weeks <-> Months <-> Years conversions
-
-#define kSecondsPerHour ( 60 * 60 ) // 3600
-#define kSecondsPerDay ( 60 * 60 * 24 ) // 86400
-#define kSecondsPerWeek ( 60 * 60 * 24 * 7 ) // 604800
-#define kMinutesPerDay ( 60 * 24 ) // 1440
-
-
-/*! @defined VersionStages
-
- @abstract NumVersion-style version stages.
- */
-
-#define kVersionStageDevelopment 0x20
-#define kVersionStageAlpha 0x40
-#define kVersionStageBeta 0x60
-#define kVersionStageFinal 0x80
-
-
-/*! @function NumVersionBuild
-
- @abstract Builds a 32-bit Mac-style NumVersion value (e.g. NumVersionBuild( 1, 2, 3, kVersionStageBeta, 4 ) -> 1.2.3b4).
- */
-
-#define NumVersionBuild( MAJOR, MINOR, BUGFIX, STAGE, REV ) \
- ( ( ( ( MAJOR ) & 0xFF ) << 24 ) | \
- ( ( ( MINOR ) & 0x0F ) << 20 ) | \
- ( ( ( BUGFIX ) & 0x0F ) << 16 ) | \
- ( ( ( STAGE ) & 0xFF ) << 8 ) | \
- ( ( ( REV ) & 0xFF ) ) )
-
-#define NumVersionExtractMajor( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 24 ) & 0xFF ) )
-#define NumVersionExtractMinorAndBugFix( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 16 ) & 0xFF ) )
-#define NumVersionExtractMinor( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 20 ) & 0x0F ) )
-#define NumVersionExtractBugFix( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 16 ) & 0x0F ) )
-#define NumVersionExtractStage( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 8 ) & 0xFF ) )
-#define NumVersionExtractRevision( VERSION ) ( (uint8_t)( ( VERSION ) & 0xFF ) )
-
-
-/*! @function NumVersionCompare
-
- @abstract Compares two NumVersion values and returns the following values:
-
- left < right -> -1
- left > right -> 1
- left = right -> 0
- */
-
-#if ( TARGET_LANGUAGE_C_LIKE )
-int NumVersionCompare( uint32_t inLeft, uint32_t inRight );
-#endif
-
-#if 0
-#pragma mark == Binary Constants ==
-#endif
-
-
-/*! @defined binary_4
-
- @abstract Macro to generate an 4-bit constant using binary notation (e.g. binary_4( 1010 ) == 0xA).
- */
-
-#define binary_4( a ) binary_4_hex_wrap( hex_digit4( a ) )
-#define binary_4_hex_wrap( a ) binary_4_hex( a )
-#define binary_4_hex( a ) ( 0x ## a )
-
-
-/*! @defined binary_8
-
- @abstract Macro to generate an 8-bit constant using binary notation (e.g. binary_8( 01111011 ) == 0x7B).
- */
-
-#define binary_8( a ) binary_8_hex_wrap( hex_digit8( a ) )
-#define binary_8_hex_wrap( a ) binary_8_hex( a )
-#define binary_8_hex( a ) ( 0x ## a )
-
-
-/*! @defined binary_16
-
- @abstract Macro to generate an 16-bit constant using binary notation (e.g. binary_16( 01111011, 01111011 ) == 0x7B7B).
- */
-
-#define binary_16( a, b ) binary_16_hex_wrap( hex_digit8( a ), hex_digit8( b ) )
-#define binary_16_hex_wrap( a, b ) binary_16_hex( a, b )
-#define binary_16_hex( a, b ) ( 0x ## a ## b )
-
-
-/*! @defined binary_32
-
- @abstract Macro to generate an 32-bit constant using binary notation
- (e.g. binary_32( 01111011, 01111011, 01111011, 01111011 ) == 0x7B7B7B7B).
- */
-
-#define binary_32( a, b, c, d ) binary_32_hex_wrap( hex_digit8( a ), hex_digit8( b ), hex_digit8( c ), hex_digit8( d ) )
-#define binary_32_hex_wrap( a, b, c, d ) binary_32_hex( a, b, c, d )
-#define binary_32_hex( a, b, c, d ) ( 0x ## a ## b ## c ## d )
-
-// Binary Constant Helpers
-
-#define hex_digit8( a ) HEX_DIGIT_ ## a
-#define hex_digit4( a ) HEX_DIGIT_ ## 0000 ## a
-
-
-#if 0
-#pragma mark == Debugging ==
-#endif
-
-
-/*! @function CommonServicesTest
-
- @abstract Unit test.
- */
-
-#if ( DEBUG )
- #if ( TARGET_LANGUAGE_C_LIKE )
-OSStatus CommonServicesTest( void );
- #endif
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __COMMON_SERVICES__
diff --git a/sd/source/ui/remotecontrol/mDNSResponder/DebugServices.c b/sd/source/ui/remotecontrol/mDNSResponder/DebugServices.c
deleted file mode 100644
index 7f57d88..0000000
--- a/sd/source/ui/remotecontrol/mDNSResponder/DebugServices.c
+++ /dev/null
@@ -1,2978 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-
- To Do:
-
- - Use StackWalk on Windows to optionally print stack frames.
- */
-
-#if 0
-#pragma mark == Includes ==
-#endif
-
-
-// Includes
-#if ( !KERNEL )
- #include <ctype.h>
- #include <stdio.h>
- #include <string.h>
-#endif
-
-#include "CommonServices.h"
-
-#include "DebugServices.h"
-
-#if ( DEBUG )
-
-#if ( TARGET_OS_VXWORKS )
- #include "intLib.h"
-#endif
-
-#if ( TARGET_OS_WIN32 )
- #include <time.h>
-
- #if ( !TARGET_OS_WINDOWS_CE )
- #include <fcntl.h>
- #include <io.h>
- #endif
-#endif
-
-#if ( DEBUG_IDEBUG_ENABLED && TARGET_API_MAC_OSX_KERNEL )
- #include <IOKit/IOLib.h>
-#endif
-
-// If MDNS_DEBUGMSGS is defined (even if defined 0), it is aware of mDNS and it is probably safe to include mDNSEmbeddedAPI.h.
-#if ( defined( MDNS_DEBUGMSGS ) )
- #include "mDNSEmbeddedAPI.h"
-#endif
-
-#if 0
-#pragma mark == Macros ==
-#endif
-
-
-// Macros
-#define DebugIsPrint( C ) ( ( ( C ) >= 0x20 ) && ( ( C ) <= 0x7E ) )
-
-#if 0
-#pragma mark == Prototypes ==
-#endif
-
-
-// Prototypes
-static OSStatus DebugPrint( DebugLevel inLevel, char *inData, size_t inSize );
-
-// fprintf
-#if ( DEBUG_FPRINTF_ENABLED )
-static OSStatus DebugFPrintFInit( DebugOutputTypeFlags inFlags, const char *inFilename );
-static void DebugFPrintFPrint( char *inData, size_t inSize );
-#endif
-
-// iDebug (Mac OS X user and kernel)
-#if ( DEBUG_IDEBUG_ENABLED )
-static OSStatus DebugiDebugInit( void );
-static void DebugiDebugPrint( char *inData, size_t inSize );
-#endif
-
-// kprintf (Mac OS X Kernel)
-#if ( DEBUG_KPRINTF_ENABLED )
-static void DebugKPrintFPrint( char *inData, size_t inSize );
-#endif
-
-// Mac OS X IOLog (Mac OS X Kernel)
-#if ( DEBUG_MAC_OS_X_IOLOG_ENABLED )
-static void DebugMacOSXIOLogPrint( char *inData, size_t inSize );
-#endif
-
-// Mac OS X Log
-#if ( TARGET_OS_MAC )
-static OSStatus DebugMacOSXLogInit( void );
-static void DebugMacOSXLogPrint( char *inData, size_t inSize );
-#endif
-
-// Windows Debugger
-#if ( TARGET_OS_WIN32 )
-static void DebugWindowsDebuggerPrint( char *inData, size_t inSize );
-#endif
-
-// Windows Event Log
-#if ( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
-static OSStatus DebugWindowsEventLogInit( const char *inName, HMODULE inModule );
-static void DebugWindowsEventLogPrint( DebugLevel inLevel, char *inData, size_t inSize );
-#endif
-
-// DebugLib support
-#if ( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
-static pascal void
-DebugAssertOutputHandler(
- OSType inComponentSignature,
- UInt32 inOptions,
- const char * inAssertionString,
- const char * inExceptionString,
- const char * inErrorString,
- const char * inFileName,
- long inLineNumber,
- void * inValue,
- ConstStr255Param inOutputMsg );
-#endif
-
-// Utilities
-static char * DebugNumVersionToString( uint32_t inVersion, char *inString );
-
-#if ( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
-static void DebugWinEnableConsole( void );
-#endif
-
-#if ( TARGET_OS_WIN32 )
-static TCHAR *
-DebugWinCharToTCharString(
- const char * inCharString,
- size_t inCharCount,
- TCHAR * outTCharString,
- size_t inTCharCountMax,
- size_t * outTCharCount );
-#endif
-
-#if 0
-#pragma mark == Globals ==
-#endif
-
-
-// Private Globals
-#if ( TARGET_OS_VXWORKS )
-// TCP States for inetstatShow.
-
-extern char ** pTcpstates; // defined in tcpLib.c
-
-const char * kDebugTCPStates[] =
-{
- "(0) TCPS_CLOSED",
- "(1) TCPS_LISTEN",
- "(2) TCPS_SYN_SENT",
- "(3) TCPS_SYN_RECEIVED",
- "(4) TCPS_ESTABLISHED",
- "(5) TCPS_CLOSE_WAIT",
- "(6) TCPS_FIN_WAIT_1",
- "(7) TCPS_CLOSING",
- "(8) TCPS_LAST_ACK",
- "(9) TCPS_FIN_WAIT_2",
- "(10) TCPS_TIME_WAIT",
-};
-#endif
-
-// General
-static bool gDebugInitialized = false;
-static DebugOutputType gDebugOutputType = kDebugOutputTypeNone;
-static DebugLevel gDebugPrintLevelMin = kDebugLevelInfo;
-static DebugLevel gDebugPrintLevelMax = kDebugLevelMax;
-static DebugLevel gDebugBreakLevel = kDebugLevelAssert;
-#if ( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
-static DebugAssertOutputHandlerUPP gDebugAssertOutputHandlerUPP = NULL;
-#endif
-
-// Custom
-static DebugOutputFunctionPtr gDebugCustomOutputFunction = NULL;
-static void * gDebugCustomOutputContext = NULL;
-
-// fprintf
-
-#if ( DEBUG_FPRINTF_ENABLED )
-static FILE * gDebugFPrintFFile = NULL;
-#endif
-
-// MacOSXLog
-#if ( TARGET_OS_MAC )
-typedef int ( *DebugMacOSXLogFunctionPtr )( const char *inFormat, ... );
-
-static DebugMacOSXLogFunctionPtr gDebugMacOSXLogFunction = NULL;
-#endif
-
-// WindowsEventLog
-#if ( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
-static HANDLE gDebugWindowsEventLogEventSource = NULL;
-#endif
-
-#if 0
-#pragma mark -
-#pragma mark == General ==
-#endif
-
-
-// DebugInitialize
-DEBUG_EXPORT OSStatus DebugInitialize( DebugOutputType inType, ... )
-{
- OSStatus err;
- DebugOutputType type;
- va_list args;
-
- va_start( args, inType );
-
-#if ( TARGET_OS_VXWORKS )
- // Set up the TCP state strings if they are not already set up by VxWorks (normally not set up for some reason).
-
- if( !pTcpstates )
- {
- pTcpstates = (char **) kDebugTCPStates;
- }
-#endif
-
- // Set up DebugLib stuff (if building with Debugging.h).
-
-#if ( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
- if( !gDebugAssertOutputHandlerUPP )
- {
- gDebugAssertOutputHandlerUPP = NewDebugAssertOutputHandlerUPP( DebugAssertOutputHandler );
- check( gDebugAssertOutputHandlerUPP );
- if( gDebugAssertOutputHandlerUPP )
- {
- InstallDebugAssertOutputHandler( gDebugAssertOutputHandlerUPP );
- }
- }
-#endif
-
- // Pre-process meta-output kind to pick an appropriate output kind for the platform.
-
- type = inType;
- if( type == kDebugOutputTypeMetaConsole )
- {
- #if ( TARGET_OS_MAC )
- type = kDebugOutputTypeMacOSXLog;
- #elif ( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- #if ( DEBUG_FPRINTF_ENABLED )
- type = kDebugOutputTypeFPrintF;
- #else
- type = kDebugOutputTypeWindowsDebugger;
- #endif
- #elif ( TARGET_API_MAC_OSX_KERNEL )
- #if ( DEBUG_MAC_OS_X_IOLOG_ENABLED )
- type = kDebugOutputTypeMacOSXIOLog;
- #elif ( DEBUG_IDEBUG_ENABLED )
- type = kDebugOutputTypeiDebug;
- #elif ( DEBUG_KPRINTF_ENABLED )
- type = kDebugOutputTypeKPrintF;
- #endif
- #elif ( TARGET_OS_VXWORKS )
- #if ( DEBUG_FPRINTF_ENABLED )
- type = kDebugOutputTypeFPrintF;
- #else
- #error target is VxWorks, but fprintf output is disabled
- #endif
- #else
- #if ( DEBUG_FPRINTF_ENABLED )
- type = kDebugOutputTypeFPrintF;
- #endif
- #endif
- }
-
- // Process output kind
- gDebugOutputType = type;
- switch( type )
- {
- case kDebugOutputTypeNone:
- err = kNoErr;
- break;
-
- case kDebugOutputTypeCustom:
- gDebugCustomOutputFunction = va_arg( args, DebugOutputFunctionPtr );
- gDebugCustomOutputContext = va_arg( args, void * );
- err = kNoErr;
- break;
-
-#if ( DEBUG_FPRINTF_ENABLED )
- case kDebugOutputTypeFPrintF:
- if( inType == kDebugOutputTypeMetaConsole )
- {
- err = DebugFPrintFInit( kDebugOutputTypeFlagsStdErr, NULL );
- }
- else
- {
- DebugOutputTypeFlags flags;
- const char * filename;
-
- flags = (DebugOutputTypeFlags) va_arg( args, unsigned int );
- if( ( flags & kDebugOutputTypeFlagsTypeMask ) == kDebugOutputTypeFlagsFile )
- {
- filename = va_arg( args, const char * );
- }
- else
- {
- filename = NULL;
- }
- err = DebugFPrintFInit( flags, filename );
- }
- break;
-#endif
-
-#if ( DEBUG_IDEBUG_ENABLED )
- case kDebugOutputTypeiDebug:
- err = DebugiDebugInit();
- break;
-#endif
-
-#if ( DEBUG_KPRINTF_ENABLED )
- case kDebugOutputTypeKPrintF:
- err = kNoErr;
- break;
-#endif
-
-#if ( DEBUG_MAC_OS_X_IOLOG_ENABLED )
- case kDebugOutputTypeMacOSXIOLog:
- err = kNoErr;
- break;
-#endif
-
-#if ( TARGET_OS_MAC )
- case kDebugOutputTypeMacOSXLog:
- err = DebugMacOSXLogInit();
- break;
-#endif
-
-#if ( TARGET_OS_WIN32 )
- case kDebugOutputTypeWindowsDebugger:
- err = kNoErr;
- break;
-#endif
-
-#if ( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- case kDebugOutputTypeWindowsEventLog:
- {
- const char * name;
- HMODULE module;
-
- name = va_arg( args, const char * );
- module = va_arg( args, HMODULE );
- err = DebugWindowsEventLogInit( name, module );
- }
- break;
-#endif
-
- default:
- err = kParamErr;
- goto exit;
- }
- gDebugInitialized = true;
-
-exit:
- va_end( args );
- return err;
-}
-
-
-// DebugFinalize
-DEBUG_EXPORT void DebugFinalize( void )
-{
-#if ( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
- check( gDebugAssertOutputHandlerUPP );
- if( gDebugAssertOutputHandlerUPP )
- {
- InstallDebugAssertOutputHandler( NULL );
- DisposeDebugAssertOutputHandlerUPP( gDebugAssertOutputHandlerUPP );
- gDebugAssertOutputHandlerUPP = NULL;
- }
-#endif
-}
-
-
-// DebugGetProperty
-DEBUG_EXPORT OSStatus DebugGetProperty( DebugPropertyTag inTag, ... )
-{
- OSStatus err;
- va_list args;
- DebugLevel * level;
-
- va_start( args, inTag );
- switch( inTag )
- {
- case kDebugPropertyTagPrintLevelMin:
- level = va_arg( args, DebugLevel * );
- *level = gDebugPrintLevelMin;
- err = kNoErr;
- break;
-
- case kDebugPropertyTagPrintLevelMax:
- level = va_arg( args, DebugLevel * );
- *level = gDebugPrintLevelMax;
- err = kNoErr;
- break;
-
- case kDebugPropertyTagBreakLevel:
- level = va_arg( args, DebugLevel * );
- *level = gDebugBreakLevel;
- err = kNoErr;
- break;
-
- default:
- err = kUnsupportedErr;
- break;
- }
- va_end( args );
- return err;
-}
-
-
-// DebugSetProperty
-DEBUG_EXPORT OSStatus DebugSetProperty( DebugPropertyTag inTag, ... )
-{
- OSStatus err;
- va_list args;
- DebugLevel level;
-
- va_start( args, inTag );
- switch( inTag )
- {
- case kDebugPropertyTagPrintLevelMin:
- level = va_arg( args, DebugLevel );
- gDebugPrintLevelMin = level;
- err = kNoErr;
- break;
-
- case kDebugPropertyTagPrintLevelMax:
- level = va_arg( args, DebugLevel );
- gDebugPrintLevelMax = level;
- err = kNoErr;
- break;
-
- case kDebugPropertyTagBreakLevel:
- level = va_arg( args, DebugLevel );
- gDebugBreakLevel = level;
- err = kNoErr;
- break;
-
- default:
- err = kUnsupportedErr;
- break;
- }
- va_end( args );
- return err;
-}
-
-#if 0
-#pragma mark -
-#pragma mark == Output ==
-#endif
-
-
-// DebugPrintF
-DEBUG_EXPORT size_t DebugPrintF( DebugLevel inLevel, const char *inFormat, ... )
-{
- va_list args;
- size_t n;
-
- // Skip if the level is not in the enabled range..
-
- if( ( inLevel < gDebugPrintLevelMin ) || ( inLevel > gDebugPrintLevelMax ) )
- {
- n = 0;
- goto exit;
- }
-
- va_start( args, inFormat );
- n = DebugPrintFVAList( inLevel, inFormat, args );
- va_end( args );
-
-exit:
- return n;
-}
-
-
-// DebugPrintFVAList
-DEBUG_EXPORT size_t DebugPrintFVAList( DebugLevel inLevel, const char *inFormat, va_list inArgs )
-{
- size_t n;
- char buffer[ 512 ];
-
- // Skip if the level is not in the enabled range..
-
- if( ( inLevel < gDebugPrintLevelMin ) || ( inLevel > gDebugPrintLevelMax ) )
- {
- n = 0;
- goto exit;
- }
-
- n = DebugSNPrintFVAList( buffer, sizeof( buffer ), inFormat, inArgs );
- DebugPrint( inLevel, buffer, (size_t) n );
-
-exit:
- return n;
-}
-
-
-// DebugPrint
-static OSStatus DebugPrint( DebugLevel inLevel, char *inData, size_t inSize )
-{
- OSStatus err;
-
- // Skip if the level is not in the enabled range..
-
- if( ( inLevel < gDebugPrintLevelMin ) || ( inLevel > gDebugPrintLevelMax ) )
- {
- err = kRangeErr;
- goto exit;
- }
-
- // Printing is not safe at interrupt time so check for this and warn with an interrupt safe mechanism (if available).
-
- if( DebugTaskLevel() & kDebugInterruptLevelMask )
- {
- #if ( TARGET_OS_VXWORKS )
- logMsg( "\ncannot print at interrupt time\n\n", 1, 2, 3, 4, 5, 6 );
- #endif
-
- err = kExecutionStateErr;
- goto exit;
- }
-
- // Initialize the debugging library if it hasn't already been initialized (allows for zero-config usage).
-
- if( !gDebugInitialized )
- {
- debug_initialize( kDebugOutputTypeMetaConsole );
- }
-
- // Print based on the current output type.
-
- switch( gDebugOutputType )
- {
- case kDebugOutputTypeNone:
- break;
-
- case kDebugOutputTypeCustom:
- if( gDebugCustomOutputFunction )
- {
- gDebugCustomOutputFunction( inData, inSize, gDebugCustomOutputContext );
- }
- break;
-
-#if ( DEBUG_FPRINTF_ENABLED )
- case kDebugOutputTypeFPrintF:
- DebugFPrintFPrint( inData, inSize );
- break;
-#endif
-
-#if ( DEBUG_IDEBUG_ENABLED )
- case kDebugOutputTypeiDebug:
- DebugiDebugPrint( inData, inSize );
- break;
-#endif
-
-#if ( DEBUG_KPRINTF_ENABLED )
- case kDebugOutputTypeKPrintF:
- DebugKPrintFPrint( inData, inSize );
- break;
-#endif
-
-#if ( DEBUG_MAC_OS_X_IOLOG_ENABLED )
- case kDebugOutputTypeMacOSXIOLog:
- DebugMacOSXIOLogPrint( inData, inSize );
- break;
-#endif
-
-#if ( TARGET_OS_MAC )
- case kDebugOutputTypeMacOSXLog:
- DebugMacOSXLogPrint( inData, inSize );
- break;
-#endif
-
-#if ( TARGET_OS_WIN32 )
- case kDebugOutputTypeWindowsDebugger:
- DebugWindowsDebuggerPrint( inData, inSize );
- break;
-#endif
-
-#if ( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- case kDebugOutputTypeWindowsEventLog:
- DebugWindowsEventLogPrint( inLevel, inData, inSize );
- break;
-#endif
-
- default:
- break;
- }
- err = kNoErr;
-
-exit:
- return err;
-}
-
-
-// DebugPrintAssert
-
-// Warning: This routine relies on several of the strings being string constants that will exist forever because the
-// underlying logMsg API that does the printing is asynchronous so it cannot use temporary/stack-based
-// pointer variables (e.g. local strings). The debug macros that invoke this function only use constant
-// constant strings, but if this function is invoked directly from other places, it must use constant strings.
-DEBUG_EXPORT void
-DebugPrintAssert(
- int_least32_t inErrorCode,
- const char * inAssertString,
- const char * inMessage,
- const char * inFilename,
- int_least32_t inLineNumber,
- const char * inFunction )
-{
- // Skip if the level is not in the enabled range..
- if( ( kDebugLevelAssert < gDebugPrintLevelMin ) || ( kDebugLevelAssert > gDebugPrintLevelMax ) )
- {
- return;
- }
-
- if( inErrorCode != 0 )
- {
- DebugPrintF(
- kDebugLevelAssert,
- "\n"
- "[ASSERT] error: %ld (%m)\n"
- "[ASSERT] where: \"%s\", line %ld, \"%s\"\n"
- "\n",
- inErrorCode, inErrorCode,
- inFilename ? inFilename : "",
- inLineNumber,
- inFunction ? inFunction : "" );
- }
- else
- {
- DebugPrintF(
- kDebugLevelAssert,
- "\n"
- "[ASSERT] assert: \"%s\" %s\n"
- "[ASSERT] where: \"%s\", line %ld, \"%s\"\n"
- "\n",
- inAssertString ? inAssertString : "",
- inMessage ? inMessage : "",
- inFilename ? inFilename : "",
- inLineNumber,
- inFunction ? inFunction : "" );
- }
-
- // Break into the debugger if enabled
- #if ( TARGET_OS_WIN32 )
- if( gDebugBreakLevel <= kDebugLevelAssert )
- {
- if( IsDebuggerPresent() )
- {
- DebugBreak();
- }
- }
- #endif
-}
-
-#if 0
-#pragma mark -
-#endif
-
-#if ( DEBUG_FPRINTF_ENABLED )
-
-// DebugFPrintFInit
-static OSStatus DebugFPrintFInit( DebugOutputTypeFlags inFlags, const char *inFilename )
-{
- OSStatus err;
- DebugOutputTypeFlags typeFlags;
-
- typeFlags = inFlags & kDebugOutputTypeFlagsTypeMask;
- if( typeFlags == kDebugOutputTypeFlagsStdOut )
- {
- #if ( TARGET_OS_WIN32 )
- DebugWinEnableConsole();
- #endif
-
- gDebugFPrintFFile = stdout;
- }
- else if( typeFlags == kDebugOutputTypeFlagsStdErr )
- {
- #if ( TARGET_OS_WIN32 )
- DebugWinEnableConsole();
- #endif
-
- gDebugFPrintFFile = stdout;
- }
- else if( typeFlags == kDebugOutputTypeFlagsFile )
- {
- require_action_quiet( inFilename && ( *inFilename != '\0' ), exit, err = kOpenErr );
-
- gDebugFPrintFFile = fopen( inFilename, "a" );
- require_action_quiet( gDebugFPrintFFile, exit, err = kOpenErr );
- }
- else
- {
- err = kParamErr;
- goto exit;
- }
- err = kNoErr;
-
-exit:
- return err;
-}
-
-
-// DebugFPrintFPrint
-static void DebugFPrintFPrint( char *inData, size_t inSize )
-{
- char * p;
- char * q;
-
- // Convert \r to \n. fprintf will interpret \n and convert to whatever is appropriate for the platform.
- p = inData;
- q = p + inSize;
- while( p < q )
- {
- if( *p == '\r' )
- {
- *p = '\n';
- }
- ++p;
- }
-
- // Write the data and flush.
- if( gDebugFPrintFFile )
- {
- fprintf( gDebugFPrintFFile, "%.*s", (int) inSize, inData );
- fflush( gDebugFPrintFFile );
- }
-}
-#endif // DEBUG_FPRINTF_ENABLED
-
-#if ( DEBUG_IDEBUG_ENABLED )
-
-// DebugiDebugInit
-static OSStatus DebugiDebugInit( void )
-{
- OSStatus err;
-
- #if ( TARGET_API_MAC_OSX_KERNEL )
-
- extern uint32_t * _giDebugReserved1;
-
- // Emulate the iDebugSetOutputType macro in iDebugServices.h.
- // Note: This is not thread safe, but neither is iDebugServices.h nor iDebugKext.
- if( !_giDebugReserved1 )
- {
- _giDebugReserved1 = (uint32_t *) IOMalloc( sizeof( uint32_t ) );
- require_action_quiet( _giDebugReserved1, exit, err = kNoMemoryErr );
- }
- *_giDebugReserved1 = 0x00010000U;
- err = kNoErr;
-exit:
- #else
-
- __private_extern__ void iDebugSetOutputTypeInternal( uint32_t inType );
-
- iDebugSetOutputTypeInternal( 0x00010000U );
- err = kNoErr;
-
- #endif
-
- return err;
-}
-
-
-// DebugiDebugPrint
-static void DebugiDebugPrint( char *inData, size_t inSize )
-{
- #if ( TARGET_API_MAC_OSX_KERNEL )
-
- // Locally declared here so we do not need to include iDebugKext.h.
- // Note: IOKit uses a global namespace for all code and only a partial link occurs at build time. When the
- // KEXT is loaded, the runtime linker will link in this extern'd symbol (assuming iDebug is present).
- // _giDebugLogInternal is actually part of IOKit proper so this should link even if iDebug is not present.
-
- typedef void ( *iDebugLogFunctionPtr )( uint32_t inLevel, uint32_t inTag, const char *inFormat, ... );
-
- extern iDebugLogFunctionPtr _giDebugLogInternal;
-
- if( _giDebugLogInternal )
- {
- _giDebugLogInternal( 0, 0, "%.*s", (int) inSize, inData );
- }
-
- #else
-
- __private_extern__ void iDebugLogInternal( uint32_t inLevel, uint32_t inTag, const char *inFormat, ... );
-
- iDebugLogInternal( 0, 0, "%.*s", (int) inSize, inData );
-
- #endif
-}
-#endif
-
-#if ( DEBUG_KPRINTF_ENABLED )
-
-// DebugKPrintFPrint
-static void DebugKPrintFPrint( char *inData, size_t inSize )
-{
- extern void kprintf( const char *inFormat, ... );
-
- kprintf( "%.*s", (int) inSize, inData );
-}
-#endif
-
-#if ( DEBUG_MAC_OS_X_IOLOG_ENABLED )
-
-// DebugMacOSXIOLogPrint
-static void DebugMacOSXIOLogPrint( char *inData, size_t inSize )
-{
- extern void IOLog( const char *inFormat, ... );
-
- IOLog( "%.*s", (int) inSize, inData );
-}
-#endif
-
-#if ( TARGET_OS_MAC )
-
-// DebugMacOSXLogInit
-static OSStatus DebugMacOSXLogInit( void )
-{
- OSStatus err;
- CFStringRef path;
- CFURLRef url;
- CFBundleRef bundle;
- CFStringRef functionName;
- void * functionPtr;
-
- bundle = NULL;
-
- // Create a bundle reference for System.framework.
-
- path = CFSTR( "/System/Library/Frameworks/System.framework" );
- url = CFURLCreateWithFileSystemPath( NULL, path, kCFURLPOSIXPathStyle, true );
- require_action_quiet( url, exit, err = memFullErr );
-
- bundle = CFBundleCreate( NULL, url );
- CFRelease( url );
- require_action_quiet( bundle, exit, err = memFullErr );
-
- // Get a ptr to the system's "printf" function from System.framework.
-
- functionName = CFSTR( "printf" );
- functionPtr = CFBundleGetFunctionPointerForName( bundle, functionName );
- require_action_quiet( functionPtr, exit, err = memFullErr );
-
- // Success! Note: The bundle cannot be released because it would invalidate the function ptr.
-
- gDebugMacOSXLogFunction = (DebugMacOSXLogFunctionPtr) functionPtr;
- bundle = NULL;
- err = noErr;
-
-exit:
- if( bundle )
- {
- CFRelease( bundle );
- }
- return err;
-}
-
-// DebugMacOSXLogPrint
-static void DebugMacOSXLogPrint( char *inData, size_t inSize )
-{
- if( gDebugMacOSXLogFunction )
- {
- gDebugMacOSXLogFunction( "%.*s", (int) inSize, inData );
- }
-}
-#endif
-
-#if ( TARGET_OS_WIN32 )
-
-// DebugWindowsDebuggerPrint
-void DebugWindowsDebuggerPrint( char *inData, size_t inSize )
-{
- TCHAR buffer[ 512 ];
- const char * src;
- const char * end;
- TCHAR * dst;
- char c;
-
- // Copy locally and null terminate the string. This also converts from char to TCHAR in case we are
- // building with UNICODE enabled since the input is always char. Also convert \r to \n in the process.
- src = inData;
- if( inSize >= sizeof_array( buffer ) )
- {
- inSize = sizeof_array( buffer ) - 1;
- }
- end = src + inSize;
- dst = buffer;
- while( src < end )
- {
- c = *src++;
- if( c == '\r' )
- {
- c = '\n';
- }
- *dst++ = (TCHAR) c;
- }
- *dst = 0;
-
- // Print out the string to the debugger.
- OutputDebugString( buffer );
-}
-#endif
-
-#if ( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
-
-// DebugWindowsEventLogInit
-static OSStatus DebugWindowsEventLogInit( const char *inName, HMODULE inModule )
-{
- OSStatus err;
- HKEY key;
- TCHAR name[ 128 ];
- const char * src;
- TCHAR path[ MAX_PATH ];
- size_t size;
- DWORD typesSupported;
- DWORD n;
-
- key = NULL;
-
- // Use a default name if needed then convert the name to TCHARs so it works on ANSI or Unicode builds.
- if( !inName || ( *inName == '\0' ) )
- {
- inName = "DefaultApp";
- }
- DebugWinCharToTCharString( inName, kSizeCString, name, sizeof( name ), NULL );
-
- // Build the path string using the fixed registry path and app name.
- src = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\";
- DebugWinCharToTCharString( src, kSizeCString, path, sizeof_array( path ), &size );
- DebugWinCharToTCharString( inName, kSizeCString, path + size, sizeof_array( path ) - size, NULL );
-
- // Add/Open the source name as a sub-key under the Application key in the EventLog registry key.
- err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL );
- require_noerr_quiet( err, exit );
-
- // Set the path in the EventMessageFile subkey. Add 1 to the TCHAR count to include the null terminator.
- n = GetModuleFileName( inModule, path, sizeof_array( path ) );
- err = translate_errno( n > 0, (OSStatus) GetLastError(), kParamErr );
- require_noerr_quiet( err, exit );
- n += 1;
- n *= sizeof( TCHAR );
-
- err = RegSetValueEx( key, TEXT( "EventMessageFile" ), 0, REG_EXPAND_SZ, (const LPBYTE) path, n );
- require_noerr_quiet( err, exit );
-
- // Set the supported event types in the TypesSupported subkey.
- typesSupported = EVENTLOG_SUCCESS | EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE |
- EVENTLOG_AUDIT_SUCCESS | EVENTLOG_AUDIT_FAILURE;
- err = RegSetValueEx( key, TEXT( "TypesSupported" ), 0, REG_DWORD, (const LPBYTE) &typesSupported, sizeof( DWORD ) );
- require_noerr_quiet( err, exit );
-
- // Set up the event source.
- gDebugWindowsEventLogEventSource = RegisterEventSource( NULL, name );
- err = translate_errno( gDebugWindowsEventLogEventSource, (OSStatus) GetLastError(), kParamErr );
- require_noerr_quiet( err, exit );
-
-exit:
- if( key )
- {
- RegCloseKey( key );
- }
- return err;
-}
-
-
-// DebugWindowsEventLogPrint
-static void DebugWindowsEventLogPrint( DebugLevel inLevel, char *inData, size_t inSize )
-{
- WORD type;
- TCHAR buffer[ 512 ];
- const char * src;
- const char * end;
- TCHAR * dst;
- char c;
- const TCHAR * array[ 1 ];
-
- // Map the debug level to a Windows EventLog type
- if( inLevel <= kDebugLevelNotice )
- {
- type = EVENTLOG_INFORMATION_TYPE;
- }
- else if( inLevel <= kDebugLevelWarning )
- {
- type = EVENTLOG_WARNING_TYPE;
- }
- else
- {
- type = EVENTLOG_ERROR_TYPE;
- }
-
- // Copy locally and null terminate the string. This also converts from char to TCHAR in case we are
- // building with UNICODE enabled since the input is always char. Also convert \r to \n in the process.
- src = inData;
- if( inSize >= sizeof_array( buffer ) )
- {
- inSize = sizeof_array( buffer ) - 1;
- }
- end = src + inSize;
- dst = buffer;
- while( src < end )
- {
- c = *src++;
- if( c == '\r' )
- {
- c = '\n';
- }
- *dst++ = (TCHAR) c;
- }
- *dst = 0;
-
- // Add the string to the event log.
- array[ 0 ] = buffer;
- if( gDebugWindowsEventLogEventSource )
- {
- ReportEvent( gDebugWindowsEventLogEventSource, type, 0, 0x20000001L, NULL, 1, 0, array, NULL );
- }
-}
-#endif // TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE
-
-#if ( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
-
-// DebugAssertOutputHandler
-static pascal void
-DebugAssertOutputHandler(
- OSType inComponentSignature,
- UInt32 inOptions,
- const char * inAssertString,
- const char * inExceptionString,
- const char * inErrorString,
- const char * inFileName,
- long inLineNumber,
- void * inValue,
- ConstStr255Param inOutputMsg )
-{
- DEBUG_UNUSED( inComponentSignature );
- DEBUG_UNUSED( inOptions );
- DEBUG_UNUSED( inExceptionString );
- DEBUG_UNUSED( inValue );
- DEBUG_UNUSED( inOutputMsg );
-
- DebugPrintAssert( 0, inAssertString, inErrorString, inFileName, (int_least32_t) inLineNumber, "" );
-}
-#endif
-
-#if 0
-#pragma mark -
-#pragma mark == Utilities ==
-#endif
-
-
-// DebugSNPrintF
-
-// Stolen from mDNS.c's mDNS_snprintf/mDNS_vsnprintf with the following changes:
-
-// Changed names to avoid name collisions with the mDNS versions.
-// Changed types to standard C types since mDNSEmbeddedAPI.h may not be available.
-// Conditionalized mDNS stuff so it can be used with or with mDNSEmbeddedAPI.h.
-// Added 64-bit support for %d (%lld), %i (%lli), %u (%llu), %o (%llo), %x (%llx), and %b (%llb).
-// Added %@ - Cocoa/CoreFoundation object. Param is the object. Strings are used directly. Others use CFCopyDescription.
-// Added %.8a - FIbre Channel address. Arg=ptr to address.
-// Added %##a - IPv4 (if AF_INET defined) or IPv6 (if AF_INET6 defined) sockaddr. Arg=ptr to sockaddr.
-// Added %b - Binary representation of integer (e.g. 01101011). Modifiers and arg=the same as %d, %x, etc.
-// Added %C - Mac-style FourCharCode (e.g. 'APPL'). Arg=32-bit value to print as a Mac-style FourCharCode.
-// Added %H - Hex Dump (e.g. "\x6b\xa7" -> "6B A7"). 1st arg=ptr, 2nd arg=size, 3rd arg=max size.
-// Added %#H - Hex Dump & ASCII (e.g. "\x41\x62" -> "6B A7 'Ab'"). 1st arg=ptr, 2nd arg=size, 3rd arg=max size.
-// Added %m - Error Message (e.g. 0 -> "kNoErr"). Modifiers and error code args are the same as %d, %x, etc.
-// Added %S - UTF-16 string. Host order if no BOM. Precision is UTF-16 char count. BOM counts in any precision. Arg=ptr.
-// Added %#S - Big Endian UTF-16 string (unless BOM overrides). Otherwise the same as %S.
-// Added %##S - Little Endian UTF-16 string (unless BOM overrides). Otherwise the same as %S.
-// Added %U - Universally Unique Identifier (UUID) (e.g. 6ba7b810-9dad-11d1-80b4-00c04fd430c8). Arg=ptr to 16-byte UUID.
-
-
-DEBUG_EXPORT size_t DebugSNPrintF(char *sbuffer, size_t buflen, const char *fmt, ...)
-{
- size_t length;
-
- va_list ptr;
- va_start(ptr,fmt);
- length = DebugSNPrintFVAList(sbuffer, buflen, fmt, ptr);
- va_end(ptr);
-
- return length;
-}
-
-
-// DebugSNPrintFVAList - va_list version of DebugSNPrintF. See DebugSNPrintF for more info.
-DEBUG_EXPORT size_t DebugSNPrintFVAList(char *sbuffer, size_t buflen, const char *fmt, va_list arg)
-{
- static const struct DebugSNPrintF_format
- {
- unsigned leftJustify : 1;
- unsigned forceSign : 1;
- unsigned zeroPad : 1;
- unsigned havePrecision : 1;
- unsigned hSize : 1;
- char lSize;
- char altForm;
- char sign; // +, - or space
- unsigned int fieldWidth;
- unsigned int precision;
- } DebugSNPrintF_format_default = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
- size_t nwritten = 0;
- int c;
- if (buflen == 0) return 0;
- buflen--; // Pre-reserve one space in the buffer for the terminating nul
- if (buflen == 0) goto exit;
-
- for (c = *fmt; c != 0; c = *++fmt)
- {
- if (c != '%')
- {
- *sbuffer++ = (char)c;
- if (++nwritten >= buflen) goto exit;
- }
- else
- {
- size_t i=0, j;
- // The mDNS Vsprintf Argument Conversion Buffer is used as a temporary holding area for
- // generating decimal numbers, hexdecimal numbers, IP addresses, domain name strings, etc.
- // The size needs to be enough for a 256-byte domain name plus some error text.
- #define mDNS_VACB_Size 300
- char mDNS_VACB[mDNS_VACB_Size];
- #define mDNS_VACB_Lim (&mDNS_VACB[mDNS_VACB_Size])
- #define mDNS_VACB_Remain(s) ((size_t)(mDNS_VACB_Lim - s))
- char *s = mDNS_VACB_Lim;
- const char *digits = "0123456789ABCDEF";
- struct DebugSNPrintF_format F = DebugSNPrintF_format_default;
-
- for(;;) // decode flags
- {
- c = *++fmt;
- if (c == '-') F.leftJustify = 1;
- else if (c == '+') F.forceSign = 1;
- else if (c == ' ') F.sign = ' ';
- else if (c == '#') F.altForm++;
- else if (c == '0') F.zeroPad = 1;
- else break;
- }
-
- if (c == '*') // decode field width
- {
- int f = va_arg(arg, int);
- if (f < 0) { f = -f; F.leftJustify = 1; }
- F.fieldWidth = (unsigned int)f;
- c = *++fmt;
- }
- else
- {
- for (; c >= '0' && c <= '9'; c = *++fmt)
- F.fieldWidth = (10 * F.fieldWidth) + (c - '0');
- }
-
- if (c == '.') // decode precision
- {
- if ((c = *++fmt) == '*')
- { F.precision = va_arg(arg, unsigned int); c = *++fmt; }
- else for (; c >= '0' && c <= '9'; c = *++fmt)
- F.precision = (10 * F.precision) + (c - '0');
- F.havePrecision = 1;
- }
-
- if (F.leftJustify) F.zeroPad = 0;
-
-conv:
- switch (c) // perform appropriate conversion
- {
- #if TYPE_LONGLONG_NATIVE
- unsigned_long_long_compat n;
- unsigned_long_long_compat base;
- #else
- unsigned long n;
- unsigned long base;
- #endif
- case 'h': F.hSize = 1; c = *++fmt; goto conv;
- case 'l': // fall through
- case 'L': F.lSize++; c = *++fmt; goto conv;
- case 'd':
- case 'i': base = 10;
- goto canBeSigned;
- case 'u': base = 10;
- goto notSigned;
- case 'o': base = 8;
- goto notSigned;
- case 'b': base = 2;
- goto notSigned;
- case 'p': n = va_arg(arg, uintptr_t);
- F.havePrecision = 1;
- F.precision = (sizeof(uintptr_t) == 4) ? 8 : 16;
- F.sign = 0;
- base = 16;
- c = 'x';
- goto number;
- case 'x': digits = "0123456789abcdef";
- case 'X': base = 16;
- goto notSigned;
-canBeSigned:
- #if TYPE_LONGLONG_NATIVE
- if (F.lSize == 1) n = (unsigned_long_long_compat)va_arg(arg, long);
- else if (F.lSize == 2) n = (unsigned_long_long_compat)va_arg(arg, long_long_compat);
- else n = (unsigned_long_long_compat)va_arg(arg, int);
- #else
- if (F.lSize == 1) n = (unsigned long)va_arg(arg, long);
- else if (F.lSize == 2) goto exit;
- else n = (unsigned long)va_arg(arg, int);
- #endif
- if (F.hSize) n = (short) n;
- #if TYPE_LONGLONG_NATIVE
- if ((long_long_compat) n < 0) { n = (unsigned_long_long_compat)-(long_long_compat)n; F.sign = '-'; }
- #else
- if ((long) n < 0) { n = (unsigned long)-(long)n; F.sign = '-'; }
- #endif
- else if (F.forceSign) F.sign = '+';
- goto number;
-
-notSigned: if (F.lSize == 1) n = va_arg(arg, unsigned long);
- else if (F.lSize == 2)
- {
- #if TYPE_LONGLONG_NATIVE
- n = va_arg(arg, unsigned_long_long_compat);
- #else
- goto exit;
- #endif
- }
- else n = va_arg(arg, unsigned int);
- if (F.hSize) n = (unsigned short) n;
- F.sign = 0;
- goto number;
-
-number: if (!F.havePrecision)
- {
- if (F.zeroPad)
- {
- F.precision = F.fieldWidth;
- if (F.altForm) F.precision -= 2;
- if (F.sign) --F.precision;
- }
- if (F.precision < 1) F.precision = 1;
- }
- if (F.precision > mDNS_VACB_Size - 1)
- F.precision = mDNS_VACB_Size - 1;
- for (i = 0; n; n /= base, i++) *--s = (char)(digits[n % base]);
- for (; i < F.precision; i++) *--s = '0';
- if (F.altForm) { *--s = (char)c; *--s = '0'; i += 2; }
- if (F.sign) { *--s = F.sign; i++; }
- break;
-
- case 'a': {
- unsigned char *a = va_arg(arg, unsigned char *);
- char pre[4] = "";
- char post[32] = "";
- if (!a) { static char emsg[] = "<<NULL>>"; s = emsg; i = sizeof(emsg)-1; }
- else
- {
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- if (F.altForm == 1)
- {
- #if (defined(MDNS_DEBUGMSGS))
- mDNSAddr *ip = (mDNSAddr*)a;
- switch (ip->type)
- {
- case mDNSAddrType_IPv4: F.precision = 4; a = (unsigned char *)&ip->ip.v4; break;
- case mDNSAddrType_IPv6: F.precision = 16; a = (unsigned char *)&ip->ip.v6; break;
- default: F.precision = 0; break;
- }
- #else
- F.precision = 0; // mDNSEmbeddedAPI.h not included so no mDNSAddr support
- #endif
- }
- else if (F.altForm == 2)
- {
- #ifdef AF_INET
- const struct sockaddr *sa;
- unsigned char *port;
- sa = (const struct sockaddr*)a;
- switch (sa->sa_family)
- {
- case AF_INET: F.precision = 4; a = (unsigned char*)&((const struct sockaddr_in *)a)->sin_addr;
- port = (unsigned char*)&((const struct sockaddr_in *)sa)->sin_port;
- DebugSNPrintF(post, sizeof(post), ":%d", (port[0] << 8) | port[1]); break;
- #ifdef AF_INET6
- case AF_INET6: F.precision = 16; a = (unsigned char*)&((const struct sockaddr_in6 *)a)->sin6_addr;
- pre[0] = '['; pre[1] = '\0';
- port = (unsigned char*)&((const struct sockaddr_in6 *)sa)->sin6_port;
- DebugSNPrintF(post, sizeof(post), "%%%d]:%d",
- (int)((const struct sockaddr_in6 *)sa)->sin6_scope_id,
- (port[0] << 8) | port[1]); break;
- #endif
- default: F.precision = 0; break;
- }
- #else
- F.precision = 0; // socket interfaces not included so no sockaddr support
- #endif
- }
- switch (F.precision)
- {
- case 4: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%d.%d.%d.%d%s",
- a[0], a[1], a[2], a[3], post); break;
- case 6: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%02X:%02X:%02X:%02X:%02X:%02X",
- a[0], a[1], a[2], a[3], a[4], a[5]); break;
- case 8: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
- a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]); break;
- case 16: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB),
- "%s%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X%s",
- pre, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8],
- a[9], a[10], a[11], a[12], a[13], a[14], a[15], post); break;
- default: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%s", "<< ERROR: Must specify address size "
- "(i.e. %.4a=IPv4, %.6a=Ethernet, %.8a=Fibre Channel %.16a=IPv6) >>"); break;
- }
- }
- }
- break;
-
- case 'U': {
- unsigned char *a = va_arg(arg, unsigned char *);
- if (!a) { static char emsg[] = "<<NULL>>"; s = emsg; i = sizeof(emsg)-1; }
- else
- {
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- *((uint32_t*) &a[0]), *((uint16_t*) &a[4]), *((uint16_t*) &a[6]),
- a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]); break;
- }
- }
- break;
-
- case 'c': *--s = (char)va_arg(arg, int); i = 1; break;
-
- case 'C': if (F.lSize) n = va_arg(arg, unsigned long);
- else n = va_arg(arg, unsigned int);
- if (F.hSize) n = (unsigned short) n;
- c = (int)( n & 0xFF); *--s = (char)(DebugIsPrint(c) ? c : '^');
- c = (int)((n >> 8) & 0xFF); *--s = (char)(DebugIsPrint(c) ? c : '^');
- c = (int)((n >> 16) & 0xFF); *--s = (char)(DebugIsPrint(c) ? c : '^');
- c = (int)((n >> 24) & 0xFF); *--s = (char)(DebugIsPrint(c) ? c : '^');
- i = 4;
- break;
-
- case 's': s = va_arg(arg, char *);
- if (!s) { static char emsg[] = "<<NULL>>"; s = emsg; i = sizeof(emsg)-1; }
- else switch (F.altForm)
- {
- case 0: i=0;
- if (F.havePrecision) // C string
- {
- while((i < F.precision) && s[i]) i++;
- // Make sure we don't truncate in the middle of a UTF-8 character.
- // If the last character is part of a multi-byte UTF-8 character, back up to the start of it.
- j=0;
- while((i > 0) && ((c = s[i-1]) & 0x80)) { j++; i--; if((c & 0xC0) != 0x80) break;}
- // If the actual count of UTF-8 characters matches the encoded UTF-8 count, add it back.
- if((j > 1) && (j <= 6))
- {
- int test = (0xFF << (8-j)) & 0xFF;
- int mask = test | (1 << ((8-j)-1));
- if((c & mask) == test) i += j;
- }
- }
- else
- while(s[i]) i++;
- break;
- case 1: i = (unsigned char) *s++; break; // Pascal string
- case 2: { // DNS label-sequence name
- unsigned char *a = (unsigned char *)s;
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- if (*a == 0) *s++ = '.'; // Special case for root DNS name
- while (*a)
- {
- if (*a > 63) { s += DebugSNPrintF(s, mDNS_VACB_Remain(s), "<<INVALID LABEL LENGTH %u>>", *a); break; }
- if (s + *a >= &mDNS_VACB[254]) { s += DebugSNPrintF(s, mDNS_VACB_Remain(s), "<<NAME TOO LONG>>"); break; }
- s += DebugSNPrintF(s, mDNS_VACB_Remain(s), "%#s.", a);
- a += 1 + *a;
- }
- i = (size_t)(s - mDNS_VACB);
- s = mDNS_VACB; // Reset s back to the start of the buffer
- break;
- }
- }
- if (F.havePrecision && i > F.precision) // Make sure we don't truncate in the middle of a UTF-8 character
- { i = F.precision; while (i>0 && (s[i] & 0xC0) == 0x80) i--;}
- break;
-
- case 'S': { // UTF-16 string
- unsigned char *a = va_arg(arg, unsigned char *);
- uint16_t *u = (uint16_t*)a;
- if (!u) { static char emsg[] = "<<NULL>>"; s = emsg; i = sizeof(emsg)-1; }
- if ((!F.havePrecision || F.precision))
- {
- if ((a[0] == 0xFE) && (a[1] == 0xFF)) { F.altForm = 1; u += 1; a += 2; F.precision--; } // Big Endian
- else if ((a[0] == 0xFF) && (a[1] == 0xFE)) { F.altForm = 2; u += 1; a += 2; F.precision--; } // Little Endian
- }
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- switch (F.altForm)
- {
- case 0: while ((!F.havePrecision || (i < F.precision)) && u[i] && mDNS_VACB_Remain(s)) // Host Endian
- { c = u[i]; *s++ = (char)(DebugIsPrint(c) ? c : '^'); i++; }
- break;
- case 1: while ((!F.havePrecision || (i < F.precision)) && u[i] && mDNS_VACB_Remain(s)) // Big Endian
- { c = ((a[0] << 8) | a[1]) & 0xFF; *s++ = (char)(DebugIsPrint(c) ? c : '^'); i++; a += 2; }
- break;
- case 2: while ((!F.havePrecision || (i < F.precision)) && u[i] && mDNS_VACB_Remain(s)) // Little Endian
- { c = ((a[1] << 8) | a[0]) & 0xFF; *s++ = (char)(DebugIsPrint(c) ? c : '^'); i++; a += 2; }
- break;
- }
- }
- s = mDNS_VACB; // Reset s back to the start of the buffer
- break;
-
- #if TARGET_OS_MAC
- case '@': { // Cocoa/CoreFoundation object
- CFTypeRef cfObj;
- CFStringRef cfStr;
- cfObj = (CFTypeRef) va_arg(arg, void *);
- cfStr = (CFGetTypeID(cfObj) == CFStringGetTypeID()) ? (CFStringRef)CFRetain(cfObj) : CFCopyDescription(cfObj);
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- if (cfStr)
- {
- CFRange range;
- CFIndex m;
- range = CFRangeMake(0, CFStringGetLength(cfStr));
- m = 0;
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list