From 9f68541e0f55495d61dd9e583bec38740a247597 Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Tue, 5 Feb 2019 08:50:26 +0100 Subject: [HICN-26] Windows compatibilty for libparc Change-Id: I6ebff82a81a2bf42fa3bf210ff0e6e530ce21915 Signed-off-by: Angelo Mantellini --- libparc/CMakeLists.txt | 29 +- libparc/cmake/Modules/FindPThread.cmake | 58 +++ libparc/cmake/get_version.sh | 0 .../doxygen-extras/doxygen-bootstrap.js | 0 libparc/documentation/doxygen-extras/footer.html | 0 libparc/documentation/doxygen-extras/header.html | 0 .../How To Create A Static PARC Object/main.c | 0 libparc/parc/CMakeLists.txt | 26 ++ libparc/parc/algol/internal_parc_Event.c | 4 - libparc/parc/algol/internal_parc_Event.h | 0 libparc/parc/algol/parc_AtomicInteger.c | 0 libparc/parc/algol/parc_AtomicInteger.h | 0 libparc/parc/algol/parc_Base64.c | 6 +- libparc/parc/algol/parc_BitVector.c | 8 +- libparc/parc/algol/parc_BitVector.h | 0 libparc/parc/algol/parc_Buffer.c | 8 +- libparc/parc/algol/parc_Buffer.h | 2 +- libparc/parc/algol/parc_BufferChunker.c | 2 + libparc/parc/algol/parc_BufferChunker.h | 0 libparc/parc/algol/parc_BufferComposer.c | 0 libparc/parc/algol/parc_BufferComposer.h | 1 + libparc/parc/algol/parc_BufferDictionary.c | 0 libparc/parc/algol/parc_BufferDictionary.h | 0 libparc/parc/algol/parc_ByteArray.c | 9 +- libparc/parc/algol/parc_ByteArray.h | 4 +- libparc/parc/algol/parc_CMacro.h | 5 +- libparc/parc/algol/parc_Chunker.c | 7 +- libparc/parc/algol/parc_Chunker.h | 0 libparc/parc/algol/parc_Clock.c | 23 +- libparc/parc/algol/parc_Clock.h | 5 +- libparc/parc/algol/parc_Collection.h | 0 libparc/parc/algol/parc_Deque.c | 12 +- libparc/parc/algol/parc_Deque.h | 2 +- libparc/parc/algol/parc_Dictionary.c | 0 libparc/parc/algol/parc_Dictionary.h | 0 libparc/parc/algol/parc_DisplayIndented.c | 23 +- libparc/parc/algol/parc_ElasticString.h | 0 libparc/parc/algol/parc_Environment.c | 28 +- libparc/parc/algol/parc_Environment.h | 0 libparc/parc/algol/parc_Event.c | 0 libparc/parc/algol/parc_EventBuffer.c | 2 +- libparc/parc/algol/parc_EventBuffer.h | 0 libparc/parc/algol/parc_EventQueue.c | 4 +- libparc/parc/algol/parc_EventQueue.h | 5 +- libparc/parc/algol/parc_EventScheduler.c | 11 +- libparc/parc/algol/parc_EventSignal.c | 0 libparc/parc/algol/parc_EventSignal.h | 0 libparc/parc/algol/parc_EventSocket.c | 5 +- libparc/parc/algol/parc_EventSocket.h | 5 +- libparc/parc/algol/parc_EventTimer.c | 0 libparc/parc/algol/parc_EventTimer.h | 0 libparc/parc/algol/parc_File.c | 36 +- libparc/parc/algol/parc_File.h | 0 libparc/parc/algol/parc_FileChunker.c | 7 +- libparc/parc/algol/parc_FileChunker.h | 0 libparc/parc/algol/parc_FileInputStream.c | 12 +- libparc/parc/algol/parc_FileInputStream.h | 0 libparc/parc/algol/parc_FileOutputStream.c | 11 +- libparc/parc/algol/parc_Hash.c | 6 +- libparc/parc/algol/parc_Hash.h | 0 libparc/parc/algol/parc_HashCode.c | 0 libparc/parc/algol/parc_HashCode.h | 0 libparc/parc/algol/parc_HashCodeTable.c | 6 +- libparc/parc/algol/parc_HashMap.c | 10 +- libparc/parc/algol/parc_HashMap.h | 0 libparc/parc/algol/parc_InputStream.c | 0 libparc/parc/algol/parc_InputStream.h | 0 libparc/parc/algol/parc_Iterator.c | 0 libparc/parc/algol/parc_JSON.c | 0 libparc/parc/algol/parc_JSON.h | 0 libparc/parc/algol/parc_JSONArray.c | 0 libparc/parc/algol/parc_JSONArray.h | 0 libparc/parc/algol/parc_JSONPair.c | 0 libparc/parc/algol/parc_JSONPair.h | 0 libparc/parc/algol/parc_JSONParser.c | 0 libparc/parc/algol/parc_JSONParser.h | 0 libparc/parc/algol/parc_JSONValue.c | 4 +- libparc/parc/algol/parc_JSONValue.h | 0 libparc/parc/algol/parc_KeyValue.c | 0 libparc/parc/algol/parc_KeyValue.h | 0 libparc/parc/algol/parc_KeyedElement.c | 0 libparc/parc/algol/parc_KeyedElement.h | 0 libparc/parc/algol/parc_LinkedList.c | 12 +- libparc/parc/algol/parc_LinkedList.h | 2 +- libparc/parc/algol/parc_List.c | 6 +- libparc/parc/algol/parc_Map.c | 0 libparc/parc/algol/parc_Map.h | 0 libparc/parc/algol/parc_Memory.c | 23 +- libparc/parc/algol/parc_Memory.h | 46 +- libparc/parc/algol/parc_Network.c | 22 +- libparc/parc/algol/parc_Network.h | 2 + libparc/parc/algol/parc_Object.c | 63 ++- libparc/parc/algol/parc_Object.h | 26 +- libparc/parc/algol/parc_OldSortedList.c | 0 libparc/parc/algol/parc_OldSortedList.h | 0 libparc/parc/algol/parc_OutputStream.c | 0 libparc/parc/algol/parc_OutputStream.h | 0 libparc/parc/algol/parc_PathName.c | 15 +- libparc/parc/algol/parc_PriorityQueue.c | 4 +- libparc/parc/algol/parc_PriorityQueue.h | 0 libparc/parc/algol/parc_Properties.c | 2 +- libparc/parc/algol/parc_RandomAccessFile.c | 0 libparc/parc/algol/parc_RandomAccessFile.h | 0 libparc/parc/algol/parc_ReadOnlyBuffer.c | 0 libparc/parc/algol/parc_SafeMemory.c | 14 +- libparc/parc/algol/parc_Stack.c | 0 libparc/parc/algol/parc_Stack.h | 0 libparc/parc/algol/parc_StdlibMemory.c | 38 +- libparc/parc/algol/parc_StdlibMemory.h | 14 + libparc/parc/algol/parc_String.c | 0 libparc/parc/algol/parc_Time.c | 37 +- libparc/parc/algol/parc_Time.h | 3 + libparc/parc/algol/parc_TreeMap.c | 0 libparc/parc/algol/parc_TreeMap.h | 0 libparc/parc/algol/parc_TreeRedBlack.c | 0 libparc/parc/algol/parc_TreeRedBlack.h | 0 libparc/parc/algol/parc_URI.c | 15 +- libparc/parc/algol/parc_URIAuthority.c | 14 +- libparc/parc/algol/parc_URIPath.c | 14 +- libparc/parc/algol/parc_URIPath.h | 0 libparc/parc/algol/parc_URISegment.c | 16 +- libparc/parc/algol/parc_Unsigned.h | 0 libparc/parc/algol/parc_Varint.c | 0 libparc/parc/algol/parc_Varint.h | 0 libparc/parc/algol/parc_Vector.c | 0 libparc/parc/algol/parc_Vector.h | 0 libparc/parc/algol/test/test_parc_ArrayList.c | 0 libparc/parc/algol/test/test_parc_Base64.c | 0 libparc/parc/algol/test/test_parc_BitVector.c | 0 libparc/parc/algol/test/test_parc_BufferChunker.c | 0 libparc/parc/algol/test/test_parc_ByteArray.c | 0 libparc/parc/algol/test/test_parc_Chunker.c | 0 libparc/parc/algol/test/test_parc_Deque.c | 0 libparc/parc/algol/test/test_parc_Display.c | 0 libparc/parc/algol/test/test_parc_Environment.c | 0 libparc/parc/algol/test/test_parc_EventScheduler.c | 0 libparc/parc/algol/test/test_parc_EventTimer.c | 0 libparc/parc/algol/test/test_parc_FileChunker.c | 0 .../parc/algol/test/test_parc_FileInputStream.c | 0 .../parc/algol/test/test_parc_FileOutputStream.c | 0 libparc/parc/algol/test/test_parc_Hash.c | 0 libparc/parc/algol/test/test_parc_HashCode.c | 0 libparc/parc/algol/test/test_parc_HashCodeTable.c | 0 libparc/parc/algol/test/test_parc_InputStream.c | 0 libparc/parc/algol/test/test_parc_JSONArray.c | 0 libparc/parc/algol/test/test_parc_JSONParser.c | 0 libparc/parc/algol/test/test_parc_KeyValue.c | 0 libparc/parc/algol/test/test_parc_KeyedElement.c | 0 libparc/parc/algol/test/test_parc_Memory.c | 0 libparc/parc/algol/test/test_parc_Network.c | 0 libparc/parc/algol/test/test_parc_Object.c | 0 libparc/parc/algol/test/test_parc_PathName.c | 0 libparc/parc/algol/test/test_parc_Stack.c | 0 libparc/parc/algol/test/test_parc_TreeMap.c | 0 libparc/parc/algol/test/test_parc_TreeRedBlack.c | 0 libparc/parc/algol/test/test_parc_Varint.c | 0 libparc/parc/assert/parc_Assert.h | 8 +- libparc/parc/concurrent/parc_AtomicUint16.c | 0 libparc/parc/concurrent/parc_AtomicUint16.h | 0 libparc/parc/concurrent/parc_AtomicUint32.c | 0 libparc/parc/concurrent/parc_AtomicUint32.h | 0 libparc/parc/concurrent/parc_AtomicUint64.c | 0 libparc/parc/concurrent/parc_AtomicUint64.h | 0 libparc/parc/concurrent/parc_AtomicUint8.c | 0 libparc/parc/concurrent/parc_AtomicUint8.h | 0 libparc/parc/concurrent/parc_FutureTask.c | 0 libparc/parc/concurrent/parc_FutureTask.h | 0 libparc/parc/concurrent/parc_Lock.c | 0 libparc/parc/concurrent/parc_Lock.h | 0 libparc/parc/concurrent/parc_Notifier.c | 26 +- libparc/parc/concurrent/parc_Notifier.h | 1 + libparc/parc/concurrent/parc_RingBuffer.c | 0 libparc/parc/concurrent/parc_RingBuffer.h | 0 libparc/parc/concurrent/parc_RingBuffer_1x1.c | 13 +- libparc/parc/concurrent/parc_RingBuffer_1x1.h | 0 libparc/parc/concurrent/parc_RingBuffer_NxM.c | 0 libparc/parc/concurrent/parc_RingBuffer_NxM.h | 0 libparc/parc/concurrent/parc_ScheduledTask.c | 7 +- libparc/parc/concurrent/parc_ScheduledTask.h | 0 libparc/parc/concurrent/parc_ScheduledThreadPool.c | 2 +- libparc/parc/concurrent/parc_ScheduledThreadPool.h | 0 libparc/parc/concurrent/parc_Synchronizer.c | 0 libparc/parc/concurrent/parc_Synchronizer.h | 0 libparc/parc/concurrent/parc_Thread.c | 6 +- libparc/parc/concurrent/parc_Thread.h | 0 libparc/parc/concurrent/parc_ThreadPool.c | 2 +- libparc/parc/concurrent/parc_ThreadPool.h | 0 libparc/parc/concurrent/parc_Timeout.c | 0 libparc/parc/concurrent/parc_Timer.c | 0 libparc/parc/concurrent/parc_Timer.h | 0 libparc/parc/concurrent/test/test_parc_Notifier.c | 0 .../concurrent/test/test_parc_RingBuffer_1x1.c | 0 .../concurrent/test/test_parc_RingBuffer_NxM.c | 0 .../parc/concurrent/test/test_parc_Synchronizer.c | 0 libparc/parc/config.h.in | 4 + libparc/parc/developer/parc_Stopwatch.c | 8 +- libparc/parc/developer/parc_Timing.h | 0 libparc/parc/developer/parc_TimingDarwin.h | 0 libparc/parc/developer/parc_TimingGeneric.h | 5 +- libparc/parc/developer/parc_TimingIntel.c | 0 libparc/parc/developer/parc_TimingIntel.h | 0 libparc/parc/developer/parc_TimingLinux.h | 0 libparc/parc/developer/test/test_parc_Timing.c | 0 libparc/parc/libparc_About.h | 0 libparc/parc/logging/parc_Log.c | 26 +- libparc/parc/logging/parc_LogEntry.h | 7 +- libparc/parc/logging/parc_LogFormatSyslog.c | 0 libparc/parc/logging/parc_LogFormatSyslog.h | 0 libparc/parc/logging/parc_LogFormatText.c | 0 libparc/parc/logging/parc_LogFormatText.h | 0 libparc/parc/logging/parc_LogLevel.c | 2 +- libparc/parc/logging/parc_LogLevel.h | 0 libparc/parc/logging/parc_LogManager.c | 0 libparc/parc/logging/parc_LogManager.h | 0 libparc/parc/logging/parc_LogReporter.c | 0 libparc/parc/logging/parc_LogReporter.h | 0 libparc/parc/logging/parc_LogReporterFile.c | 0 libparc/parc/logging/parc_LogReporterFile.h | 0 libparc/parc/logging/parc_LogReporterTextStdout.c | 7 +- libparc/parc/logging/parc_LogReporterTextStdout.h | 0 .../parc/logging/test/test_parc_LogFormatSyslog.c | 0 libparc/parc/logging/test/test_parc_LogLevel.c | 0 .../parc/logging/test/test_parc_LogReporterFile.c | 0 .../logging/test/test_parc_LogReporterTextStdout.c | 0 .../security/command-line/parcPublicKey_About.h | 0 libparc/parc/security/parc_Certificate.c | 0 libparc/parc/security/parc_Certificate.h | 0 libparc/parc/security/parc_CertificateFactory.h | 0 libparc/parc/security/parc_CertificateType.c | 0 libparc/parc/security/parc_CertificateType.h | 0 libparc/parc/security/parc_ContainerEncoding.c | 0 libparc/parc/security/parc_ContainerEncoding.h | 0 libparc/parc/security/parc_CryptoCache.c | 0 libparc/parc/security/parc_CryptoCache.h | 0 libparc/parc/security/parc_CryptoHash.c | 0 libparc/parc/security/parc_CryptoHash.h | 0 libparc/parc/security/parc_CryptoHashType.h | 0 libparc/parc/security/parc_CryptoHasher.c | 4 +- libparc/parc/security/parc_CryptoHasher.h | 0 libparc/parc/security/parc_CryptoSuite.c | 6 +- libparc/parc/security/parc_CryptoSuite.h | 0 libparc/parc/security/parc_DiffieHellmanGroup.h | 0 libparc/parc/security/parc_DiffieHellmanKeyShare.c | 2 +- libparc/parc/security/parc_Identity.c | 0 libparc/parc/security/parc_Identity.h | 0 libparc/parc/security/parc_IdentityFile.c | 13 +- libparc/parc/security/parc_InMemoryVerifier.c | 5 +- libparc/parc/security/parc_InMemoryVerifier.h | 0 libparc/parc/security/parc_Key.c | 0 libparc/parc/security/parc_Key.h | 0 libparc/parc/security/parc_KeyId.c | 0 libparc/parc/security/parc_KeyId.h | 0 libparc/parc/security/parc_KeyStore.c | 0 libparc/parc/security/parc_KeyStore.h | 0 libparc/parc/security/parc_Pkcs12KeyStore.c | 42 +- libparc/parc/security/parc_PublicKeySigner.c | 8 +- libparc/parc/security/parc_SecureRandom.c | 12 +- libparc/parc/security/parc_Security.c | 8 +- libparc/parc/security/parc_Security.h | 0 libparc/parc/security/parc_Signature.c | 0 libparc/parc/security/parc_Signature.h | 0 libparc/parc/security/parc_Signer.h | 0 libparc/parc/security/parc_SigningAlgorithm.c | 0 libparc/parc/security/parc_SymmetricKeyStore.c | 12 +- libparc/parc/security/parc_Verifier.c | 0 libparc/parc/security/parc_X509Certificate.c | 2 +- libparc/parc/security/parc_X509Certificate.h | 0 .../security/test/test_parc_CertificateFactory.c | 0 .../parc/security/test/test_parc_CertificateType.c | 0 .../security/test/test_parc_ContainerEncoding.c | 0 libparc/parc/security/test/test_parc_CryptoCache.c | 0 libparc/parc/security/test/test_parc_CryptoHash.c | 0 .../parc/security/test/test_parc_CryptoHasher.c | 0 libparc/parc/security/test/test_parc_CryptoSuite.c | 0 .../parc/security/test/test_parc_DiffieHellman.c | 0 .../test/test_parc_DiffieHellmanKeyShare.c | 0 .../security/test/test_parc_InMemoryVerifier.c | 0 libparc/parc/security/test/test_parc_Key.c | 0 libparc/parc/security/test/test_parc_KeyStore.c | 0 .../parc/security/test/test_parc_Pkcs12KeyStore.c | 0 .../parc/security/test/test_parc_SecureRandom.c | 0 libparc/parc/security/test/test_parc_Security.c | 0 libparc/parc/security/test/test_parc_Signature.c | 0 .../security/test/test_parc_SigningAlgorithm.c | 0 .../security/test/test_parc_SymmetricKeyStore.c | 0 libparc/parc/security/test/test_parc_Verifier.c | 0 .../parc/security/test/test_parc_X509Certificate.c | 0 libparc/parc/statistics/parc_BasicStats.h | 0 libparc/parc/statistics/parc_EWMA.c | 6 +- libparc/parc/statistics/parc_EWMA.h | 0 libparc/parc/testing/parc_MemoryTesting.c | 0 libparc/parc/testing/parc_MemoryTesting.h | 0 .../parc/testing/test/test_parc_MemoryTesting.c | 0 .../parc/testing/test/test_parc_ObjectTesting.c | 0 libparc/parc/windows/getopt.c | 149 +++++++ libparc/parc/windows/getopt.h | 33 ++ libparc/parc/windows/getopt_long.c | 233 ++++++++++ libparc/parc/windows/parc_Utils.c | 128 ++++++ libparc/parc/windows/parc_Utils.h | 168 +++++++ libparc/parc/windows/queue.h | 488 +++++++++++++++++++++ 300 files changed, 1887 insertions(+), 330 deletions(-) create mode 100644 libparc/cmake/Modules/FindPThread.cmake mode change 100755 => 100644 libparc/cmake/get_version.sh mode change 100755 => 100644 libparc/documentation/doxygen-extras/doxygen-bootstrap.js mode change 100755 => 100644 libparc/documentation/doxygen-extras/footer.html mode change 100755 => 100644 libparc/documentation/doxygen-extras/header.html mode change 100755 => 100644 libparc/examples/How To Create A Static PARC Object/main.c mode change 100755 => 100644 libparc/parc/algol/internal_parc_Event.c mode change 100755 => 100644 libparc/parc/algol/internal_parc_Event.h mode change 100755 => 100644 libparc/parc/algol/parc_AtomicInteger.c mode change 100755 => 100644 libparc/parc/algol/parc_AtomicInteger.h mode change 100755 => 100644 libparc/parc/algol/parc_Base64.c mode change 100755 => 100644 libparc/parc/algol/parc_BitVector.c mode change 100755 => 100644 libparc/parc/algol/parc_BitVector.h mode change 100755 => 100644 libparc/parc/algol/parc_Buffer.c mode change 100755 => 100644 libparc/parc/algol/parc_BufferChunker.h mode change 100755 => 100644 libparc/parc/algol/parc_BufferComposer.c mode change 100755 => 100644 libparc/parc/algol/parc_BufferComposer.h mode change 100755 => 100644 libparc/parc/algol/parc_BufferDictionary.c mode change 100755 => 100644 libparc/parc/algol/parc_BufferDictionary.h mode change 100755 => 100644 libparc/parc/algol/parc_Chunker.c mode change 100755 => 100644 libparc/parc/algol/parc_Chunker.h mode change 100755 => 100644 libparc/parc/algol/parc_Clock.c mode change 100755 => 100644 libparc/parc/algol/parc_Clock.h mode change 100755 => 100644 libparc/parc/algol/parc_Collection.h mode change 100755 => 100644 libparc/parc/algol/parc_Deque.h mode change 100755 => 100644 libparc/parc/algol/parc_Dictionary.c mode change 100755 => 100644 libparc/parc/algol/parc_Dictionary.h mode change 100755 => 100644 libparc/parc/algol/parc_DisplayIndented.c mode change 100755 => 100644 libparc/parc/algol/parc_ElasticString.h mode change 100755 => 100644 libparc/parc/algol/parc_Environment.h mode change 100755 => 100644 libparc/parc/algol/parc_Event.c mode change 100755 => 100644 libparc/parc/algol/parc_EventBuffer.h mode change 100755 => 100644 libparc/parc/algol/parc_EventQueue.c mode change 100755 => 100644 libparc/parc/algol/parc_EventScheduler.c mode change 100755 => 100644 libparc/parc/algol/parc_EventSignal.c mode change 100755 => 100644 libparc/parc/algol/parc_EventSignal.h mode change 100755 => 100644 libparc/parc/algol/parc_EventSocket.c mode change 100755 => 100644 libparc/parc/algol/parc_EventSocket.h mode change 100755 => 100644 libparc/parc/algol/parc_EventTimer.c mode change 100755 => 100644 libparc/parc/algol/parc_EventTimer.h mode change 100755 => 100644 libparc/parc/algol/parc_File.h mode change 100755 => 100644 libparc/parc/algol/parc_FileChunker.h mode change 100755 => 100644 libparc/parc/algol/parc_FileInputStream.c mode change 100755 => 100644 libparc/parc/algol/parc_FileInputStream.h mode change 100755 => 100644 libparc/parc/algol/parc_FileOutputStream.c mode change 100755 => 100644 libparc/parc/algol/parc_Hash.c mode change 100755 => 100644 libparc/parc/algol/parc_Hash.h mode change 100755 => 100644 libparc/parc/algol/parc_HashCode.c mode change 100755 => 100644 libparc/parc/algol/parc_HashCode.h mode change 100755 => 100644 libparc/parc/algol/parc_HashCodeTable.c mode change 100755 => 100644 libparc/parc/algol/parc_HashMap.h mode change 100755 => 100644 libparc/parc/algol/parc_InputStream.c mode change 100755 => 100644 libparc/parc/algol/parc_InputStream.h mode change 100755 => 100644 libparc/parc/algol/parc_Iterator.c mode change 100755 => 100644 libparc/parc/algol/parc_JSON.c mode change 100755 => 100644 libparc/parc/algol/parc_JSON.h mode change 100755 => 100644 libparc/parc/algol/parc_JSONArray.c mode change 100755 => 100644 libparc/parc/algol/parc_JSONArray.h mode change 100755 => 100644 libparc/parc/algol/parc_JSONPair.c mode change 100755 => 100644 libparc/parc/algol/parc_JSONPair.h mode change 100755 => 100644 libparc/parc/algol/parc_JSONParser.c mode change 100755 => 100644 libparc/parc/algol/parc_JSONParser.h mode change 100755 => 100644 libparc/parc/algol/parc_JSONValue.c mode change 100755 => 100644 libparc/parc/algol/parc_JSONValue.h mode change 100755 => 100644 libparc/parc/algol/parc_KeyValue.c mode change 100755 => 100644 libparc/parc/algol/parc_KeyValue.h mode change 100755 => 100644 libparc/parc/algol/parc_KeyedElement.c mode change 100755 => 100644 libparc/parc/algol/parc_KeyedElement.h mode change 100755 => 100644 libparc/parc/algol/parc_Map.c mode change 100755 => 100644 libparc/parc/algol/parc_Map.h mode change 100755 => 100644 libparc/parc/algol/parc_Memory.c mode change 100755 => 100644 libparc/parc/algol/parc_OldSortedList.c mode change 100755 => 100644 libparc/parc/algol/parc_OldSortedList.h mode change 100755 => 100644 libparc/parc/algol/parc_OutputStream.c mode change 100755 => 100644 libparc/parc/algol/parc_OutputStream.h mode change 100755 => 100644 libparc/parc/algol/parc_PathName.c mode change 100755 => 100644 libparc/parc/algol/parc_PriorityQueue.c mode change 100755 => 100644 libparc/parc/algol/parc_PriorityQueue.h mode change 100755 => 100644 libparc/parc/algol/parc_RandomAccessFile.c mode change 100755 => 100644 libparc/parc/algol/parc_RandomAccessFile.h mode change 100755 => 100644 libparc/parc/algol/parc_ReadOnlyBuffer.c mode change 100755 => 100644 libparc/parc/algol/parc_Stack.c mode change 100755 => 100644 libparc/parc/algol/parc_Stack.h mode change 100755 => 100644 libparc/parc/algol/parc_StdlibMemory.c mode change 100755 => 100644 libparc/parc/algol/parc_StdlibMemory.h mode change 100755 => 100644 libparc/parc/algol/parc_String.c mode change 100755 => 100644 libparc/parc/algol/parc_Time.c mode change 100755 => 100644 libparc/parc/algol/parc_TreeMap.c mode change 100755 => 100644 libparc/parc/algol/parc_TreeMap.h mode change 100755 => 100644 libparc/parc/algol/parc_TreeRedBlack.c mode change 100755 => 100644 libparc/parc/algol/parc_TreeRedBlack.h mode change 100755 => 100644 libparc/parc/algol/parc_URIPath.c mode change 100755 => 100644 libparc/parc/algol/parc_URIPath.h mode change 100755 => 100644 libparc/parc/algol/parc_URISegment.c mode change 100755 => 100644 libparc/parc/algol/parc_Unsigned.h mode change 100755 => 100644 libparc/parc/algol/parc_Varint.c mode change 100755 => 100644 libparc/parc/algol/parc_Varint.h mode change 100755 => 100644 libparc/parc/algol/parc_Vector.c mode change 100755 => 100644 libparc/parc/algol/parc_Vector.h mode change 100755 => 100644 libparc/parc/algol/test/test_parc_ArrayList.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Base64.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_BitVector.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_BufferChunker.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_ByteArray.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Chunker.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Deque.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Display.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Environment.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_EventScheduler.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_EventTimer.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_FileChunker.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_FileInputStream.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_FileOutputStream.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Hash.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_HashCode.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_HashCodeTable.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_InputStream.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_JSONArray.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_JSONParser.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_KeyValue.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_KeyedElement.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Memory.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Network.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Object.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_PathName.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Stack.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_TreeMap.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_TreeRedBlack.c mode change 100755 => 100644 libparc/parc/algol/test/test_parc_Varint.c mode change 100755 => 100644 libparc/parc/concurrent/parc_AtomicUint16.c mode change 100755 => 100644 libparc/parc/concurrent/parc_AtomicUint16.h mode change 100755 => 100644 libparc/parc/concurrent/parc_AtomicUint32.c mode change 100755 => 100644 libparc/parc/concurrent/parc_AtomicUint32.h mode change 100755 => 100644 libparc/parc/concurrent/parc_AtomicUint64.c mode change 100755 => 100644 libparc/parc/concurrent/parc_AtomicUint64.h mode change 100755 => 100644 libparc/parc/concurrent/parc_AtomicUint8.c mode change 100755 => 100644 libparc/parc/concurrent/parc_AtomicUint8.h mode change 100755 => 100644 libparc/parc/concurrent/parc_FutureTask.c mode change 100755 => 100644 libparc/parc/concurrent/parc_FutureTask.h mode change 100755 => 100644 libparc/parc/concurrent/parc_Lock.c mode change 100755 => 100644 libparc/parc/concurrent/parc_Lock.h mode change 100755 => 100644 libparc/parc/concurrent/parc_Notifier.c mode change 100755 => 100644 libparc/parc/concurrent/parc_Notifier.h mode change 100755 => 100644 libparc/parc/concurrent/parc_RingBuffer.c mode change 100755 => 100644 libparc/parc/concurrent/parc_RingBuffer.h mode change 100755 => 100644 libparc/parc/concurrent/parc_RingBuffer_1x1.c mode change 100755 => 100644 libparc/parc/concurrent/parc_RingBuffer_1x1.h mode change 100755 => 100644 libparc/parc/concurrent/parc_RingBuffer_NxM.c mode change 100755 => 100644 libparc/parc/concurrent/parc_RingBuffer_NxM.h mode change 100755 => 100644 libparc/parc/concurrent/parc_ScheduledTask.c mode change 100755 => 100644 libparc/parc/concurrent/parc_ScheduledTask.h mode change 100755 => 100644 libparc/parc/concurrent/parc_ScheduledThreadPool.h mode change 100755 => 100644 libparc/parc/concurrent/parc_Synchronizer.c mode change 100755 => 100644 libparc/parc/concurrent/parc_Synchronizer.h mode change 100755 => 100644 libparc/parc/concurrent/parc_Thread.h mode change 100755 => 100644 libparc/parc/concurrent/parc_ThreadPool.h mode change 100755 => 100644 libparc/parc/concurrent/parc_Timeout.c mode change 100755 => 100644 libparc/parc/concurrent/parc_Timer.c mode change 100755 => 100644 libparc/parc/concurrent/parc_Timer.h mode change 100755 => 100644 libparc/parc/concurrent/test/test_parc_Notifier.c mode change 100755 => 100644 libparc/parc/concurrent/test/test_parc_RingBuffer_1x1.c mode change 100755 => 100644 libparc/parc/concurrent/test/test_parc_RingBuffer_NxM.c mode change 100755 => 100644 libparc/parc/concurrent/test/test_parc_Synchronizer.c mode change 100755 => 100644 libparc/parc/developer/parc_Timing.h mode change 100755 => 100644 libparc/parc/developer/parc_TimingDarwin.h mode change 100755 => 100644 libparc/parc/developer/parc_TimingGeneric.h mode change 100755 => 100644 libparc/parc/developer/parc_TimingIntel.c mode change 100755 => 100644 libparc/parc/developer/parc_TimingIntel.h mode change 100755 => 100644 libparc/parc/developer/parc_TimingLinux.h mode change 100755 => 100644 libparc/parc/developer/test/test_parc_Timing.c mode change 100755 => 100644 libparc/parc/libparc_About.h mode change 100755 => 100644 libparc/parc/logging/parc_Log.c mode change 100755 => 100644 libparc/parc/logging/parc_LogEntry.h mode change 100755 => 100644 libparc/parc/logging/parc_LogFormatSyslog.c mode change 100755 => 100644 libparc/parc/logging/parc_LogFormatSyslog.h mode change 100755 => 100644 libparc/parc/logging/parc_LogFormatText.c mode change 100755 => 100644 libparc/parc/logging/parc_LogFormatText.h mode change 100755 => 100644 libparc/parc/logging/parc_LogLevel.c mode change 100755 => 100644 libparc/parc/logging/parc_LogLevel.h mode change 100755 => 100644 libparc/parc/logging/parc_LogManager.c mode change 100755 => 100644 libparc/parc/logging/parc_LogManager.h mode change 100755 => 100644 libparc/parc/logging/parc_LogReporter.c mode change 100755 => 100644 libparc/parc/logging/parc_LogReporter.h mode change 100755 => 100644 libparc/parc/logging/parc_LogReporterFile.c mode change 100755 => 100644 libparc/parc/logging/parc_LogReporterFile.h mode change 100755 => 100644 libparc/parc/logging/parc_LogReporterTextStdout.c mode change 100755 => 100644 libparc/parc/logging/parc_LogReporterTextStdout.h mode change 100755 => 100644 libparc/parc/logging/test/test_parc_LogFormatSyslog.c mode change 100755 => 100644 libparc/parc/logging/test/test_parc_LogLevel.c mode change 100755 => 100644 libparc/parc/logging/test/test_parc_LogReporterFile.c mode change 100755 => 100644 libparc/parc/logging/test/test_parc_LogReporterTextStdout.c mode change 100755 => 100644 libparc/parc/security/command-line/parcPublicKey_About.h mode change 100755 => 100644 libparc/parc/security/parc_Certificate.c mode change 100755 => 100644 libparc/parc/security/parc_Certificate.h mode change 100755 => 100644 libparc/parc/security/parc_CertificateFactory.h mode change 100755 => 100644 libparc/parc/security/parc_CertificateType.c mode change 100755 => 100644 libparc/parc/security/parc_CertificateType.h mode change 100755 => 100644 libparc/parc/security/parc_ContainerEncoding.c mode change 100755 => 100644 libparc/parc/security/parc_ContainerEncoding.h mode change 100755 => 100644 libparc/parc/security/parc_CryptoCache.c mode change 100755 => 100644 libparc/parc/security/parc_CryptoCache.h mode change 100755 => 100644 libparc/parc/security/parc_CryptoHash.c mode change 100755 => 100644 libparc/parc/security/parc_CryptoHash.h mode change 100755 => 100644 libparc/parc/security/parc_CryptoHashType.h mode change 100755 => 100644 libparc/parc/security/parc_CryptoHasher.c mode change 100755 => 100644 libparc/parc/security/parc_CryptoHasher.h mode change 100755 => 100644 libparc/parc/security/parc_CryptoSuite.c mode change 100755 => 100644 libparc/parc/security/parc_CryptoSuite.h mode change 100755 => 100644 libparc/parc/security/parc_DiffieHellmanGroup.h mode change 100755 => 100644 libparc/parc/security/parc_Identity.c mode change 100755 => 100644 libparc/parc/security/parc_Identity.h mode change 100755 => 100644 libparc/parc/security/parc_InMemoryVerifier.h mode change 100755 => 100644 libparc/parc/security/parc_Key.c mode change 100755 => 100644 libparc/parc/security/parc_Key.h mode change 100755 => 100644 libparc/parc/security/parc_KeyId.c mode change 100755 => 100644 libparc/parc/security/parc_KeyId.h mode change 100755 => 100644 libparc/parc/security/parc_KeyStore.c mode change 100755 => 100644 libparc/parc/security/parc_KeyStore.h mode change 100755 => 100644 libparc/parc/security/parc_Security.h mode change 100755 => 100644 libparc/parc/security/parc_Signature.c mode change 100755 => 100644 libparc/parc/security/parc_Signature.h mode change 100755 => 100644 libparc/parc/security/parc_Signer.h mode change 100755 => 100644 libparc/parc/security/parc_SigningAlgorithm.c mode change 100755 => 100644 libparc/parc/security/parc_Verifier.c mode change 100755 => 100644 libparc/parc/security/parc_X509Certificate.h mode change 100755 => 100644 libparc/parc/security/test/test_parc_CertificateFactory.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_CertificateType.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_ContainerEncoding.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_CryptoCache.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_CryptoHash.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_CryptoHasher.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_CryptoSuite.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_DiffieHellman.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_DiffieHellmanKeyShare.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_InMemoryVerifier.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_Key.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_KeyStore.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_Pkcs12KeyStore.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_SecureRandom.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_Security.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_Signature.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_SigningAlgorithm.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_SymmetricKeyStore.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_Verifier.c mode change 100755 => 100644 libparc/parc/security/test/test_parc_X509Certificate.c mode change 100755 => 100644 libparc/parc/statistics/parc_BasicStats.h mode change 100755 => 100644 libparc/parc/statistics/parc_EWMA.h mode change 100755 => 100644 libparc/parc/testing/parc_MemoryTesting.c mode change 100755 => 100644 libparc/parc/testing/parc_MemoryTesting.h mode change 100755 => 100644 libparc/parc/testing/test/test_parc_MemoryTesting.c mode change 100755 => 100644 libparc/parc/testing/test/test_parc_ObjectTesting.c create mode 100644 libparc/parc/windows/getopt.c create mode 100644 libparc/parc/windows/getopt.h create mode 100644 libparc/parc/windows/getopt_long.c create mode 100644 libparc/parc/windows/parc_Utils.c create mode 100644 libparc/parc/windows/parc_Utils.h create mode 100644 libparc/parc/windows/queue.h diff --git a/libparc/CMakeLists.txt b/libparc/CMakeLists.txt index f40a340e..f7c5fd22 100644 --- a/libparc/CMakeLists.txt +++ b/libparc/CMakeLists.txt @@ -30,6 +30,8 @@ elseif(COMPILE_FOR_IOS) message("############ Detected cross compile for $ENV{CMAKE_SYSTEM_NAME}") message("############ This build will not include doxygen, tools, or tests") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +elseif(WIN32) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996 /wd4146") else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") find_package( Doxygen ) @@ -48,20 +50,32 @@ include_directories(${PROJECT_BINARY_DIR}/parc ${PROJECT_SOURCE_DIR}) if (DOC_ONLY) message("############ Skipping check of required dependencies.") elseif(COMPILE_FOR_IOS) -find_host_package( LibEvent REQUIRED ) + find_host_package( LibEvent REQUIRED ) include_directories(${LIBEVENT_INCLUDE_DIRS}) - + find_package ( Threads REQUIRED ) find_host_package ( OpenSSL REQUIRED ) else() find_package( LibEvent REQUIRED ) include_directories(${LIBEVENT_INCLUDE_DIRS}) + if(NOT WIN32) + if(ENABLE_TEST) + find_package( LongBow REQUIRED ) + include_directories(${LONGBOW_INCLUDE_DIRS}) + endif() + find_package ( Threads REQUIRED ) + else() - if(ENABLE_TEST) - find_package( LongBow REQUIRED ) - include_directories(${LONGBOW_INCLUDE_DIRS}) + find_package( PThread REQUIRED ) + include_directories( ${PTHREAD_INCLUDE_DIRS} ) + + find_package ( OpenSSL REQUIRED ) + include_directories( ${OPENSSL_INCLUDE_DIR} ) + add_definitions(-D_TIMESPEC_DEFINED=1) + find_library(WSOCK32_LIBRARY wsock32 required) + find_library(WS2_32_LIBRARY ws2_32 required) endif() - find_package ( Threads REQUIRED ) + find_package ( OpenSSL REQUIRED ) include_directories(${OPENSSL_INCLUDE_DIR}) @@ -82,6 +96,9 @@ else() ${LIBEVENT_LIBRARIES} ${OPENSSL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + ${PTHREAD_LIBRARIES} + ${WSOCK32_LIBRARY} + ${WS2_32_LIBRARY} ) endif() diff --git a/libparc/cmake/Modules/FindPThread.cmake b/libparc/cmake/Modules/FindPThread.cmake new file mode 100644 index 00000000..23dfc330 --- /dev/null +++ b/libparc/cmake/Modules/FindPThread.cmake @@ -0,0 +1,58 @@ +# Copyright (c) 2019 Cisco and/or its affiliates. +# 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. + +######################################## +# +# Find the PThread libraries and includes +# This module sets: +# PTHREAD_FOUND: True if Libconsumer-producer was found +# PTHREADR_LIBRARY: The Libconsumer-producer library +# PTHREAD_LIBRARIES: The Libconsumer-producer library and dependencies +# PTHREAD_INCLUDE_DIR: The Libconsumer-producer include dir +# + + +set(PTHREAD_SEARCH_PATH_LIST + ${PTHREAD_HOME} + $ENV{PTHREAD_HOME} + /usr/local + /opt + /usr +) + +find_path(PTHREAD_INCLUDE_DIR pthread.h + HINTS ${PTHREAD_SEARCH_PATH_LIST} + PATH_SUFFIXES include + DOC "Find the pthreadincludes" +) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + find_library(PTHREAD_LIBRARY NAMES pthreadVC2.lib + HINTS ${PTHREAD_SEARCH_PATH_LIST} + PATH_SUFFIXES lib/x64 + DOC "Find the pthread libraries" + ) +elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) + find_library(PTHREAD_LIBRARY NAMES pthreadVC2.lib + HINTS ${PTHREAD_SEARCH_PATH_LIST} + PATH_SUFFIXES lib/x32 + DOC "Find the pthread libraries" + ) +endif() + + +set(PTHREAD_LIBRARIES ${PTHREAD_LIBRARY}) +set(PTHREAD_INCLUDE_DIRS ${PTHREAD_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Pthread DEFAULT_MSG PTHREAD_LIBRARIES PTHREAD_INCLUDE_DIRS) \ No newline at end of file diff --git a/libparc/cmake/get_version.sh b/libparc/cmake/get_version.sh old mode 100755 new mode 100644 diff --git a/libparc/documentation/doxygen-extras/doxygen-bootstrap.js b/libparc/documentation/doxygen-extras/doxygen-bootstrap.js old mode 100755 new mode 100644 diff --git a/libparc/documentation/doxygen-extras/footer.html b/libparc/documentation/doxygen-extras/footer.html old mode 100755 new mode 100644 diff --git a/libparc/documentation/doxygen-extras/header.html b/libparc/documentation/doxygen-extras/header.html old mode 100755 new mode 100644 diff --git a/libparc/examples/How To Create A Static PARC Object/main.c b/libparc/examples/How To Create A Static PARC Object/main.c old mode 100755 new mode 100644 diff --git a/libparc/parc/CMakeLists.txt b/libparc/parc/CMakeLists.txt index ebb3ff91..df582a35 100644 --- a/libparc/parc/CMakeLists.txt +++ b/libparc/parc/CMakeLists.txt @@ -285,6 +285,19 @@ set (LIBPARC_ASSERT_HEADER_FILES assert/parc_Assert.h ) +if(WIN32) + set (WINDOWS_UTILITY_HEADER_FILES + windows/parc_Utils.h + windows/queue.h + windows/getopt.h + ) + set (WINDOWS_UTILITY_SOURCE_FILES + windows/parc_Utils.c + windows/getopt.c + windows/getopt_long.c + ) +endif() + set(LIBPARC_LOGGING_SOURCE_FILES logging/parc_Log.c logging/parc_LogEntry.c @@ -352,6 +365,13 @@ if(ENABLE_TEST) ) endif() +if(WIN32) + list(APPEND LIBPARC_SOURCE_FILES + ${WINDOWS_UTILITY_SOURCE_FILES} + ${WINDOWS_UTILITY_HEADER_FILES} + ) +endif() + set(LIBPARC_ALGOL_FILES ${LIBPARC_ALGOL_SOURCE_FILES} ${LIBPARC_ALGOL_HEADER_FILES}) list(SORT LIBPARC_ALGOL_FILES) source_group(algol FILES ${LIBPARC_ALGOL_FILES}) @@ -381,9 +401,12 @@ if(COMPILE_FOR_IOS OR ANDROID_API) ) else() add_library(parc STATIC ${LIBPARC_SOURCE_FILES}) + target_link_libraries(parc ${LIBEVENT_LIBRARIES}) + target_link_libraries(parc ${OPENSSL_LIBRARIES}) add_library(parc.shared SHARED ${LIBPARC_SOURCE_FILES}) target_link_libraries(parc.shared ${LIBEVENT_LIBRARIES}) target_link_libraries(parc.shared ${OPENSSL_LIBRARIES}) + target_link_libraries(parc.shared ${PARC_BIN_LIBRARIES}) set_target_properties(parc.shared PROPERTIES C_STANDARD 99 SOVERSION 1 @@ -411,6 +434,9 @@ install(FILES ${LIBPARC_BASE_HEADER_FILES} DESTINATION include/parc COMPON install(FILES ${LIBPARC_STATISTICS_HEADER_FILES} DESTINATION include/parc/statistics COMPONENT headers) install(FILES ${LIBPARC_MEMORY_HEADER_FILES} DESTINATION include/parc/memory COMPONENT headers) install(FILES ${LIBPARC_ASSERT_HEADER_FILES} DESTINATION include/parc/assert COMPONENT headers) +if(WIN32) + install(FILES ${WINDOWS_UTILITY_HEADER_FILES} DESTINATION include/parc/windows COMPONENT headers) +endif() if(ENABLE_TEST) install(FILES ${LIBPARC_TESTING_HEADER_FILES} DESTINATION include/parc/testing COMPONENT headers) diff --git a/libparc/parc/algol/internal_parc_Event.c b/libparc/parc/algol/internal_parc_Event.c old mode 100755 new mode 100644 index 54c193ea..9335e1e0 --- a/libparc/parc/algol/internal_parc_Event.c +++ b/libparc/parc/algol/internal_parc_Event.c @@ -13,10 +13,6 @@ * limitations under the License. */ -/** - */ -#include - #include #include #include "internal_parc_Event.h" diff --git a/libparc/parc/algol/internal_parc_Event.h b/libparc/parc/algol/internal_parc_Event.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_AtomicInteger.c b/libparc/parc/algol/parc_AtomicInteger.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_AtomicInteger.h b/libparc/parc/algol/parc_AtomicInteger.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Base64.c b/libparc/parc/algol/parc_Base64.c old mode 100755 new mode 100644 index cac0aa4d..e4e66437 --- a/libparc/parc/algol/parc_Base64.c +++ b/libparc/parc/algol/parc_Base64.c @@ -71,7 +71,9 @@ const uint8_t decodeTable[256] = { '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~' }; +#ifndef min #define min(a, b) ((a < b) ? a : b) +#endif /** * Encode the 3-byte quantum pointed to by quantum into 4 encoded characters. @@ -198,7 +200,7 @@ parcBase64_Encode(PARCBufferComposer *result, PARCBuffer *plainText) } PARCBufferComposer * -parcBase64_EncodeArray(PARCBufferComposer *output, size_t length, const uint8_t array[length]) +parcBase64_EncodeArray(PARCBufferComposer *output, size_t length, const uint8_t *array) { size_t offset = 0; @@ -233,7 +235,7 @@ parcBase64_DecodeString(PARCBufferComposer *output, const char *encodedString) } PARCBufferComposer * -parcBase64_DecodeArray(PARCBufferComposer *output, size_t length, const uint8_t array[length]) +parcBase64_DecodeArray(PARCBufferComposer *output, size_t length, const uint8_t *array) { size_t offset = 0; bool success = true; diff --git a/libparc/parc/algol/parc_BitVector.c b/libparc/parc/algol/parc_BitVector.c old mode 100755 new mode 100644 index 21a66c23..68a86459 --- a/libparc/parc/algol/parc_BitVector.c +++ b/libparc/parc/algol/parc_BitVector.c @@ -171,7 +171,7 @@ parcBitVector_SetVector(PARCBitVector *parcBitVector, const PARCBitVector *bitsT parcAssertNotNull(parcBitVector, "parcBitVector_SetVector passed a NULL parcBitVector"); parcAssertNotNull(parcBitVector, "parcBitVector_SetVector passed a NULL vector of bits to set"); int settingBit = 0; - for (int i = 0; i < bitsToSet->numberOfBitsSet; i++) { + for (unsigned int i = 0; i < bitsToSet->numberOfBitsSet; i++) { settingBit = parcBitVector_NextBitSet(bitsToSet, settingBit); parcAssertTrue(settingBit != -1, "Number of bits claimed set inconsistent with bits found"); parcBitVector_Set(parcBitVector, settingBit); @@ -220,8 +220,8 @@ parcBitVector_ClearVector(PARCBitVector *parcBitVector, const PARCBitVector *bit return; } - int clearingBit = 0; - for (int i = 0; i < bitsToClear->numberOfBitsSet; i++) { + unsigned int clearingBit = 0; + for (unsigned int i = 0; i < bitsToClear->numberOfBitsSet; i++) { clearingBit = parcBitVector_NextBitSet(bitsToClear, clearingBit); // only clear up to the end of the original vector if (clearingBit >= parcBitVector->bitLength) { @@ -271,7 +271,7 @@ parcBitVector_Contains(const PARCBitVector *parcBitVector, const PARCBitVector * bool result = true; int testBit = 0; - for (int i = 0; i < testVector->numberOfBitsSet; i++, testBit++) { + for (unsigned int i = 0; i < testVector->numberOfBitsSet; i++, testBit++) { testBit = parcBitVector_NextBitSet(testVector, testBit); if (parcBitVector_Get(parcBitVector, testBit) != 1) { result = false; diff --git a/libparc/parc/algol/parc_BitVector.h b/libparc/parc/algol/parc_BitVector.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Buffer.c b/libparc/parc/algol/parc_Buffer.c old mode 100755 new mode 100644 index 20520f9c..261aac6d --- a/libparc/parc/algol/parc_Buffer.c +++ b/libparc/parc/algol/parc_Buffer.c @@ -761,7 +761,7 @@ parcBuffer_GetUint8(PARCBuffer *buffer) } PARCBuffer * -parcBuffer_GetBytes(PARCBuffer *buffer, size_t length, uint8_t array[length]) +parcBuffer_GetBytes(PARCBuffer *buffer, size_t length, uint8_t *array) { parcBuffer_OptionalAssertValid(buffer); _trapIfBufferUnderflow(buffer, length); @@ -863,7 +863,7 @@ parcBuffer_PutAtIndex(PARCBuffer *buffer, size_t index, uint8_t value) } PARCBuffer * -parcBuffer_PutArray(PARCBuffer *buffer, size_t arrayLength, const uint8_t array[arrayLength]) +parcBuffer_PutArray(PARCBuffer *buffer, size_t arrayLength, const uint8_t *array) { parcBuffer_OptionalAssertValid(buffer); parcAssertTrue(parcBuffer_Remaining(buffer) >= arrayLength, @@ -977,7 +977,7 @@ parcBuffer_ToHexString(const PARCBuffer *buffer) } bool -parcBuffer_SkipOver(PARCBuffer *buffer, size_t length, const uint8_t bytesToSkipOver[length]) +parcBuffer_SkipOver(PARCBuffer *buffer, size_t length, const uint8_t *bytesToSkipOver) { while (parcBuffer_Remaining(buffer) > 0) { uint8_t character = parcBuffer_GetUint8(buffer); @@ -990,7 +990,7 @@ parcBuffer_SkipOver(PARCBuffer *buffer, size_t length, const uint8_t bytesToSkip } bool -parcBuffer_SkipTo(PARCBuffer *buffer, size_t length, const uint8_t bytesToSkipTo[length]) +parcBuffer_SkipTo(PARCBuffer *buffer, size_t length, const uint8_t *bytesToSkipTo) { bool result = false; diff --git a/libparc/parc/algol/parc_Buffer.h b/libparc/parc/algol/parc_Buffer.h index 665019db..fdc205f8 100644 --- a/libparc/parc/algol/parc_Buffer.h +++ b/libparc/parc/algol/parc_Buffer.h @@ -362,7 +362,7 @@ PARCBuffer *parcBuffer_AllocateCString(const char *string); * } * @endcode */ -PARCBuffer *parcBuffer_CreateFromArray(const void *bytes, size_t length); +PARCBuffer *parcBuffer_CreateFromArray(const void *bytes, const size_t length); /** * Parse a null-terminated hexadecimal string to create a new `PARCBuffer` instance. diff --git a/libparc/parc/algol/parc_BufferChunker.c b/libparc/parc/algol/parc_BufferChunker.c index f3a4ab67..03c67f58 100644 --- a/libparc/parc/algol/parc_BufferChunker.c +++ b/libparc/parc/algol/parc_BufferChunker.c @@ -20,7 +20,9 @@ #include #include +#ifndef _WIN32 #include +#endif #include #include diff --git a/libparc/parc/algol/parc_BufferChunker.h b/libparc/parc/algol/parc_BufferChunker.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_BufferComposer.c b/libparc/parc/algol/parc_BufferComposer.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_BufferComposer.h b/libparc/parc/algol/parc_BufferComposer.h old mode 100755 new mode 100644 index 25c69258..e0ec5112 --- a/libparc/parc/algol/parc_BufferComposer.h +++ b/libparc/parc/algol/parc_BufferComposer.h @@ -30,6 +30,7 @@ struct parc_buffer_composer; typedef struct parc_buffer_composer PARCBufferComposer; +#include #include extern parcObjectDescriptor_Declaration(PARCBufferComposer); diff --git a/libparc/parc/algol/parc_BufferDictionary.c b/libparc/parc/algol/parc_BufferDictionary.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_BufferDictionary.h b/libparc/parc/algol/parc_BufferDictionary.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_ByteArray.c b/libparc/parc/algol/parc_ByteArray.c index 1d81d211..e4cc0480 100644 --- a/libparc/parc/algol/parc_ByteArray.c +++ b/libparc/parc/algol/parc_ByteArray.c @@ -108,7 +108,7 @@ parcByteArray_Allocate(const size_t length) } PARCByteArray * -parcByteArray_Wrap(const size_t length, uint8_t array[length]) +parcByteArray_Wrap(const size_t length, uint8_t *array) { if (array != NULL) { PARCByteArray *result = parcObject_CreateInstance(PARCByteArray); @@ -209,7 +209,7 @@ parcByteArray_Compare(const PARCByteArray *x, const PARCByteArray *y) } PARCByteArray * -parcByteArray_PutBytes(PARCByteArray *result, size_t offset, size_t length, const uint8_t source[length]) +parcByteArray_PutBytes(PARCByteArray *result, size_t offset, size_t length, const uint8_t *source) { parcByteArray_OptionalAssertValid(result); parcTrapOutOfBoundsIf(offset > result->length, @@ -224,7 +224,7 @@ parcByteArray_PutBytes(PARCByteArray *result, size_t offset, size_t length, cons } PARCByteArray * -parcByteArray_GetBytes(const PARCByteArray *result, size_t offset, size_t length, uint8_t array[length]) +parcByteArray_GetBytes(const PARCByteArray *result, size_t offset, size_t length, uint8_t *array) { parcByteArray_OptionalAssertValid(result); @@ -265,7 +265,7 @@ static void _parcByteArray_PrettyPrintLine(const unsigned char *memory, size_t offset, size_t length) { int bytesPerLine = 16; - char accumulator[bytesPerLine + 1]; + char *accumulator = (char *)malloc(sizeof(char) * (bytesPerLine + 1)); memset(accumulator, ' ', bytesPerLine); accumulator[bytesPerLine] = 0; @@ -286,6 +286,7 @@ _parcByteArray_PrettyPrintLine(const unsigned char *memory, size_t offset, size_ } } printf(" %s\n", accumulator); + free(accumulator); } void diff --git a/libparc/parc/algol/parc_ByteArray.h b/libparc/parc/algol/parc_ByteArray.h index c7a26285..71047339 100644 --- a/libparc/parc/algol/parc_ByteArray.h +++ b/libparc/parc/algol/parc_ByteArray.h @@ -156,7 +156,7 @@ PARCByteArray *parcByteArray_Allocate(const size_t capacity); * } * @endcode */ -PARCByteArray *parcByteArray_Wrap(size_t capacity, uint8_t *array); +PARCByteArray *parcByteArray_Wrap(const size_t capacity, uint8_t *array); /** * Returns the pointer to the `uint8_t` array that backs this `PARCByteArray`. @@ -560,7 +560,7 @@ PARCHashCode parcByteArray_HashCode(const PARCByteArray *array); * } * @endcode */ -uint8_t *parcByteArray_AddressOfIndex(const PARCByteArray *array, size_t index); +uint8_t *parcByteArray_AddressOfIndex(const PARCByteArray *array, const size_t index); /** * Pretty print the given `PARCByteArray` instance. diff --git a/libparc/parc/algol/parc_CMacro.h b/libparc/parc/algol/parc_CMacro.h index a47129ea..0b948d2f 100644 --- a/libparc/parc/algol/parc_CMacro.h +++ b/libparc/parc/algol/parc_CMacro.h @@ -35,7 +35,10 @@ * parcCMacro_IfElse is a c-macro trick for implementing a macro If-Else switch. * It uses parcCMacro_ThirdParam to select between A or B depending on whether __VA_ARGS__ expands to a comma. */ -#define parcCMacro_IfElse(A, B, ...) parcCMacro_ThirdParam(__VA_ARGS__, A, B, NOOP) + + +#define EXPAND( x ) x +#define parcCMacro_IfElse(A, B, ...) EXPAND(parcCMacro_ThirdParam( __VA_ARGS__ , A, B, NOOP)) /** \cond */ #define _parcCMacro_Cat_(A, B) A ## B diff --git a/libparc/parc/algol/parc_Chunker.c b/libparc/parc/algol/parc_Chunker.c old mode 100755 new mode 100644 index b84ed05f..f6c94b6d --- a/libparc/parc/algol/parc_Chunker.c +++ b/libparc/parc/algol/parc_Chunker.c @@ -13,14 +13,13 @@ * limitations under the License. */ -/** - */ +#ifndef _WIN32 +#include +#endif #include - #include #include -#include #include #include diff --git a/libparc/parc/algol/parc_Chunker.h b/libparc/parc/algol/parc_Chunker.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Clock.c b/libparc/parc/algol/parc_Clock.c old mode 100755 new mode 100644 index 95cf74bc..58624fc9 --- a/libparc/parc/algol/parc_Clock.c +++ b/libparc/parc/algol/parc_Clock.c @@ -68,7 +68,7 @@ _counterClock_GetTimeval(const PARCClock *clock, struct timeval *output) uint64_t value = parcAtomicInteger_Uint64Increment(&cc->counter); // put 19 bits in the micro-seconds so it is never larger than 1E+6 - output->tv_sec = value >> 19; + output->tv_sec = (long) (value >> 19); output->tv_usec = value & 0x7FFFF; } @@ -94,6 +94,17 @@ parcClock_Counter(void) return clock; } +#ifdef _WIN32 +static int _clock_gettime(int value, struct timespec *spec) { + __int64 wintime; + GetSystemTimeAsFileTime((FILETIME *)&wintime); + wintime -= 116444736000000000i64; //1jan1601 to 1jan1970 + spec->tv_sec = wintime / 10000000i64; //seconds + spec->tv_nsec = wintime % 10000000i64 * 100; //nano-seconds + return 0; +} +#endif + // =========== // Wallclock @@ -105,6 +116,11 @@ _wallclock_GetTimeval(const PARCClock *dummy __attribute__((unused)), struct tim clock_gettime(CLOCK_REALTIME, &ts); output->tv_sec = ts.tv_sec; output->tv_usec = ts.tv_nsec / 1000; +#elif _WIN32 + struct timespec ts; + _clock_gettime(TIME_UTC, &ts); + output->tv_sec = (long)ts.tv_sec; + output->tv_usec = ts.tv_nsec / 1000; #else clock_serv_t clockService; mach_timespec_t mts; @@ -167,6 +183,11 @@ _monoclock_GetTimeval(const PARCClock *dummy __attribute__((unused)), struct tim clock_gettime(CLOCK_MONOTONIC_RAW, &ts); output->tv_sec = ts.tv_sec; output->tv_usec = ts.tv_nsec / 1000; +#elif _WIN32 + struct timespec ts; + _clock_gettime(TIME_UTC, &ts); + output->tv_sec = (long)ts.tv_sec; + output->tv_usec = ts.tv_nsec / 1000; #else clock_serv_t clockService; mach_timespec_t mts; diff --git a/libparc/parc/algol/parc_Clock.h b/libparc/parc/algol/parc_Clock.h old mode 100755 new mode 100644 index 35c77fd7..698773b9 --- a/libparc/parc/algol/parc_Clock.h +++ b/libparc/parc/algol/parc_Clock.h @@ -98,8 +98,11 @@ #ifndef PARC_parc_Clock_h #define PARC_parc_Clock_h -#include +#ifndef _WIN32 #include +#endif + +#include struct parc_clock; typedef struct parc_clock PARCClock; diff --git a/libparc/parc/algol/parc_Collection.h b/libparc/parc/algol/parc_Collection.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Deque.c b/libparc/parc/algol/parc_Deque.c index 84808766..c0b83551 100644 --- a/libparc/parc/algol/parc_Deque.c +++ b/libparc/parc/algol/parc_Deque.c @@ -13,17 +13,15 @@ * limitations under the License. */ -/** - */ -#include - -#include +#ifndef _WIN32 +#include +#endif +#include #include -#include +#include #include - #include #include #include diff --git a/libparc/parc/algol/parc_Deque.h b/libparc/parc/algol/parc_Deque.h old mode 100755 new mode 100644 index 57dd39b1..8b988dee --- a/libparc/parc/algol/parc_Deque.h +++ b/libparc/parc/algol/parc_Deque.h @@ -345,7 +345,7 @@ bool parcDeque_Equals(const PARCDeque *x, const PARCDeque *y); * @endcode * */ -void parcDeque_Display(const PARCDeque *deque, int indentation); +void parcDeque_Display(const PARCDeque *deque, const int indentation); /** * Wakes up a single thread that is waiting on this object (see `parcDeque_Wait)`. diff --git a/libparc/parc/algol/parc_Dictionary.c b/libparc/parc/algol/parc_Dictionary.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Dictionary.h b/libparc/parc/algol/parc_Dictionary.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_DisplayIndented.c b/libparc/parc/algol/parc_DisplayIndented.c old mode 100755 new mode 100644 index 39e1d76e..a17e7f04 --- a/libparc/parc/algol/parc_DisplayIndented.c +++ b/libparc/parc/algol/parc_DisplayIndented.c @@ -13,19 +13,18 @@ * limitations under the License. */ -/** - */ -#include - -#include +#ifndef _WIN32 +#include +#endif +#include #include #include #include -#include #include #include +#include #include static char *_spaces = " "; @@ -38,7 +37,7 @@ _indent(int indentation) size_t result = 0; if (indentation > 0) { - result = write(1, _spaces, indentation * _indentationFactor); + result = write(1, _spaces, (unsigned int)(indentation * _indentationFactor)); parcAssertTrue(result == (indentation * _indentationFactor), "Write(2) failed to write %zd bytes.", indentation * _indentationFactor); } @@ -54,11 +53,11 @@ _parcDisplayIndented_Print(int indentation, char *string) while (start != NULL) { _indent(indentation); if (end != NULL) { - ssize_t nwritten = write(1, start, end - start + 1); + ssize_t nwritten = write(1, start, (unsigned int)(end - start + 1)); parcAssertTrue(nwritten >= 0, "Error calling write"); start = end + 1; } else { - ssize_t nwritten = write(1, start, strlen(start)); + ssize_t nwritten = write(1, start, (unsigned int)strlen(start)); parcAssertTrue(nwritten >= 0, "Error calling write"); break; } @@ -87,11 +86,10 @@ parcDisplayIndented_PrintLine(int indentation, const char *format, ...) } void -parcDisplayIndented_PrintMemory(int indentation, size_t length, const char memory[length]) +parcDisplayIndented_PrintMemory(int indentation, size_t length, const char *memory) { int bytesPerLine = 16; - - char accumulator[bytesPerLine + 1]; + char *accumulator = (char *)malloc(sizeof(char)*(bytesPerLine + 1)); memset(accumulator, ' ', bytesPerLine); accumulator[bytesPerLine] = 0; @@ -111,4 +109,5 @@ parcDisplayIndented_PrintMemory(int indentation, size_t length, const char memor offset += bytesInLine; } printf(" %s]\n", accumulator); + free(accumulator); } diff --git a/libparc/parc/algol/parc_ElasticString.h b/libparc/parc/algol/parc_ElasticString.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Environment.c b/libparc/parc/algol/parc_Environment.c index 2955a139..2ca11b4d 100644 --- a/libparc/parc/algol/parc_Environment.c +++ b/libparc/parc/algol/parc_Environment.c @@ -13,15 +13,15 @@ * limitations under the License. */ -/** - */ -#include -#include -#include -#include +#ifndef _WIN32 #include +#include +#endif +#include +#include +#include #include #include @@ -35,11 +35,23 @@ parcEnvironment_GetHomeDirectory(void) PARCFile * parcEnvironment_HomeDirectory(void) { - char *path; +#ifdef _WIN32 + char *pValue; + size_t len; + errno_t err = _dupenv_s(&pValue, &len, "USERPROFILE"); + if (err != 0) { + return parcFile_Create(pValue); + } + else { + return NULL; + } +#else + char *path; if ((path = getenv("HOME")) == NULL) { path = getpwuid(getuid())->pw_dir; } - return parcFile_Create(path); +#endif + } diff --git a/libparc/parc/algol/parc_Environment.h b/libparc/parc/algol/parc_Environment.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Event.c b/libparc/parc/algol/parc_Event.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_EventBuffer.c b/libparc/parc/algol/parc_EventBuffer.c index 6293680c..9867d916 100644 --- a/libparc/parc/algol/parc_EventBuffer.c +++ b/libparc/parc/algol/parc_EventBuffer.c @@ -162,7 +162,7 @@ parcEventBuffer_copyOut(PARCEventBuffer *readBuffer, void *data_out, size_t leng { parcAssertNotNull(data_out, "parcEventBuffer_Copy was passed a null data_out buffer\n"); parcEventBuffer_OptionalAssertValid(readBuffer); - return evbuffer_copyout(readBuffer->evbuffer, data_out, length); + return (int)evbuffer_copyout(readBuffer->evbuffer, data_out, length); } int diff --git a/libparc/parc/algol/parc_EventBuffer.h b/libparc/parc/algol/parc_EventBuffer.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_EventQueue.c b/libparc/parc/algol/parc_EventQueue.c old mode 100755 new mode 100644 index dffab1e7..3542b408 --- a/libparc/parc/algol/parc_EventQueue.c +++ b/libparc/parc/algol/parc_EventQueue.c @@ -176,7 +176,7 @@ parcEventQueue_SetFileDescriptor(PARCEventQueue *parcEventQueue, int fd) int parcEventQueue_GetFileDescriptor(PARCEventQueue *parcEventQueue) { - return bufferevent_getfd(parcEventQueue->buffereventBuffer); + return (int)bufferevent_getfd(parcEventQueue->buffereventBuffer); } PARCEventType @@ -239,7 +239,7 @@ parcEventQueue_Printf(PARCEventQueue *parcEventQueue, const char *fmt, ...) int parcEventQueue_Read(PARCEventQueue *parcEventQueue, void *data, size_t dataLength) { - return bufferevent_read(parcEventQueue->buffereventBuffer, data, dataLength); + return (int)bufferevent_read(parcEventQueue->buffereventBuffer, data, dataLength); } int diff --git a/libparc/parc/algol/parc_EventQueue.h b/libparc/parc/algol/parc_EventQueue.h index 282df302..d6ed1bce 100644 --- a/libparc/parc/algol/parc_EventQueue.h +++ b/libparc/parc/algol/parc_EventQueue.h @@ -27,8 +27,11 @@ #ifndef libparc_parc_EventQueue_h #define libparc_parc_EventQueue_h -#include +#ifndef _WIN32 #include +#endif + +#include #include diff --git a/libparc/parc/algol/parc_EventScheduler.c b/libparc/parc/algol/parc_EventScheduler.c old mode 100755 new mode 100644 index 3983740e..59103f49 --- a/libparc/parc/algol/parc_EventScheduler.c +++ b/libparc/parc/algol/parc_EventScheduler.c @@ -13,16 +13,15 @@ * limitations under the License. */ -/** - */ -#include - -#include +#ifndef _WIN32 +#include +#endif +#include #include -#include #include "internal_parc_Event.h" +#include #include #include #include diff --git a/libparc/parc/algol/parc_EventSignal.c b/libparc/parc/algol/parc_EventSignal.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_EventSignal.h b/libparc/parc/algol/parc_EventSignal.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_EventSocket.c b/libparc/parc/algol/parc_EventSocket.c old mode 100755 new mode 100644 index 62aa10bc..c44c824a --- a/libparc/parc/algol/parc_EventSocket.c +++ b/libparc/parc/algol/parc_EventSocket.c @@ -35,7 +35,10 @@ static int _parc_event_socket_debug_enabled = 0; * Current implementation based on top of libevent2 */ +#ifndef _WIN32 #include +#endif + #include /** @@ -71,7 +74,7 @@ _parc_evconn_error_callback(struct evconnlistener *listener, void *ctx) PARCEventSocket *parcEventSocket = (PARCEventSocket *) ctx; int error = EVUTIL_SOCKET_ERROR(); - char *errorString = evutil_socket_error_to_string(error); + char *errorString = (char *)evutil_socket_error_to_string(error); parcEventSocket_LogDebug(parcEventSocket, "_parc_evconn_error_callback(error=%d,errorString=%s,parcEventSocket=%p)\n", error, errorString, parcEventSocket); diff --git a/libparc/parc/algol/parc_EventSocket.h b/libparc/parc/algol/parc_EventSocket.h old mode 100755 new mode 100644 index 48a11b25..286e528d --- a/libparc/parc/algol/parc_EventSocket.h +++ b/libparc/parc/algol/parc_EventSocket.h @@ -27,8 +27,11 @@ #ifndef libparc_parc_EventSocket_h #define libparc_parc_EventSocket_h -#include +#ifndef _WIN32 #include +#endif + +#include /** * Current implementation based on top of libevent2 diff --git a/libparc/parc/algol/parc_EventTimer.c b/libparc/parc/algol/parc_EventTimer.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_EventTimer.h b/libparc/parc/algol/parc_EventTimer.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_File.c b/libparc/parc/algol/parc_File.c index 353ffcca..f39a31af 100644 --- a/libparc/parc/algol/parc_File.c +++ b/libparc/parc/algol/parc_File.c @@ -25,20 +25,21 @@ #define __USE_XOPEN_EXTENDED #endif //__USE_XOPEN_EXTENDED -#include +#ifndef _WIN32 #include +#include +#endif + +#include #include #include - -#include #include #include #include #include #include - #include #include #include @@ -134,7 +135,13 @@ parcFile_Mkdir(const PARCFile *file) parcFile_OptionalAssertValid(file); char *string = parcPathName_ToString(file->pathName); + +#ifndef _WIN32 bool result = (mkdir(string, 0777) == 0); +#else + bool result = (CreateDirectory(string, NULL) == 0); +#endif + parcMemory_Deallocate((void **) &string); return result; @@ -167,6 +174,7 @@ parcFile_IsDirectory(const PARCFile *file) return result; } +#ifndef _WIN32 static int _deleteNode(const char *path, const struct stat *stat, int flag, struct FTW *ftwbuf) { @@ -179,6 +187,7 @@ _deleteNode(const char *path, const struct stat *stat, int flag, struct FTW *ftw } return result; } +#endif /** * @function parcFile_Delete @@ -201,16 +210,21 @@ parcFile_Delete(const PARCFile *file) bool result = false; if (parcFile_IsDirectory(file)) { - // depth first, dont't follow symlinks, do not cross mount points. - int flags = FTW_DEPTH | FTW_PHYS | FTW_MOUNT; - // maximum 20 fds open at a time - int maximumFileDescriptors = 20; +#ifndef _WIN32 + // depth first, dont't follow symlinks, do not cross mount points. + int flags = FTW_DEPTH | FTW_PHYS | FTW_MOUNT; + // maximum 20 fds open at a time + int maximumFileDescriptors = 20; + + int failure = nftw(string, _deleteNode, maximumFileDescriptors, flags); + parcAssertFalse(failure, "Error on recursive delete: (%d) %s", errno, strerror(errno)); - int failure = nftw(string, _deleteNode, maximumFileDescriptors, flags); - parcAssertFalse(failure, "Error on recursive delete: (%d) %s", errno, strerror(errno)); + result = failure == false; +#else + result = RemoveDirectoryA(string); +#endif - result = failure == false; } else { result = (unlink(string) == 0); } diff --git a/libparc/parc/algol/parc_File.h b/libparc/parc/algol/parc_File.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_FileChunker.c b/libparc/parc/algol/parc_FileChunker.c index d7acd58e..0af63e15 100644 --- a/libparc/parc/algol/parc_FileChunker.c +++ b/libparc/parc/algol/parc_FileChunker.c @@ -16,18 +16,17 @@ /** */ +#ifndef _WIN32 #include +#endif #include #include -#include #include #include #include - #include - #include PARCChunkerInterface *PARCFileChunkerAsChunker = &(PARCChunkerInterface) { @@ -174,7 +173,7 @@ _parcChunker_NextFromBuffer(PARCFileChunker *chunker, _ChunkerState *state) { size_t chunkSize = state->nextChunkSize; - parcRandomAccessFile_Seek(chunker->fhandle, state->position, PARCRandomAccessFilePosition_Start); + parcRandomAccessFile_Seek(chunker->fhandle, (long)(state->position), PARCRandomAccessFilePosition_Start); PARCBuffer *slice = parcBuffer_Allocate(chunkSize); parcRandomAccessFile_Read(chunker->fhandle, slice); diff --git a/libparc/parc/algol/parc_FileChunker.h b/libparc/parc/algol/parc_FileChunker.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_FileInputStream.c b/libparc/parc/algol/parc_FileInputStream.c old mode 100755 new mode 100644 index 186d07b5..0ccd912d --- a/libparc/parc/algol/parc_FileInputStream.c +++ b/libparc/parc/algol/parc_FileInputStream.c @@ -13,15 +13,15 @@ * limitations under the License. */ -/** - */ -#include +#ifndef _WIN32 +#include +#include +#endif +#include #include #include #include -#include -#include #include #include @@ -88,7 +88,7 @@ parcFileInputStream_Read(PARCFileInputStream *inputStream, PARCBuffer *buffer) { while (parcBuffer_HasRemaining(buffer)) { void *buf = parcBuffer_Overlay(buffer, 0); - ssize_t nread = read(inputStream->fd, buf, parcBuffer_Remaining(buffer)); + ssize_t nread = read(inputStream->fd, buf, (unsigned int)parcBuffer_Remaining(buffer)); if (nread < 0) { break; } diff --git a/libparc/parc/algol/parc_FileInputStream.h b/libparc/parc/algol/parc_FileInputStream.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_FileOutputStream.c b/libparc/parc/algol/parc_FileOutputStream.c old mode 100755 new mode 100644 index 3e5c8cd6..c119e67f --- a/libparc/parc/algol/parc_FileOutputStream.c +++ b/libparc/parc/algol/parc_FileOutputStream.c @@ -13,15 +13,14 @@ * limitations under the License. */ -/** - */ -#include +#ifndef _WIN32 +#include +#endif +#include #include -#include #include - #include #include @@ -75,7 +74,7 @@ parcFileOutputStream_Write(PARCFileOutputStream *outputStream, PARCBuffer *buffe size_t remaining = parcBuffer_Remaining(buffer); size_t chunkSize = remaining > maximumChunkSize ? maximumChunkSize : remaining; void *buf = parcBuffer_Overlay(buffer, chunkSize); - ssize_t nwritten = write(outputStream->fd, buf, chunkSize); + ssize_t nwritten = write(outputStream->fd, buf, (unsigned int)chunkSize); if (nwritten == -1) { break; } diff --git a/libparc/parc/algol/parc_Hash.c b/libparc/parc/algol/parc_Hash.c old mode 100755 new mode 100644 index 1884c74c..fae29a63 --- a/libparc/parc/algol/parc_Hash.c +++ b/libparc/parc/algol/parc_Hash.c @@ -18,11 +18,13 @@ * website for details on the algorithm: http://www.isthe.com/chongo/tech/comp/fnv * */ -#include -#include +#ifndef _WIN32 #include +#endif +#include +#include #include #include diff --git a/libparc/parc/algol/parc_Hash.h b/libparc/parc/algol/parc_Hash.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_HashCode.c b/libparc/parc/algol/parc_HashCode.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_HashCode.h b/libparc/parc/algol/parc_HashCode.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_HashCodeTable.c b/libparc/parc/algol/parc_HashCodeTable.c old mode 100755 new mode 100644 index 9531e312..d4c5a7ae --- a/libparc/parc/algol/parc_HashCodeTable.c +++ b/libparc/parc/algol/parc_HashCodeTable.c @@ -165,7 +165,7 @@ _rehash(LinearAddressingHashTable *old_table, LinearAddressingHashTable *new_tab } static void -_expand(PARCHashCodeTable *hashCodeTable) +_expandTable(PARCHashCodeTable *hashCodeTable) { LinearAddressingHashTable temp_table; LinearAddressingHashTable *old_table = &hashCodeTable->hashtable; @@ -269,7 +269,7 @@ parcHashCodeTable_Add(PARCHashCodeTable *table, void *key, void *data) parcAssertNotNull(data, "Parameter data must be non-null"); if (table->hashtable.tableSize >= table->hashtable.expandThreshold) { - _expand(table); + _expandTable(table); } HashCodeType hashcode = table->keyHashCodeFunc(key); @@ -278,7 +278,7 @@ parcHashCodeTable_Add(PARCHashCodeTable *table, void *key, void *data) do { result = _innerTableAdd(&table->hashtable, table->keyEqualsFunc, hashcode, key, data); if (result == ADD_NOSPACE) { - _expand(table); + _expandTable(table); } } while (result == ADD_NOSPACE); diff --git a/libparc/parc/algol/parc_HashMap.c b/libparc/parc/algol/parc_HashMap.c index 5e73a4c3..58137b20 100644 --- a/libparc/parc/algol/parc_HashMap.c +++ b/libparc/parc/algol/parc_HashMap.c @@ -91,7 +91,7 @@ _parcHashMap_GetEntry(const PARCHashMap *hashMap, const PARCObject *key) { PARCHashCode keyHash = parcObject_HashCode(key); - int bucket = keyHash % hashMap->capacity; + int bucket = (int)(keyHash % hashMap->capacity); _PARCHashMapEntry *result = NULL; @@ -399,7 +399,7 @@ _parcHashMap_Resize(PARCHashMap *hashMap, size_t newCapacity) while (parcIterator_HasNext(elementIt)) { _PARCHashMapEntry *entry = parcIterator_Next(elementIt); PARCHashCode keyHash = parcObject_HashCode(entry->key); - int newBucket = keyHash % newCapacity; + int newBucket = (int)(keyHash % newCapacity); if (newBuckets[newBucket] == NULL) { newBuckets[newBucket] = parcLinkedList_Create(); } @@ -422,7 +422,7 @@ parcHashMap_Remove(PARCHashMap *hashMap, const PARCObject *key) { PARCHashCode keyHash = parcObject_HashCode(key); - int bucket = keyHash % hashMap->capacity; + int bucket = (int)(keyHash % hashMap->capacity); bool result = false; @@ -476,7 +476,7 @@ parcHashMap_Put(PARCHashMap *hashMap, const PARCObject *key, const PARCObject *v entry = _parcHashMapEntry_Create(key, value); PARCHashCode keyHash = parcObject_HashCode(key); - int bucket = keyHash % hashMap->capacity; + int bucket = (int)(keyHash % hashMap->capacity); if (hashMap->buckets[bucket] == NULL) { hashMap->buckets[bucket] = parcLinkedList_Create(); @@ -560,7 +560,7 @@ _parcHashMap_Init(PARCHashMap *map __attribute__((unused))) state->listIterator = NULL; for (size_t i = 0; i < map->capacity; ++i) { if (map->buckets[i] != NULL) { - state->bucket = i; + state->bucket = (int)i; state->listIterator = parcLinkedList_CreateIterator(map->buckets[i]); break; } diff --git a/libparc/parc/algol/parc_HashMap.h b/libparc/parc/algol/parc_HashMap.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_InputStream.c b/libparc/parc/algol/parc_InputStream.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_InputStream.h b/libparc/parc/algol/parc_InputStream.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Iterator.c b/libparc/parc/algol/parc_Iterator.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_JSON.c b/libparc/parc/algol/parc_JSON.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_JSON.h b/libparc/parc/algol/parc_JSON.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_JSONArray.c b/libparc/parc/algol/parc_JSONArray.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_JSONArray.h b/libparc/parc/algol/parc_JSONArray.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_JSONPair.c b/libparc/parc/algol/parc_JSONPair.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_JSONPair.h b/libparc/parc/algol/parc_JSONPair.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_JSONParser.c b/libparc/parc/algol/parc_JSONParser.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_JSONParser.h b/libparc/parc/algol/parc_JSONParser.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_JSONValue.c b/libparc/parc/algol/parc_JSONValue.c old mode 100755 new mode 100644 index f5aff0b4..8b9af28d --- a/libparc/parc/algol/parc_JSONValue.c +++ b/libparc/parc/algol/parc_JSONValue.c @@ -757,7 +757,7 @@ parcJSONValue_GetBoolean(const PARCJSONValue *value) static long double _parcJSONValue_GetNumber(const PARCJSONValue *value) { - long double fraction = value->value.number.fraction / powl(10.0, value->value.number.fractionLog10); + long double fraction = (long double)value->value.number.fraction / (long double)powl(10.0, (long double) value->value.number.fractionLog10); long double number = (long double) value->value.number.sign * ((long double) value->value.number.whole + fraction); long double result = number * powl(10.0, (long double) value->value.number.exponent); @@ -815,7 +815,7 @@ parcJSONValue_GetTimeval(const PARCJSONValue *jsonTimeval, struct timeval *timev PARCJSON *json = parcJSONValue_GetJSON(jsonTimeval); PARCJSONValue *value = parcJSON_GetValueByName(json, "seconds"); - timeval->tv_sec = parcJSONValue_GetInteger(value); + timeval->tv_sec = (long)parcJSONValue_GetInteger(value); value = parcJSON_GetValueByName(json, "micros"); timeval->tv_usec = (int) parcJSONValue_GetInteger(value); diff --git a/libparc/parc/algol/parc_JSONValue.h b/libparc/parc/algol/parc_JSONValue.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_KeyValue.c b/libparc/parc/algol/parc_KeyValue.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_KeyValue.h b/libparc/parc/algol/parc_KeyValue.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_KeyedElement.c b/libparc/parc/algol/parc_KeyedElement.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_KeyedElement.h b/libparc/parc/algol/parc_KeyedElement.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_LinkedList.c b/libparc/parc/algol/parc_LinkedList.c index b5bbd0a6..4b0dd17e 100644 --- a/libparc/parc/algol/parc_LinkedList.c +++ b/libparc/parc/algol/parc_LinkedList.c @@ -13,17 +13,15 @@ * limitations under the License. */ -/** - */ -#include - -#include +#ifndef _WIN32 +#include +#endif +#include #include -#include +#include #include - #include #include #include diff --git a/libparc/parc/algol/parc_LinkedList.h b/libparc/parc/algol/parc_LinkedList.h index 381e2a18..fbf46ac9 100644 --- a/libparc/parc/algol/parc_LinkedList.h +++ b/libparc/parc/algol/parc_LinkedList.h @@ -499,7 +499,7 @@ bool parcLinkedList_Equals(const PARCLinkedList *x, const PARCLinkedList *y); * @endcode * */ -void parcLinkedList_Display(const PARCLinkedList *list, int indentation); +void parcLinkedList_Display(const PARCLinkedList *list, const int indentation); /** * Wakes up a single thread that is waiting on this object (see `parcLinkedList_Wait)`. diff --git a/libparc/parc/algol/parc_List.c b/libparc/parc/algol/parc_List.c index bdb343f8..fef3853e 100644 --- a/libparc/parc/algol/parc_List.c +++ b/libparc/parc/algol/parc_List.c @@ -101,7 +101,7 @@ parcList_Add(PARCList *list, void *element) } bool -parcList_AddAll(PARCList *list, size_t argc, void *argv[argc]) +parcList_AddAll(PARCList *list, size_t argc, void **argv) { for (int i = 0; i < argc; i++) { (list->interface->Add)(list->instance, argv[i]); @@ -166,7 +166,7 @@ parcList_GetAtIndex(const PARCList *list, size_t index) int parcList_HashCode(const PARCList *list) { - return (list->interface->HashCode)(list->instance); + return (int)(list->interface->HashCode)(list->instance); } ssize_t @@ -177,7 +177,7 @@ parcList_IndexOf(const PARCList *list, PARCObject *element) if (list->interface->IndexOf) { result = (list->interface->IndexOf)(list->instance, element); } else { - for (ssize_t i = 0; i < parcList_Size(list); i++) { + for (size_t i = 0; i < parcList_Size(list); i++) { PARCObject *e = parcList_GetAtIndex(list, i); if (parcObject_Equals(e, element)) { result = i; diff --git a/libparc/parc/algol/parc_Map.c b/libparc/parc/algol/parc_Map.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Map.h b/libparc/parc/algol/parc_Map.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Memory.c b/libparc/parc/algol/parc_Memory.c old mode 100755 new mode 100644 index eebdadf0..6552a902 --- a/libparc/parc/algol/parc_Memory.c +++ b/libparc/parc/algol/parc_Memory.c @@ -13,21 +13,19 @@ * limitations under the License. */ -/** - */ -#include - -#include - +#ifndef _WIN32 #include +#endif + +#include #include #include #include #include - #include #include +#include #include #include #include @@ -93,6 +91,14 @@ parcMemory_DeallocateImpl(void **pointer) ((PARCMemoryDeallocate *) parcMemory->Deallocate)(pointer); } +#ifdef _WIN32 +void +parcMemory_DeallocateAlignImpl(void **pointer) +{ + ((PARCMemoryDeallocateAlign *) parcMemory->DeallocateAlign)(pointer); +} +#endif + void * parcMemory_Reallocate(void *pointer, size_t newSize) { @@ -138,6 +144,9 @@ PARCMemoryInterface PARCMemoryAsPARCMemory = { .AllocateAndClear = (uintptr_t) parcMemory_AllocateAndClear, .MemAlign = (uintptr_t) parcMemory_MemAlign, .Deallocate = (uintptr_t) parcMemory_DeallocateImpl, +#ifdef _WIN32 + .DeallocateAlign = (uintptr_t)parcMemory_DeallocateAlignImpl, +#endif .Reallocate = (uintptr_t) parcMemory_Reallocate, .StringDuplicate = (uintptr_t) parcMemory_StringDuplicate, .Outstanding = (uintptr_t) parcMemory_Outstanding diff --git a/libparc/parc/algol/parc_Memory.h b/libparc/parc/algol/parc_Memory.h index fe3c4b5a..6e4a84e8 100644 --- a/libparc/parc/algol/parc_Memory.h +++ b/libparc/parc/algol/parc_Memory.h @@ -43,6 +43,10 @@ typedef int (PARCMemoryMemAlign)(void **pointer, size_t alignment, size_t size); typedef void (PARCMemoryDeallocate)(void **pointer); +#ifdef _WIN32 +typedef void (PARCMemoryDeallocateAlign)(void **pointer); +#endif + typedef void *(PARCMemoryReallocate)(void *pointer, size_t newSize); typedef char *(PARCMemoryStringDuplicate)(const char *string, size_t length); @@ -121,6 +125,19 @@ typedef struct parc_memory_interface { */ uintptr_t Deallocate; +#ifdef _WIN32 + /** + * Deallocate memory previously Aligned allocated via `MemAlign`. + * + * @param [in,out] pointer A pointer to a `void *` pointer to the address of the allocated memory that will be set to zero. + * + * @see AllocateAndClear + * @see Allocate + * @see Reallocate + */ + uintptr_t DeallocateAlign; +#endif + /** * Try to change the size of the allocation pointed to by @p pointer to @p newSize, and returns ptr. * If there is not enough room to enlarge the memory allocation pointed to by @p pointer, @@ -308,8 +325,35 @@ int parcMemory_MemAlign(void **pointer, const size_t alignment, const size_t siz */ void parcMemory_DeallocateImpl(void **pointer); +#ifdef _WIN32 +/** + * Deallocate memory previously allocated via `MemAlign`. + * + * @param [in,out] pointer A pointer to a `void *` pointer to the address of the allocated memory that will be set to zero. + * + * Example: + * @code + * { + * void *allocatedMemory; + * + * allocatedMemory = parcMemory_Allocate(100); + * if (allocatedMemory == NULL) { + * // allocation failed + * } + * } + * @endcode + * + * @see parcMemory_MemAlign + */ +void parcMemory_DeallocateAlignImpl(void **pointer); +#endif + #define parcMemory_Deallocate(_pointer_) parcMemory_DeallocateImpl((void **) _pointer_) +#ifdef _WIN32 +#define parcMemory_DeallocateAlign(_pointer_) parcMemory_DeallocateAlignImpl((void **) _pointer_) +#endif + /** * Try to change the size of the allocation pointed to by @p pointer to @p newSize, and returns ptr. * If there is not enough room to enlarge the memory allocation pointed to by @p pointer, @@ -432,7 +476,7 @@ size_t parcMemory_RoundUpToCacheLine(const size_t size); * * @see parcMemory_RoundUpToCacheLine */ -size_t parcMemory_RoundUpToMultiple(size_t size, size_t multiple); +size_t parcMemory_RoundUpToMultiple(const size_t size, const size_t multiple); /** * @def parcMemory_SafeFree diff --git a/libparc/parc/algol/parc_Network.c b/libparc/parc/algol/parc_Network.c index 2b6c8888..543a77b9 100644 --- a/libparc/parc/algol/parc_Network.c +++ b/libparc/parc/algol/parc_Network.c @@ -13,19 +13,16 @@ * limitations under the License. */ -/** - */ -#include - -#include - +#ifndef _WIN32 #include -#include -#include #include +#endif +#include +#include +#include #include - +#include #include #include #include @@ -52,7 +49,7 @@ parcNetwork_SockAddress(const char *address, in_port_t port) parcAssertNotNull(result, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(struct sockaddr_in)); if (result != NULL) { parcAssertTrue(ai->ai_addrlen == sizeof(struct sockaddr_in), - "Sockaddr wrong length, expected %zu got %u", sizeof(struct sockaddr_in), ai->ai_addrlen); + "Sockaddr wrong length, expected %zu got %zu", sizeof(struct sockaddr_in), ai->ai_addrlen); memcpy(result, ai->ai_addr, ai->ai_addrlen); result->sin_port = htons(port); addr = (struct sockaddr *) result; @@ -65,7 +62,7 @@ parcNetwork_SockAddress(const char *address, in_port_t port) parcAssertNotNull(result, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(struct sockaddr_in6)); if (result != NULL) { parcAssertTrue(ai->ai_addrlen == sizeof(struct sockaddr_in6), - "Sockaddr wrong length, expected %zu got %u", sizeof(struct sockaddr_in6), ai->ai_addrlen); + "Sockaddr wrong length, expected %zu got %zu", sizeof(struct sockaddr_in6), ai->ai_addrlen); memcpy(result, ai->ai_addr, ai->ai_addrlen); result->sin6_port = htons(port); @@ -304,6 +301,7 @@ parcNetwork_ParseLinkAddress(const char *address) } parcTrapIllegalValue(address, "Bad scheme '%s'", address); + return NULL; } bool @@ -370,9 +368,11 @@ parcNetwork_IsSocketLocal(struct sockaddr *sock) bool isLocal = false; switch (sock->sa_family) { +#ifndef _WIN32 case PF_LOCAL: isLocal = true; break; +#endif case PF_INET: isLocal = _isInet4Loopback((struct sockaddr_in *) sock); diff --git a/libparc/parc/algol/parc_Network.h b/libparc/parc/algol/parc_Network.h index bf7cfcbd..4b95138b 100644 --- a/libparc/parc/algol/parc_Network.h +++ b/libparc/parc/algol/parc_Network.h @@ -22,8 +22,10 @@ #ifndef libparc_parc_Networking_h #define libparc_parc_Networking_h +#ifndef _WIN32 #include #include +#endif #include #include diff --git a/libparc/parc/algol/parc_Object.c b/libparc/parc/algol/parc_Object.c index 70a24f34..422a97f7 100644 --- a/libparc/parc/algol/parc_Object.c +++ b/libparc/parc/algol/parc_Object.c @@ -13,25 +13,23 @@ * limitations under the License. */ -/** - */ -#include - -#include +#ifndef _WIN32 +#include +#include +#include +#endif +#include #include #include -#include #include #include -#include #include #include -#include - #include #include +#include #include #include #include @@ -364,7 +362,11 @@ parcObject_Acquire(const PARCObject *object) _PARCObjectHeader *header = _parcObject_Header(object); +#ifndef _WIN32 parcAtomicUint64_Increment(&header->references); +#else + InterlockedIncrement((unsigned volatile *)(&header->references)); +#endif return (PARCObject *) object; } @@ -528,7 +530,12 @@ _parcObject_InitializeLocking(_PARCObjectLocking *locking) pthread_mutex_init(&locking->lock, &_parcObject_GlobalLockAttributes); pthread_cond_init(&locking->notification, NULL); - locking->locker = (pthread_t) NULL; +#ifndef _WIN32 + locking->locker = (pthread_t)NULL; +#else + locking->locker = (pthread_t) { NULL, 0 }; +#endif + } } @@ -578,6 +585,8 @@ parcObject_CreateInstanceImpl(const PARCObjectDescriptor *descriptor) size_t totalMemoryLength = prefixLength + descriptor->objectSize; void *origin = NULL; + + //origin = parcMemory_AllocateAndClear(totalMemoryLength); parcMemory_MemAlign(&origin, sizeof(void *), totalMemoryLength); if (origin == NULL) { @@ -630,7 +639,11 @@ parcObject_Release(PARCObject **objectPointer) parcTrapIllegalValueIf(header->references == 0, "PARCObject@%p references must be > 0", object); +#ifndef _WIN32 PARCReferenceCount result = parcAtomicUint64_Decrement(&header->references); +#else + PARCReferenceCount result = InterlockedDecrement((unsigned volatile *)(&header->references)); +#endif if (result == 0) { if (_parcObject_Destructor(header->descriptor, objectPointer)) { @@ -639,7 +652,11 @@ parcObject_Release(PARCObject **objectPointer) } if (header->isAllocated) { void *origin = _parcObject_Origin(object); +#ifndef _WIN32 parcMemory_Deallocate(&origin); +#else + parcMemory_DeallocateAlign(&origin); +#endif } parcAssertNotNull(*objectPointer, "Class implementation unnecessarily clears the object pointer."); } else { @@ -770,7 +787,13 @@ parcObject_Unlock(const PARCObject *object) if (object != NULL) { _PARCObjectLocking *locking = _parcObjectHeader_Locking(object); if (locking != NULL) { - locking->locker = (pthread_t) NULL; + +#ifndef _WIN32 + locking->locker = (pthread_t)NULL; +#else + locking->locker = (pthread_t) { NULL, 0 }; +#endif + result = (pthread_mutex_unlock(&locking->lock) == 0); parcAssertTrue(result, "Attempted to unlock an unowned lock."); @@ -840,7 +863,11 @@ parcObject_IsLocked(const PARCObject *object) _PARCObjectLocking *locking = _parcObjectHeader_Locking(object); if (locking != NULL) { - result = locking->locker != (pthread_t) NULL; +#ifndef _WIN32 + result = locking->locker != (pthread_t)NULL; +#else + result = locking->locker.p != NULL; +#endif } return result; @@ -890,7 +917,7 @@ parcObject_WaitFor(const PARCObject *object, const uint64_t nanoSeconds) .tv_sec = now.tv_sec, .tv_nsec = (now.tv_usec * 1000) }; - time.tv_nsec += nanoSeconds; + time.tv_nsec += (long)nanoSeconds; time.tv_sec += time.tv_nsec / 1000000000; time.tv_nsec = time.tv_nsec % 1000000000; @@ -932,8 +959,11 @@ bool parcObject_BarrierSet(const PARCObject *object) { _PARCObjectHeader *header = _parcObject_Header(object); - +#ifndef _WIN32 while (__sync_bool_compare_and_swap(&header->barrier, false, true) == false) { +#else + while (InterlockedCompareExchange((unsigned volatile *)&header->barrier, false, true) != header->barrier) { +#endif ; } return true; @@ -944,7 +974,12 @@ parcObject_BarrierUnset(const PARCObject *object) { _PARCObjectHeader *header = _parcObject_Header(object); +#ifndef _WIN32 while (__sync_bool_compare_and_swap(&header->barrier, true, false) == false) { +#else + while (InterlockedCompareExchange((unsigned volatile *)&header->barrier, true, false) != header->barrier) { +#endif + ; } diff --git a/libparc/parc/algol/parc_Object.h b/libparc/parc/algol/parc_Object.h index ac7e9652..ba9392a4 100644 --- a/libparc/parc/algol/parc_Object.h +++ b/libparc/parc/algol/parc_Object.h @@ -623,7 +623,7 @@ const PARCObjectDescriptor *parcObject_SetDescriptor(PARCObject *object, const P }; \ _Pragma("GCC diagnostic pop") \ const PARCObjectDescriptor parcObject_DescriptorName(_subtype) -#else +#elif defined(__GNUC__) #define parcObject_Extends(_subtype, _superType, ...) \ _Pragma("GCC diagnostic ignored \"-Woverride-init\"") \ parcObjectDescriptor_Declaration(_subtype) = { \ @@ -647,7 +647,29 @@ const PARCObjectDescriptor *parcObject_SetDescriptor(PARCObject *object, const P }; \ _Pragma("GCC diagnostic warning \"-Woverride-init\"") \ const PARCObjectDescriptor parcObject_DescriptorName(_subtype) -#endif +#else +#define parcObject_Extends(_subtype, _superType, ...) \ + parcObjectDescriptor_Declaration(_subtype) = { \ + .super = &parcObject_DescriptorName(_superType), \ + .name = #_subtype, \ + .objectSize = 0, \ + .objectAlignment = 0, \ + .destroy = NULL, \ + .destructor = NULL, \ + .release = NULL, \ + .copy = NULL, \ + .toString = NULL, \ + .equals = NULL, \ + .compare = NULL, \ + .hashCode = NULL, \ + .toJSON = NULL, \ + .display = NULL, \ + .isLockable = true, \ + .typeState = NULL, \ + __VA_ARGS__ \ + }; \ + const PARCObjectDescriptor parcObject_DescriptorName(_subtype) +#endif /** * Define a new PARC Object implementation, by composing a new PARC Object Descriptor referencing an old one. diff --git a/libparc/parc/algol/parc_OldSortedList.c b/libparc/parc/algol/parc_OldSortedList.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_OldSortedList.h b/libparc/parc/algol/parc_OldSortedList.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_OutputStream.c b/libparc/parc/algol/parc_OutputStream.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_OutputStream.h b/libparc/parc/algol/parc_OutputStream.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_PathName.c b/libparc/parc/algol/parc_PathName.c old mode 100755 new mode 100644 index 56e57d27..ec6b2a5b --- a/libparc/parc/algol/parc_PathName.c +++ b/libparc/parc/algol/parc_PathName.c @@ -13,19 +13,16 @@ * limitations under the License. */ -/** - */ -#include - -#include +#ifndef _WIN32 +#include +#endif +#include #include #include #include -#include - #include - +#include #include #include #include @@ -80,7 +77,7 @@ parcObject_ExtendPARCObject(PARCPathName, _destroy, parcPathName_Copy, parcPathN parcPathName_Equals, NULL, NULL, NULL); PARCPathName * -parcPathName_ParseToLimit(size_t limit, const char path[limit]) +parcPathName_ParseToLimit(size_t limit, const char *path) { PARCPathName *result = parcPathName_Create(); diff --git a/libparc/parc/algol/parc_PriorityQueue.c b/libparc/parc/algol/parc_PriorityQueue.c old mode 100755 new mode 100644 index c6c003b1..6fea804b --- a/libparc/parc/algol/parc_PriorityQueue.c +++ b/libparc/parc/algol/parc_PriorityQueue.c @@ -251,7 +251,7 @@ _bubbleUp(PARCPriorityQueue *queue, size_t elementIndex) * @endcode */ static void -_expand(PARCPriorityQueue *queue) +_expandTable(PARCPriorityQueue *queue) { queue->capacity *= 2; queue->array = parcMemory_Reallocate(queue->array, sizeof(HeapEntry) * queue->capacity); @@ -320,7 +320,7 @@ parcPriorityQueue_Add(PARCPriorityQueue *queue, void *data) parcAssertNotNull(data, "Parameter data must be non-null"); if (queue->size + 1 > queue->capacity) { - _expand(queue); + _expandTable(queue); } // insert at the end of the array diff --git a/libparc/parc/algol/parc_PriorityQueue.h b/libparc/parc/algol/parc_PriorityQueue.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Properties.c b/libparc/parc/algol/parc_Properties.c index 2a6c7d33..623128a0 100644 --- a/libparc/parc/algol/parc_Properties.c +++ b/libparc/parc/algol/parc_Properties.c @@ -222,7 +222,7 @@ parcProperties_SetProperty(PARCProperties *properties, const char *name, const c } const char * -parcProperties_GetProperty(const PARCProperties *properties, const char *name) +parcProperties_GetProperty(const PARCProperties *properties, const char *restrict name) { char *result = NULL; diff --git a/libparc/parc/algol/parc_RandomAccessFile.c b/libparc/parc/algol/parc_RandomAccessFile.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_RandomAccessFile.h b/libparc/parc/algol/parc_RandomAccessFile.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_ReadOnlyBuffer.c b/libparc/parc/algol/parc_ReadOnlyBuffer.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_SafeMemory.c b/libparc/parc/algol/parc_SafeMemory.c index 76908548..337dfb5f 100644 --- a/libparc/parc/algol/parc_SafeMemory.c +++ b/libparc/parc/algol/parc_SafeMemory.c @@ -62,14 +62,16 @@ # include #endif +#ifndef _WIN32 #include +#include +#include +#endif + #include #include #include -#include -#include #include - #include #include #include @@ -565,7 +567,7 @@ parcSafeMemory_IsValid(const void *memory) { bool result = true; - PARCSafeMemoryState state = _parcSafeMemory_GetState(memory); + PARCSafeMemoryState state = _parcSafeMemory_GetState((const PARCSafeMemoryUsable *)memory); if (state != PARCSafeMemoryState_OK) { return false; } @@ -629,12 +631,12 @@ parcSafeMemory_Display(const void *memory, int indentation) if (memory == NULL) { parcDisplayIndented_PrintLine(indentation, "PARCSafeMemory@NULL"); } else { - _MemoryPrefix *prefix = _parcSafeMemory_GetPrefix(memory); + _MemoryPrefix *prefix = _parcSafeMemory_GetPrefix((const PARCSafeMemoryUsable *)memory); parcDisplayIndented_PrintLine(indentation, "PARCSafeMemory@%p {", (void *) memory); parcDisplayIndented_PrintLine(indentation + 1, "%p=[ magic=0x%" PRIx64 " requestedLength=%zd, actualLength=%zd, alignment=%zd, guard=0x%" PRIx64 "]", - _parcSafeMemory_GetOrigin(memory), + _parcSafeMemory_GetOrigin((const PARCSafeMemoryUsable *)memory), prefix->magic, prefix->requestedLength, prefix->actualLength, diff --git a/libparc/parc/algol/parc_Stack.c b/libparc/parc/algol/parc_Stack.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Stack.h b/libparc/parc/algol/parc_Stack.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_StdlibMemory.c b/libparc/parc/algol/parc_StdlibMemory.c old mode 100755 new mode 100644 index 11381a54..536823d0 --- a/libparc/parc/algol/parc_StdlibMemory.c +++ b/libparc/parc/algol/parc_StdlibMemory.c @@ -13,20 +13,18 @@ * limitations under the License. */ -/** - */ -#include +#ifndef _WIN32 +#include +#endif +#include #include #include -#include #include #include -#include #include #include - #include static uint32_t _parcStdlibMemory_OutstandingAllocations; @@ -114,14 +112,23 @@ parcStdlibMemory_MemAlign(void **pointer, size_t alignment, size_t size) return EINVAL; } +#ifndef _WIN32 int failure = posix_memalign(pointer, alignment, size); if (failure != 0) { return failure; } + if (*pointer == NULL) { return ENOMEM; } +#else + *pointer= _aligned_malloc(size, alignment); + + if (*pointer == NULL) { + return errno; + } +#endif _parcStdlibMemory_IncrementOutstandingAllocations(); @@ -141,6 +148,22 @@ parcStdlibMemory_Deallocate(void **pointer) _parcStdlibMemory_DecrementOutstandingAllocations(); } +#ifdef _WIN32 +void +parcStdlibMemory_DeallocateAlign(void **pointer) +{ +#ifndef PARCLibrary_DISABLE_VALIDATION + parcTrapIllegalValueIf(_parcStdlibMemory_OutstandingAllocations == 0, + "parcStdlibMemory_DeallocateAlign invoked with nothing left to free (double free somewhere?)\n"); +#endif + _aligned_free(*pointer); + *pointer = NULL; + + _parcStdlibMemory_DecrementOutstandingAllocations(); +} + +#endif + void * parcStdlibMemory_Reallocate(void *pointer, size_t newSize) { @@ -174,6 +197,9 @@ PARCMemoryInterface PARCStdlibMemoryAsPARCMemory = { .AllocateAndClear = (uintptr_t) parcStdlibMemory_AllocateAndClear, .MemAlign = (uintptr_t) parcStdlibMemory_MemAlign, .Deallocate = (uintptr_t) parcStdlibMemory_Deallocate, +#ifdef _WIN32 + .DeallocateAlign = (uintptr_t) parcStdlibMemory_DeallocateAlign, +#endif .Reallocate = (uintptr_t) parcStdlibMemory_Reallocate, .StringDuplicate = (uintptr_t) parcStdlibMemory_StringDuplicate, .Outstanding = (uintptr_t) parcStdlibMemory_Outstanding diff --git a/libparc/parc/algol/parc_StdlibMemory.h b/libparc/parc/algol/parc_StdlibMemory.h old mode 100755 new mode 100644 index 9abbf915..9ac135b2 --- a/libparc/parc/algol/parc_StdlibMemory.h +++ b/libparc/parc/algol/parc_StdlibMemory.h @@ -103,6 +103,20 @@ int parcStdlibMemory_MemAlign(void **pointer, size_t alignment, size_t size); */ void parcStdlibMemory_Deallocate(void **pointer); +#ifdef _WIN32 +/** + * Deallocate the memory pointed to by @p pointer + * + * @param [in,out] pointer A pointer to a pointer to the memory to be deallocated + * + * Example: + * @code + * <#example#> + * @endcode + */ +void parcStdlibMemory_DeallocateAlign(void **pointer); +#endif + /** * Resizes previously allocated memory at @p pointer to @p newSize. If necessary, * new memory is allocated and the content copied from the old memory to the diff --git a/libparc/parc/algol/parc_String.c b/libparc/parc/algol/parc_String.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Time.c b/libparc/parc/algol/parc_Time.c old mode 100755 new mode 100644 index 07ab185b..8f292c1b --- a/libparc/parc/algol/parc_Time.c +++ b/libparc/parc/algol/parc_Time.c @@ -13,17 +13,16 @@ * limitations under the License. */ -/** - */ -#include +#ifndef _WIN32 +#include +#endif +#include #include #include #include -#include #include - #include #include @@ -43,11 +42,20 @@ char * parcTime_TimevalAsRFC3339(const struct timeval *utcTime, char result[64]) { char tmbuf[64]; + struct tm *nowtm; + +#ifndef _WIN32 + struct tm theTime; + nowtm = gmtime_r(&utcTime->tv_sec, &theTime); +#else struct tm theTime; + __int64 ltime = utcTime->tv_sec; + int x = _gmtime64_s(&theTime, <ime); + nowtm = &theTime; +#endif - struct tm *nowtm = gmtime_r(&utcTime->tv_sec, &theTime); strftime(tmbuf, sizeof tmbuf, "%Y-%m-%dT%H:%M:%S", nowtm); - snprintf(result, 64, "%s.%06ldZ", tmbuf, (long) utcTime->tv_usec); + snprintf(result, 64, "%s.%06ldZ", tmbuf, (long)utcTime->tv_usec); return result; } @@ -57,7 +65,16 @@ parcTime_TimevalAsISO8601(const struct timeval *utcTime, char result[64]) char tmbuf[64]; struct tm theTime; - struct tm *nowtm = gmtime_r(&utcTime->tv_sec, &theTime); + struct tm *nowtm; + +#ifndef _WIN32 + nowtm = gmtime_r(&utcTime->tv_sec, &theTime); +#else + __int64 ltime = utcTime->tv_sec; + _gmtime64_s(&theTime, <ime); + nowtm = &theTime; +#endif + strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm); snprintf(result, 64, "%s.%06ldZ", tmbuf, (long) utcTime->tv_usec); return result; @@ -66,7 +83,7 @@ parcTime_TimevalAsISO8601(const struct timeval *utcTime, char result[64]) char * parcTime_TimeAsRFC3339(const time_t utcTime, char result[64]) { - struct timeval theTime = { utcTime, 0 }; + struct timeval theTime = { (long)utcTime, 0 }; return parcTime_TimevalAsRFC3339(&theTime, result); } @@ -83,7 +100,7 @@ parcTime_NowAsRFC3339(char result[64]) char * parcTime_TimeAsISO8601(const time_t utcTime, char result[64]) { - struct timeval theTime = { utcTime, 0 }; + struct timeval theTime = { (long)utcTime, 0 }; return parcTime_TimevalAsISO8601(&theTime, result); } diff --git a/libparc/parc/algol/parc_Time.h b/libparc/parc/algol/parc_Time.h index 2a68144e..a04d02ae 100644 --- a/libparc/parc/algol/parc_Time.h +++ b/libparc/parc/algol/parc_Time.h @@ -26,7 +26,10 @@ #ifndef libparc_parc_Time_h #define libparc_parc_Time_h +#ifndef _WIN32 #include +#endif + #include /** diff --git a/libparc/parc/algol/parc_TreeMap.c b/libparc/parc/algol/parc_TreeMap.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_TreeMap.h b/libparc/parc/algol/parc_TreeMap.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_TreeRedBlack.c b/libparc/parc/algol/parc_TreeRedBlack.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_TreeRedBlack.h b/libparc/parc/algol/parc_TreeRedBlack.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_URI.c b/libparc/parc/algol/parc_URI.c index e14dfc9f..94f74981 100644 --- a/libparc/parc/algol/parc_URI.c +++ b/libparc/parc/algol/parc_URI.c @@ -13,22 +13,17 @@ * limitations under the License. */ -/** - * - */ -#include - -#include - +#ifndef _WIN32 #include +#endif + +#include #include #include -#include #include #include - +#include #include - #include #include #include diff --git a/libparc/parc/algol/parc_URIAuthority.c b/libparc/parc/algol/parc_URIAuthority.c index 1e3468d1..96b5611a 100644 --- a/libparc/parc/algol/parc_URIAuthority.c +++ b/libparc/parc/algol/parc_URIAuthority.c @@ -13,22 +13,18 @@ * limitations under the License. */ -/** - * - */ -#include - -#include - +#ifndef _WIN32 #include +#endif + +#include #include #include -#include #include #include +#include #include - #include #include #include diff --git a/libparc/parc/algol/parc_URIPath.c b/libparc/parc/algol/parc_URIPath.c old mode 100755 new mode 100644 index 04636852..78f28f6f --- a/libparc/parc/algol/parc_URIPath.c +++ b/libparc/parc/algol/parc_URIPath.c @@ -13,21 +13,19 @@ * limitations under the License. */ -/** - */ -#include - -#include - +#ifndef _WIN32 #include +#include +#endif + +#include #include #include -#include #include #include +#include #include - #include #include #include diff --git a/libparc/parc/algol/parc_URIPath.h b/libparc/parc/algol/parc_URIPath.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_URISegment.c b/libparc/parc/algol/parc_URISegment.c old mode 100755 new mode 100644 index 786a7182..aa009665 --- a/libparc/parc/algol/parc_URISegment.c +++ b/libparc/parc/algol/parc_URISegment.c @@ -13,21 +13,17 @@ * limitations under the License. */ -/** - */ -#include - -#include - +#ifndef _WIN32 #include +#endif + +#include #include #include -#include #include #include - +#include #include - #include #include @@ -131,7 +127,7 @@ parcURISegment_CreateFromBuffer(PARCBuffer *buffer) } PARCURISegment * -parcURISegment_Create(size_t length, const unsigned char segment[length]) +parcURISegment_Create(size_t length, const unsigned char *segment) { PARCURISegment *result = NULL; diff --git a/libparc/parc/algol/parc_Unsigned.h b/libparc/parc/algol/parc_Unsigned.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Varint.c b/libparc/parc/algol/parc_Varint.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Varint.h b/libparc/parc/algol/parc_Varint.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Vector.c b/libparc/parc/algol/parc_Vector.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/parc_Vector.h b/libparc/parc/algol/parc_Vector.h old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_ArrayList.c b/libparc/parc/algol/test/test_parc_ArrayList.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Base64.c b/libparc/parc/algol/test/test_parc_Base64.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_BitVector.c b/libparc/parc/algol/test/test_parc_BitVector.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_BufferChunker.c b/libparc/parc/algol/test/test_parc_BufferChunker.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_ByteArray.c b/libparc/parc/algol/test/test_parc_ByteArray.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Chunker.c b/libparc/parc/algol/test/test_parc_Chunker.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Deque.c b/libparc/parc/algol/test/test_parc_Deque.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Display.c b/libparc/parc/algol/test/test_parc_Display.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Environment.c b/libparc/parc/algol/test/test_parc_Environment.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_EventScheduler.c b/libparc/parc/algol/test/test_parc_EventScheduler.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_EventTimer.c b/libparc/parc/algol/test/test_parc_EventTimer.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_FileChunker.c b/libparc/parc/algol/test/test_parc_FileChunker.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_FileInputStream.c b/libparc/parc/algol/test/test_parc_FileInputStream.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_FileOutputStream.c b/libparc/parc/algol/test/test_parc_FileOutputStream.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Hash.c b/libparc/parc/algol/test/test_parc_Hash.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_HashCode.c b/libparc/parc/algol/test/test_parc_HashCode.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_HashCodeTable.c b/libparc/parc/algol/test/test_parc_HashCodeTable.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_InputStream.c b/libparc/parc/algol/test/test_parc_InputStream.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_JSONArray.c b/libparc/parc/algol/test/test_parc_JSONArray.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_JSONParser.c b/libparc/parc/algol/test/test_parc_JSONParser.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_KeyValue.c b/libparc/parc/algol/test/test_parc_KeyValue.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_KeyedElement.c b/libparc/parc/algol/test/test_parc_KeyedElement.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Memory.c b/libparc/parc/algol/test/test_parc_Memory.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Network.c b/libparc/parc/algol/test/test_parc_Network.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Object.c b/libparc/parc/algol/test/test_parc_Object.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_PathName.c b/libparc/parc/algol/test/test_parc_PathName.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Stack.c b/libparc/parc/algol/test/test_parc_Stack.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_TreeMap.c b/libparc/parc/algol/test/test_parc_TreeMap.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_TreeRedBlack.c b/libparc/parc/algol/test/test_parc_TreeRedBlack.c old mode 100755 new mode 100644 diff --git a/libparc/parc/algol/test/test_parc_Varint.c b/libparc/parc/algol/test/test_parc_Varint.c old mode 100755 new mode 100644 diff --git a/libparc/parc/assert/parc_Assert.h b/libparc/parc/assert/parc_Assert.h index 46e3e2f0..692edccd 100644 --- a/libparc/parc/assert/parc_Assert.h +++ b/libparc/parc/assert/parc_Assert.h @@ -182,10 +182,10 @@ parcLog_PrintError("Cannot obtain lock: " M, ##__VA_ARGS__); \ assert(!(A)); \ } -#define parcAssertAligned(address, alignment, ...) \ - parcLog_PrintError(__VA_ARGS__); \ - assert(((alignment & (~alignment + 1)) == alignment) \ - ? (((uintptr_t)address) % alignment) == 0 ? 1 : 0 \ +#define parcAssertAligned(address, alignment, M, ...) \ + parcLog_PrintError(M,##__VA_ARGS__); \ + assert(((alignment & (~alignment + 1)) == alignment) \ + ? (((uintptr_t)address) % alignment) == 0 ? 1 : 0 \ : 0); #endif diff --git a/libparc/parc/concurrent/parc_AtomicUint16.c b/libparc/parc/concurrent/parc_AtomicUint16.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_AtomicUint16.h b/libparc/parc/concurrent/parc_AtomicUint16.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_AtomicUint32.c b/libparc/parc/concurrent/parc_AtomicUint32.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_AtomicUint32.h b/libparc/parc/concurrent/parc_AtomicUint32.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_AtomicUint64.c b/libparc/parc/concurrent/parc_AtomicUint64.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_AtomicUint64.h b/libparc/parc/concurrent/parc_AtomicUint64.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_AtomicUint8.c b/libparc/parc/concurrent/parc_AtomicUint8.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_AtomicUint8.h b/libparc/parc/concurrent/parc_AtomicUint8.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_FutureTask.c b/libparc/parc/concurrent/parc_FutureTask.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_FutureTask.h b/libparc/parc/concurrent/parc_FutureTask.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_Lock.c b/libparc/parc/concurrent/parc_Lock.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_Lock.h b/libparc/parc/concurrent/parc_Lock.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_Notifier.c b/libparc/parc/concurrent/parc_Notifier.c old mode 100755 new mode 100644 index 67e8cfb3..e313cd6e --- a/libparc/parc/concurrent/parc_Notifier.c +++ b/libparc/parc/concurrent/parc_Notifier.c @@ -13,26 +13,29 @@ * limitations under the License. */ -/** - */ +#ifndef _WIN32 +#include +#endif #include #include #include -#include #include #include - #include - #include #include -#ifdef __GNUC__ +#if defined(__GNUC__) #define ATOMIC_ADD_AND_FETCH(ptr, increment) __sync_add_and_fetch(ptr, increment) #define ATOMIC_BOOL_CAS(ptr, oldvalue, newvalue) __sync_bool_compare_and_swap(ptr, oldvalue, newvalue) #define ATOMIC_FETCH(ptr) ATOMIC_ADD_AND_FETCH(ptr, 0) #define ATOMIC_SET(ptr, oldvalue, newvalue) ATOMIC_BOOL_CAS(ptr, oldvalue, newvalue) +#elif defined(_WIN32) +#define ATOMIC_ADD_AND_FETCH(ptr, increment) (++(*(ptr))) +#define ATOMIC_BOOL_CAS(ptr, oldvalue, newvalue) (InterlockedCompareExchangePointer((volatile PVOID *)ptr, (PVOID)newvalue, (PVOID)oldvalue) == ptr) +#define ATOMIC_FETCH(ptr) ATOMIC_ADD_AND_FETCH(ptr, 0) +#define ATOMIC_SET(ptr, oldvalue, newvalue) ATOMIC_BOOL_CAS(ptr, oldvalue, newvalue) #else #error "Only GNUC supported, we need atomic operations" #endif @@ -63,6 +66,8 @@ parcObject_ExtendPARCObject(PARCNotifier, _parcNotifier_Finalize, NULL, NULL, NU static bool _parcNotifier_MakeNonblocking(PARCNotifier *notifier) { + +#ifndef _WIN32 // set the read side to be non-blocking int flags = fcntl(notifier->fds[PARCNotifierReadFd], F_GETFL, 0); if (flags == 0) { @@ -71,6 +76,8 @@ _parcNotifier_MakeNonblocking(PARCNotifier *notifier) } } perror("fcntl error"); +#endif + return false; } @@ -82,12 +89,15 @@ parcNotifier_Create(void) notifier->paused = false; notifier->skippedNotify = false; +#ifndef _WIN32 int failure = pipe(notifier->fds); parcAssertFalse(failure, "Error on pipe: %s", strerror(errno)); if (!_parcNotifier_MakeNonblocking(notifier)) { - parcObject_Release((void **) ¬ifier); + parcObject_Release((void **)¬ifier); } +#endif + } return notifier; @@ -146,4 +156,4 @@ parcNotifier_StartEvents(PARCNotifier *notifier) // we missed some notifications, so re-signal ourself parcNotifier_Notify(notifier); } -} +} \ No newline at end of file diff --git a/libparc/parc/concurrent/parc_Notifier.h b/libparc/parc/concurrent/parc_Notifier.h old mode 100755 new mode 100644 index 44eda3b5..e139c141 --- a/libparc/parc/concurrent/parc_Notifier.h +++ b/libparc/parc/concurrent/parc_Notifier.h @@ -175,4 +175,5 @@ void parcNotifier_PauseEvents(PARCNotifier *notifier); * @endcode */ void parcNotifier_StartEvents(PARCNotifier *notifier); + #endif // libparc_parc_Notifier_h diff --git a/libparc/parc/concurrent/parc_RingBuffer.c b/libparc/parc/concurrent/parc_RingBuffer.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_RingBuffer.h b/libparc/parc/concurrent/parc_RingBuffer.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_RingBuffer_1x1.c b/libparc/parc/concurrent/parc_RingBuffer_1x1.c old mode 100755 new mode 100644 index a93049eb..9827154b --- a/libparc/parc/concurrent/parc_RingBuffer_1x1.c +++ b/libparc/parc/concurrent/parc_RingBuffer_1x1.c @@ -71,22 +71,23 @@ * */ +#ifndef _WIN32 +#include +#endif + #include #include #include #include #include #include -#include #include #include #include - #include -#ifdef __GNUC__ - +#if defined(__GNUC__) // on x86 or x86_64, simple assignment will work #if (__x86_64__ || __i386__) #define ATOMIC_ADD_AND_FETCH(ptr, increment) __sync_add_and_fetch(ptr, increment) @@ -100,6 +101,10 @@ #define ATOMIC_SET(ptr, oldvalue, newvalue) ATOMIC_BOOL_CAS(ptr, oldvalue, newvalue) #endif +#elif defined(_WIN32) +#define ATOMIC_FETCH(ptr) *(ptr) +#define ATOMIC_SET(ptr, oldvalue, newvalue) *(ptr) = newvalue +#define ATOMIC_BOOL_CAS(ptr, oldvalue, newvalue) (InterlockedCompareExchangePointer(ptr,newvalue,oldvalue) == ptr) #else #error "Only GNUC supported, we need atomic operations" #endif diff --git a/libparc/parc/concurrent/parc_RingBuffer_1x1.h b/libparc/parc/concurrent/parc_RingBuffer_1x1.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_RingBuffer_NxM.c b/libparc/parc/concurrent/parc_RingBuffer_NxM.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_RingBuffer_NxM.h b/libparc/parc/concurrent/parc_RingBuffer_NxM.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_ScheduledTask.c b/libparc/parc/concurrent/parc_ScheduledTask.c old mode 100755 new mode 100644 index 4875abf7..e9636d28 --- a/libparc/parc/concurrent/parc_ScheduledTask.c +++ b/libparc/parc/concurrent/parc_ScheduledTask.c @@ -13,17 +13,16 @@ * limitations under the License. */ +#ifndef _WIN32 +#include +#endif -/** - */ #include -#include #include #include #include #include - #include #include diff --git a/libparc/parc/concurrent/parc_ScheduledTask.h b/libparc/parc/concurrent/parc_ScheduledTask.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_ScheduledThreadPool.c b/libparc/parc/concurrent/parc_ScheduledThreadPool.c index 0b77372e..6e544a92 100644 --- a/libparc/parc/concurrent/parc_ScheduledThreadPool.c +++ b/libparc/parc/concurrent/parc_ScheduledThreadPool.c @@ -57,7 +57,7 @@ _workerThread(PARCThread *thread, PARCScheduledThreadPool *pool) parcSortedList_Notify(pool->workQueue); } else { - parcSortedList_WaitFor(pool->workQueue, executionDelay); + parcSortedList_WaitFor(pool->workQueue, (const unsigned long)executionDelay); } } else { parcSortedList_Wait(pool->workQueue); diff --git a/libparc/parc/concurrent/parc_ScheduledThreadPool.h b/libparc/parc/concurrent/parc_ScheduledThreadPool.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_Synchronizer.c b/libparc/parc/concurrent/parc_Synchronizer.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_Synchronizer.h b/libparc/parc/concurrent/parc_Synchronizer.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_Thread.c b/libparc/parc/concurrent/parc_Thread.c index 50be042d..8004f672 100644 --- a/libparc/parc/concurrent/parc_Thread.c +++ b/libparc/parc/concurrent/parc_Thread.c @@ -210,7 +210,11 @@ parcThread_Cancel(PARCThread *thread) int parcThread_GetId(const PARCThread *thread) { - return (int) thread->thread; +#ifndef _WIN32 + return (int)thread->thread; +#else + return pthread_getw32threadid_np(thread->thread); +#endif } bool diff --git a/libparc/parc/concurrent/parc_Thread.h b/libparc/parc/concurrent/parc_Thread.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_ThreadPool.c b/libparc/parc/concurrent/parc_ThreadPool.c index 2d9ef6d6..67c4bcff 100644 --- a/libparc/parc/concurrent/parc_ThreadPool.c +++ b/libparc/parc/concurrent/parc_ThreadPool.c @@ -276,7 +276,7 @@ parcThreadPool_AwaitTermination(PARCThreadPool *pool, PARCTimeout *timeout) } else { // This is not accurate as this will continue the delay, rather than keep a cumulative amount of delay. uint64_t delay = parcTimeout_InNanoSeconds(timeout); - parcLinkedList_WaitFor(pool->workQueue, delay); + parcLinkedList_WaitFor(pool->workQueue, (const unsigned long)delay); } } result = true; diff --git a/libparc/parc/concurrent/parc_ThreadPool.h b/libparc/parc/concurrent/parc_ThreadPool.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_Timeout.c b/libparc/parc/concurrent/parc_Timeout.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_Timer.c b/libparc/parc/concurrent/parc_Timer.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/parc_Timer.h b/libparc/parc/concurrent/parc_Timer.h old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/test/test_parc_Notifier.c b/libparc/parc/concurrent/test/test_parc_Notifier.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/test/test_parc_RingBuffer_1x1.c b/libparc/parc/concurrent/test/test_parc_RingBuffer_1x1.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/test/test_parc_RingBuffer_NxM.c b/libparc/parc/concurrent/test/test_parc_RingBuffer_NxM.c old mode 100755 new mode 100644 diff --git a/libparc/parc/concurrent/test/test_parc_Synchronizer.c b/libparc/parc/concurrent/test/test_parc_Synchronizer.c old mode 100755 new mode 100644 diff --git a/libparc/parc/config.h.in b/libparc/parc/config.h.in index 868c03ca..99618215 100644 --- a/libparc/parc/config.h.in +++ b/libparc/parc/config.h.in @@ -1,6 +1,10 @@ /* CPU Cache line size */ #define LEVEL1_DCACHE_LINESIZE @LEVEL1_DCACHE_LINESIZE@ +#ifndef _WIN32 #define _GNU_SOURCE +#else +#include +#endif #define HAVE_REALLOC @HAVE_REALLOC@ \ No newline at end of file diff --git a/libparc/parc/developer/parc_Stopwatch.c b/libparc/parc/developer/parc_Stopwatch.c index 2b696f4a..5f87e718 100644 --- a/libparc/parc/developer/parc_Stopwatch.c +++ b/libparc/parc/developer/parc_Stopwatch.c @@ -13,11 +13,11 @@ * limitations under the License. */ -/** - */ -#include - +#ifndef _WIN32 #include +#endif + +#include #include #if __APPLE__ diff --git a/libparc/parc/developer/parc_Timing.h b/libparc/parc/developer/parc_Timing.h old mode 100755 new mode 100644 diff --git a/libparc/parc/developer/parc_TimingDarwin.h b/libparc/parc/developer/parc_TimingDarwin.h old mode 100755 new mode 100644 diff --git a/libparc/parc/developer/parc_TimingGeneric.h b/libparc/parc/developer/parc_TimingGeneric.h old mode 100755 new mode 100644 index 8c1d4468..79ac0bfb --- a/libparc/parc/developer/parc_TimingGeneric.h +++ b/libparc/parc/developer/parc_TimingGeneric.h @@ -23,9 +23,12 @@ #ifndef libparc_parc_TimingLinux_h #define libparc_parc_TimingLinux_h +#ifndef _WIN32 +#include +#endif + #include #include -#include #ifdef PARCTIMING_GENERIC diff --git a/libparc/parc/developer/parc_TimingIntel.c b/libparc/parc/developer/parc_TimingIntel.c old mode 100755 new mode 100644 diff --git a/libparc/parc/developer/parc_TimingIntel.h b/libparc/parc/developer/parc_TimingIntel.h old mode 100755 new mode 100644 diff --git a/libparc/parc/developer/parc_TimingLinux.h b/libparc/parc/developer/parc_TimingLinux.h old mode 100755 new mode 100644 diff --git a/libparc/parc/developer/test/test_parc_Timing.c b/libparc/parc/developer/test/test_parc_Timing.c old mode 100755 new mode 100644 diff --git a/libparc/parc/libparc_About.h b/libparc/parc/libparc_About.h old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_Log.c b/libparc/parc/logging/parc_Log.c old mode 100755 new mode 100644 index 4aa2a679..7034f5ea --- a/libparc/parc/logging/parc_Log.c +++ b/libparc/parc/logging/parc_Log.c @@ -13,15 +13,15 @@ * limitations under the License. */ -/** - */ +#ifndef _WIN32 +#include +#endif + #include #include -#include #include - #include #include @@ -138,7 +138,7 @@ parcLog_MessageVaList(PARCLog *log, PARCLogLevel level, uint64_t messageId, cons } bool -parcLog_Message(PARCLog *log, PARCLogLevel level, uint64_t messageId, const char *format, ...) +parcLog_Message(PARCLog *log, PARCLogLevel level, uint64_t messageId, const char *restrict format, ...) { va_list ap; va_start(ap, format); @@ -149,7 +149,7 @@ parcLog_Message(PARCLog *log, PARCLogLevel level, uint64_t messageId, const char } bool -parcLog_Warning(PARCLog *logger, const char *format, ...) +parcLog_Warning(PARCLog *logger, const char *restrict format, ...) { va_list ap; va_start(ap, format); @@ -160,7 +160,7 @@ parcLog_Warning(PARCLog *logger, const char *format, ...) } bool -parcLog_Info(PARCLog *logger, const char *format, ...) +parcLog_Info(PARCLog *logger, const char *restrict format, ...) { va_list ap; va_start(ap, format); @@ -171,7 +171,7 @@ parcLog_Info(PARCLog *logger, const char *format, ...) } bool -parcLog_Notice(PARCLog *logger, const char *format, ...) +parcLog_Notice(PARCLog *logger, const char *restrict format, ...) { va_list ap; va_start(ap, format); @@ -182,7 +182,7 @@ parcLog_Notice(PARCLog *logger, const char *format, ...) } bool -parcLog_Debug(PARCLog *logger, const char *format, ...) +parcLog_Debug(PARCLog *logger, const char *restrict format, ...) { bool result = false; @@ -197,7 +197,7 @@ parcLog_Debug(PARCLog *logger, const char *format, ...) } bool -parcLog_Error(PARCLog *logger, const char *format, ...) +parcLog_Error(PARCLog *logger, const char *restrict format, ...) { va_list ap; va_start(ap, format); @@ -208,7 +208,7 @@ parcLog_Error(PARCLog *logger, const char *format, ...) } bool -parcLog_Critical(PARCLog *logger, const char *format, ...) +parcLog_Critical(PARCLog *logger, const char *restrict format, ...) { va_list ap; va_start(ap, format); @@ -219,7 +219,7 @@ parcLog_Critical(PARCLog *logger, const char *format, ...) } bool -parcLog_Alert(PARCLog *logger, const char *format, ...) +parcLog_Alert(PARCLog *logger, const char *restrict format, ...) { va_list ap; va_start(ap, format); @@ -230,7 +230,7 @@ parcLog_Alert(PARCLog *logger, const char *format, ...) } bool -parcLog_Emergency(PARCLog *logger, const char *format, ...) +parcLog_Emergency(PARCLog *logger, const char *restrict format, ...) { va_list ap; va_start(ap, format); diff --git a/libparc/parc/logging/parc_LogEntry.h b/libparc/parc/logging/parc_LogEntry.h old mode 100755 new mode 100644 index 90f6c493..250a83c0 --- a/libparc/parc/logging/parc_LogEntry.h +++ b/libparc/parc/logging/parc_LogEntry.h @@ -34,10 +34,13 @@ #ifndef PARC_Library_parc_LogEntry_h #define PARC_Library_parc_LogEntry_h -#include +#ifndef _WIN32 +#include +#endif +#include #include -#include + struct PARCLogEntry; typedef struct PARCLogEntry PARCLogEntry; diff --git a/libparc/parc/logging/parc_LogFormatSyslog.c b/libparc/parc/logging/parc_LogFormatSyslog.c old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogFormatSyslog.h b/libparc/parc/logging/parc_LogFormatSyslog.h old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogFormatText.c b/libparc/parc/logging/parc_LogFormatText.c old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogFormatText.h b/libparc/parc/logging/parc_LogFormatText.h old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogLevel.c b/libparc/parc/logging/parc_LogLevel.c old mode 100755 new mode 100644 index 62d07072..d1ffe63c --- a/libparc/parc/logging/parc_LogLevel.c +++ b/libparc/parc/logging/parc_LogLevel.c @@ -74,7 +74,7 @@ parcLogLevel_FromString(const char *levelAsString) PARCLogLevel result = PARCLogLevel_All; for (size_t i = 0; levelToString[i] != NULL; i++) { if (strcasecmp(levelAsString, levelToString[i]) == 0) { - result = i; + result = (PARCLogLevel)i; } } diff --git a/libparc/parc/logging/parc_LogLevel.h b/libparc/parc/logging/parc_LogLevel.h old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogManager.c b/libparc/parc/logging/parc_LogManager.c old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogManager.h b/libparc/parc/logging/parc_LogManager.h old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogReporter.c b/libparc/parc/logging/parc_LogReporter.c old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogReporter.h b/libparc/parc/logging/parc_LogReporter.h old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogReporterFile.c b/libparc/parc/logging/parc_LogReporterFile.c old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogReporterFile.h b/libparc/parc/logging/parc_LogReporterFile.h old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/parc_LogReporterTextStdout.c b/libparc/parc/logging/parc_LogReporterTextStdout.c old mode 100755 new mode 100644 index 86d5190e..53ff6fa4 --- a/libparc/parc/logging/parc_LogReporterTextStdout.c +++ b/libparc/parc/logging/parc_LogReporterTextStdout.c @@ -13,11 +13,12 @@ * limitations under the License. */ -/** - */ +#ifndef _WIN32 +#include +#endif + #include #include -#include #include #include diff --git a/libparc/parc/logging/parc_LogReporterTextStdout.h b/libparc/parc/logging/parc_LogReporterTextStdout.h old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/test/test_parc_LogFormatSyslog.c b/libparc/parc/logging/test/test_parc_LogFormatSyslog.c old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/test/test_parc_LogLevel.c b/libparc/parc/logging/test/test_parc_LogLevel.c old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/test/test_parc_LogReporterFile.c b/libparc/parc/logging/test/test_parc_LogReporterFile.c old mode 100755 new mode 100644 diff --git a/libparc/parc/logging/test/test_parc_LogReporterTextStdout.c b/libparc/parc/logging/test/test_parc_LogReporterTextStdout.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/command-line/parcPublicKey_About.h b/libparc/parc/security/command-line/parcPublicKey_About.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_Certificate.c b/libparc/parc/security/parc_Certificate.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_Certificate.h b/libparc/parc/security/parc_Certificate.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CertificateFactory.h b/libparc/parc/security/parc_CertificateFactory.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CertificateType.c b/libparc/parc/security/parc_CertificateType.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CertificateType.h b/libparc/parc/security/parc_CertificateType.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_ContainerEncoding.c b/libparc/parc/security/parc_ContainerEncoding.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_ContainerEncoding.h b/libparc/parc/security/parc_ContainerEncoding.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CryptoCache.c b/libparc/parc/security/parc_CryptoCache.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CryptoCache.h b/libparc/parc/security/parc_CryptoCache.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CryptoHash.c b/libparc/parc/security/parc_CryptoHash.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CryptoHash.h b/libparc/parc/security/parc_CryptoHash.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CryptoHashType.h b/libparc/parc/security/parc_CryptoHashType.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CryptoHasher.c b/libparc/parc/security/parc_CryptoHasher.c old mode 100755 new mode 100644 index a4d492ff..b7226e46 --- a/libparc/parc/security/parc_CryptoHasher.c +++ b/libparc/parc/security/parc_CryptoHasher.c @@ -435,7 +435,7 @@ static const uint32_t _crc32c_table[] = { */ __attribute__((unused)) static uint32_t -_crc32c_UpdateSoftware(uint32_t crc, size_t len, uint8_t p[len]) +_crc32c_UpdateSoftware(uint32_t crc, size_t len, uint8_t *p) { for (int i = 0; i < len; i++) { crc = (crc >> 8) ^ _crc32c_table[((uint8_t) (crc & 0xFF)) ^ p[i]]; @@ -469,7 +469,7 @@ _crc32c_Finalize(uint32_t crc) * the CRC table used by the software calculation. */ static uint32_t -_crc32c_Update(uint32_t crc, size_t len, uint8_t p[len]) +_crc32c_Update(uint32_t crc, size_t len, uint8_t *p) { #ifdef __SSE4_2__ crc = _crc32c_UpdateIntel(crc, len, p); diff --git a/libparc/parc/security/parc_CryptoHasher.h b/libparc/parc/security/parc_CryptoHasher.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_CryptoSuite.c b/libparc/parc/security/parc_CryptoSuite.c old mode 100755 new mode 100644 index b7e1938b..7d7920f5 --- a/libparc/parc/security/parc_CryptoSuite.c +++ b/libparc/parc/security/parc_CryptoSuite.c @@ -35,12 +35,11 @@ parcCryptoSuite_GetCryptoHash(PARCCryptoSuite suite) case PARCCryptoSuite_HMAC_SHA512: // fallthrough case PARCCryptoSuite_RSA_SHA512: return PARCCryptoHashType_SHA512; - case PARCCryptoSuite_NULL_CRC32C: return PARCCryptoHashType_CRC32C; - default: parcTrapIllegalValue(suite, "Unknown crypto suite: %d", suite); + return PARCCryptoHashType_NULL; } } @@ -66,6 +65,7 @@ parcCryptoSuite_GetSignatureSizeBytes(PARCCryptoSuite suite, int keyLengthBits) default: parcTrapIllegalValue(suite, "Unknown crypto suite: %d", suite); + return -1; } } @@ -82,6 +82,7 @@ PARCCryptoSuite parcCryptoSuite_GetFromSigningHash(PARCSigningAlgorithm signAlgo return PARCCryptoSuite_NULL_CRC32C; default: parcTrapIllegalValue(suite, "Unknown signing algorithm suite: %d", signAlgo); + return PARCSigningAlgorithm_UNKNOWN; } } @@ -107,5 +108,6 @@ parcCryptoSuite_GetSigningAlgorithm(PARCCryptoSuite suite) default: parcTrapIllegalValue(suit, "Unknown crypto suite: %d", suite); + return PARCSigningAlgorithm_UNKNOWN; } } diff --git a/libparc/parc/security/parc_CryptoSuite.h b/libparc/parc/security/parc_CryptoSuite.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_DiffieHellmanGroup.h b/libparc/parc/security/parc_DiffieHellmanGroup.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_DiffieHellmanKeyShare.c b/libparc/parc/security/parc_DiffieHellmanKeyShare.c index 313af4a3..48c3ee26 100644 --- a/libparc/parc/security/parc_DiffieHellmanKeyShare.c +++ b/libparc/parc/security/parc_DiffieHellmanKeyShare.c @@ -148,7 +148,7 @@ parcDiffieHellmanKeyShare_SerializePublicKey(PARCDiffieHellmanKeyShare *keyShare const EC_POINT *point = EC_KEY_get0_public_key(ecKey); const EC_GROUP *group = EC_KEY_get0_group(ecKey); char *keyBuffer = EC_POINT_point2hex(group, point, form, bnctx); - int length = strlen(keyBuffer); + int length = (int)strlen(keyBuffer); PARCBuffer *publicKey = parcBuffer_Allocate(length); parcBuffer_PutArray(publicKey, length, (uint8_t *) keyBuffer); diff --git a/libparc/parc/security/parc_Identity.c b/libparc/parc/security/parc_Identity.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_Identity.h b/libparc/parc/security/parc_Identity.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_IdentityFile.c b/libparc/parc/security/parc_IdentityFile.c index 8372a111..395757b6 100644 --- a/libparc/parc/security/parc_IdentityFile.c +++ b/libparc/parc/security/parc_IdentityFile.c @@ -13,23 +13,20 @@ * limitations under the License. */ -/** - */ -#include - -#include +#ifndef _WIN32 +#include +#endif +#include #include -#include +#include #include #include #include #include - #include #include - #include struct parc_identity_file { diff --git a/libparc/parc/security/parc_InMemoryVerifier.c b/libparc/parc/security/parc_InMemoryVerifier.c index 33f6fcfe..8955e1f1 100644 --- a/libparc/parc/security/parc_InMemoryVerifier.c +++ b/libparc/parc/security/parc_InMemoryVerifier.c @@ -99,6 +99,7 @@ _parcInMemoryVerifier_GetCryptoHasher(void *interfaceContext, PARCKeyId *keyid, default: parcTrapUnexpectedState("unsupported hash type: %d", hashType); + return NULL; } } @@ -275,7 +276,7 @@ _parcInMemoryVerifier_RSAKey_Verify(PARCInMemoryVerifier *verifier, PARCCryptoHa { const uint8_t *der_bytes = parcByteArray_Array(parcBuffer_Array(derEncodedKey)); - long der_length = parcBuffer_Remaining(derEncodedKey); + long der_length = (long)parcBuffer_Remaining(derEncodedKey); EVP_PKEY *unwrapped_key = d2i_PUBKEY(NULL, &der_bytes, der_length); if (unwrapped_key != NULL) { @@ -337,7 +338,7 @@ _parcInMemoryVerifier_ECDSAKey_Verify(PARCInMemoryVerifier *verifier, PARCCrypto { const uint8_t *der_bytes = parcByteArray_Array(parcBuffer_Array(derEncodedKey)); - long der_length = parcBuffer_Remaining(derEncodedKey); + long der_length = (long)parcBuffer_Remaining(derEncodedKey); EVP_PKEY *unwrapped_key = d2i_PUBKEY(NULL, &der_bytes, der_length); if (unwrapped_key != NULL) { diff --git a/libparc/parc/security/parc_InMemoryVerifier.h b/libparc/parc/security/parc_InMemoryVerifier.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_Key.c b/libparc/parc/security/parc_Key.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_Key.h b/libparc/parc/security/parc_Key.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_KeyId.c b/libparc/parc/security/parc_KeyId.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_KeyId.h b/libparc/parc/security/parc_KeyId.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_KeyStore.c b/libparc/parc/security/parc_KeyStore.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_KeyStore.h b/libparc/parc/security/parc_KeyStore.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_Pkcs12KeyStore.c b/libparc/parc/security/parc_Pkcs12KeyStore.c index f6c65e4f..12246593 100644 --- a/libparc/parc/security/parc_Pkcs12KeyStore.c +++ b/libparc/parc/security/parc_Pkcs12KeyStore.c @@ -13,31 +13,27 @@ * limitations under the License. */ -/** - */ +#ifndef _WIN32 +#include +#endif #include #include #include #include #include -#include #include - #include - #include #include #include #include - #include #include #include #include #include - #include #include @@ -102,12 +98,22 @@ _parcPkcs12KeyStore_ParseFile(PARCPkcs12KeyStore *keystore, const char *filename { parcSecurity_AssertIsInitialized(); +#ifndef _WIN32 FILE *fp = fopen(filename, "rb"); - parcAssertNotNull(fp, "Error opening %s: %s", filename, strerror(errno)); if (fp == NULL) { return -1; } +#else + FILE *fp; + errno_t err = fopen_s(&fp, filename, "rb"); + char errmsg[1024]; + strerror_s(errmsg, 1024, err); + parcAssertNotNull(fp, "Error opening %s: %s", filename, errmsg); + if (err != 0) { + return -1; + } +#endif PKCS12 *p12Keystore = NULL; d2i_PKCS12_fp(fp, &p12Keystore); @@ -156,17 +162,17 @@ PKCS12 *_createPkcs12KeyStore_RSA( // Extract the private key EVP_PKEY *privateKey = NULL; uint8_t *privateKeyBytes = parcBuffer_Overlay(privateKeyBuffer, parcBuffer_Limit(privateKeyBuffer)); - d2i_PrivateKey(EVP_PKEY_RSA, &privateKey, (const unsigned char **) &privateKeyBytes, parcBuffer_Limit(privateKeyBuffer)); + d2i_PrivateKey(EVP_PKEY_RSA, &privateKey, (const unsigned char **) &privateKeyBytes, (long)parcBuffer_Limit(privateKeyBuffer)); parcBuffer_Release(&privateKeyBuffer); - + // Extract the certificate PARCBuffer *certBuffer = parcCertificate_GetDEREncodedCertificate(certificate); uint8_t *certBytes = parcBuffer_Overlay(certBuffer, parcBuffer_Limit(certBuffer)); X509 *cert = NULL; - d2i_X509(&cert, (const unsigned char **) &certBytes, parcBuffer_Limit(certBuffer)); - + d2i_X509(&cert, (const unsigned char **) &certBytes, (long)parcBuffer_Limit(certBuffer)); + parcCertificate_Release(&certificate); - + PKCS12 *pkcs12 = PKCS12_create((char *) password, "ccnxuser", privateKey, @@ -190,17 +196,17 @@ PKCS12 *_createPkcs12KeyStore_ECDSA( // Extract the private key EVP_PKEY *privateKey = NULL; uint8_t *privateKeyBytes = parcBuffer_Overlay(privateKeyBuffer, parcBuffer_Limit(privateKeyBuffer)); - d2i_PrivateKey(EVP_PKEY_EC, &privateKey, (const unsigned char **) &privateKeyBytes, parcBuffer_Limit(privateKeyBuffer)); + d2i_PrivateKey(EVP_PKEY_EC, &privateKey, (const unsigned char **) &privateKeyBytes, (long)parcBuffer_Limit(privateKeyBuffer)); parcBuffer_Release(&privateKeyBuffer); - + // Extract the certificate PARCBuffer *certBuffer = parcCertificate_GetDEREncodedCertificate(certificate); uint8_t *certBytes = parcBuffer_Overlay(certBuffer, parcBuffer_Limit(certBuffer)); X509 *cert = NULL; - d2i_X509(&cert, (const unsigned char **) &certBytes, parcBuffer_Limit(certBuffer)); - + d2i_X509(&cert, (const unsigned char **) &certBytes, (long)parcBuffer_Limit(certBuffer)); + parcCertificate_Release(&certificate); - + PKCS12 *pkcs12 = PKCS12_create((char *) password, "ccnxuser", privateKey, diff --git a/libparc/parc/security/parc_PublicKeySigner.c b/libparc/parc/security/parc_PublicKeySigner.c index 55404b9c..de048df8 100644 --- a/libparc/parc/security/parc_PublicKeySigner.c +++ b/libparc/parc/security/parc_PublicKeySigner.c @@ -170,7 +170,7 @@ static inline int _SignDigestRSA(const PARCCryptoHash *digestToSign, PARCBuffer EVP_PKEY *privateKey = NULL; size_t keySize = parcBuffer_Remaining(privateKeyBuffer); uint8_t *bytes = parcBuffer_Overlay(privateKeyBuffer, keySize); - privateKey = d2i_PrivateKey(EVP_PKEY_RSA, &privateKey, (const unsigned char **) &bytes, keySize); + privateKey = d2i_PrivateKey(EVP_PKEY_RSA, &privateKey, (const unsigned char **) &bytes, (long)keySize); RSA *rsa = EVP_PKEY_get1_RSA(privateKey); //*sig = parcMemory_Allocate(RSA_size(rsa)); @@ -196,7 +196,7 @@ static inline int _SignDigestECDSA(const PARCCryptoHash *digestToSign, PARCBuffe EVP_PKEY *privateKey = NULL; size_t keySize = parcBuffer_Remaining(privateKeyBuffer); uint8_t *bytes = parcBuffer_Overlay(privateKeyBuffer, keySize); - privateKey = d2i_PrivateKey(EVP_PKEY_EC, &privateKey, (const unsigned char **) &bytes, keySize); + privateKey = d2i_PrivateKey(EVP_PKEY_EC, &privateKey, (const unsigned char **) &bytes, (long)keySize); EC_KEY *ec_key = EVP_PKEY_get1_EC_KEY(privateKey); @@ -283,7 +283,7 @@ _GetSignatureSize(PARCPublicKeySigner *signer) { EVP_PKEY *privateKey = NULL; uint8_t *bytes = parcBuffer_Overlay(privateKeyBuffer, parcBuffer_Limit(privateKeyBuffer)); - privateKey = d2i_PrivateKey(EVP_PKEY_RSA, &privateKey, (const unsigned char **) &bytes, parcBuffer_Limit(privateKeyBuffer)); + privateKey = d2i_PrivateKey(EVP_PKEY_RSA, &privateKey, (const unsigned char **) &bytes, (long)parcBuffer_Limit(privateKeyBuffer)); RSA *rsa = EVP_PKEY_get1_RSA(privateKey); @@ -297,7 +297,7 @@ _GetSignatureSize(PARCPublicKeySigner *signer) EVP_PKEY *privateKey = NULL; size_t keySize = parcBuffer_Remaining(privateKeyBuffer); uint8_t *bytes = parcBuffer_Overlay(privateKeyBuffer, keySize); - privateKey = d2i_PrivateKey(EVP_PKEY_EC, &privateKey, (const unsigned char **) &bytes, keySize); + privateKey = d2i_PrivateKey(EVP_PKEY_EC, &privateKey, (const unsigned char **) &bytes, (long)keySize); EC_KEY *ec_key = EVP_PKEY_get1_EC_KEY(privateKey); diff --git a/libparc/parc/security/parc_SecureRandom.c b/libparc/parc/security/parc_SecureRandom.c index 92c308c1..80189cb9 100644 --- a/libparc/parc/security/parc_SecureRandom.c +++ b/libparc/parc/security/parc_SecureRandom.c @@ -13,19 +13,17 @@ * limitations under the License. */ +#ifndef _WIN32 +#include +#endif -/** - */ #include - #include #include -#include #include #include #include - #include struct parc_securerandom { @@ -77,7 +75,7 @@ static void _parcSecureRandom_ReSeed(PARCSecureRandom *random, PARCBuffer *buffer) { size_t length = parcBuffer_Remaining(buffer); - int wrote_bytes = write(random->randomfd, parcBuffer_Overlay(buffer, length), length); + int wrote_bytes = write(random->randomfd, parcBuffer_Overlay(buffer, length), (long)length); } PARCSecureRandom * @@ -104,7 +102,7 @@ ssize_t parcSecureRandom_NextBytes(PARCSecureRandom *random, PARCBuffer *buffer) { size_t length = parcBuffer_Remaining(buffer); - ssize_t result = read(random->randomfd, parcBuffer_Overlay(buffer, 0), length); + ssize_t result = read(random->randomfd, parcBuffer_Overlay(buffer, 0), (unsigned int)length); return result; } diff --git a/libparc/parc/security/parc_Security.c b/libparc/parc/security/parc_Security.c index e5f7609d..999a41da 100644 --- a/libparc/parc/security/parc_Security.c +++ b/libparc/parc/security/parc_Security.c @@ -50,8 +50,10 @@ #error OpenSSL version must be at least 0.9.8 release #endif +#ifndef _WIN32 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif #include #include @@ -120,8 +122,10 @@ _getThreadId(CRYPTO_THREADID *id) #elif defined(__linux__) // linux (at least ubuntu and redhat) uses unsigned long int CRYPTO_THREADID_set_numeric(id, threadid); +#elif _WIN32 + CRYPTO_THREADID_set_pointer(id, threadid.p); #else -#error Unsupported platform, only __APPLE__ and __linux__ supported +#error Unsupported platform, only __APPLE__, __linux__ and MSVC supported #endif } #endif @@ -206,4 +210,6 @@ parcSecurity_Fini(void) parcAssertTrue(unlockSuccessful, "Unable to unlock the PARC Security framework."); } +#ifndef _WIN32 #pragma GCC diagnostic pop +#endif \ No newline at end of file diff --git a/libparc/parc/security/parc_Security.h b/libparc/parc/security/parc_Security.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_Signature.c b/libparc/parc/security/parc_Signature.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_Signature.h b/libparc/parc/security/parc_Signature.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_Signer.h b/libparc/parc/security/parc_Signer.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_SigningAlgorithm.c b/libparc/parc/security/parc_SigningAlgorithm.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_SymmetricKeyStore.c b/libparc/parc/security/parc_SymmetricKeyStore.c index 49d5055e..0d5f53e0 100644 --- a/libparc/parc/security/parc_SymmetricKeyStore.c +++ b/libparc/parc/security/parc_SymmetricKeyStore.c @@ -26,13 +26,15 @@ * @endcode */ +#ifndef _WIN32 +#include +#endif + #include #include #include -#include #include #include -#include #include #include @@ -390,9 +392,11 @@ parcSymmetricKeyStore_CreateKey(unsigned bits) parcAssertTrue((bits & 0x07) == 0, "bits must be a multiple of 8"); unsigned keylength = bits / 8; - uint8_t buffer[keylength]; + uint8_t *buffer = (uint8_t *)malloc(sizeof(uint8_t) * keylength); RAND_bytes(buffer, keylength); - return parcBuffer_Flip(parcBuffer_PutArray(parcBuffer_Allocate(keylength), keylength, buffer)); + PARCBuffer *parcBuffer = parcBuffer_Flip(parcBuffer_PutArray(parcBuffer_Allocate(keylength), keylength, buffer)); + free(buffer); + return parcBuffer; } PARCBuffer * diff --git a/libparc/parc/security/parc_Verifier.c b/libparc/parc/security/parc_Verifier.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/parc_X509Certificate.c b/libparc/parc/security/parc_X509Certificate.c index 2c964ae7..ab29bfa6 100644 --- a/libparc/parc/security/parc_X509Certificate.c +++ b/libparc/parc/security/parc_X509Certificate.c @@ -389,7 +389,7 @@ parcX509Certificate_CreateFromDERBuffer(const PARCBuffer *buffer) PARCByteArray *array = parcBuffer_Array(buffer); uint8_t *arrayIn = parcByteArray_Array(array); - cert->certificate = d2i_X509(&cert->certificate, (const unsigned char **) &arrayIn, parcBuffer_Remaining(buffer)); + cert->certificate = d2i_X509(&cert->certificate, (const unsigned char **) &arrayIn, (long)parcBuffer_Remaining(buffer)); if (cert->certificate == NULL) { parcX509Certificate_Release(&cert); return NULL; diff --git a/libparc/parc/security/parc_X509Certificate.h b/libparc/parc/security/parc_X509Certificate.h old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_CertificateFactory.c b/libparc/parc/security/test/test_parc_CertificateFactory.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_CertificateType.c b/libparc/parc/security/test/test_parc_CertificateType.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_ContainerEncoding.c b/libparc/parc/security/test/test_parc_ContainerEncoding.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_CryptoCache.c b/libparc/parc/security/test/test_parc_CryptoCache.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_CryptoHash.c b/libparc/parc/security/test/test_parc_CryptoHash.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_CryptoHasher.c b/libparc/parc/security/test/test_parc_CryptoHasher.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_CryptoSuite.c b/libparc/parc/security/test/test_parc_CryptoSuite.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_DiffieHellman.c b/libparc/parc/security/test/test_parc_DiffieHellman.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_DiffieHellmanKeyShare.c b/libparc/parc/security/test/test_parc_DiffieHellmanKeyShare.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_InMemoryVerifier.c b/libparc/parc/security/test/test_parc_InMemoryVerifier.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_Key.c b/libparc/parc/security/test/test_parc_Key.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_KeyStore.c b/libparc/parc/security/test/test_parc_KeyStore.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_Pkcs12KeyStore.c b/libparc/parc/security/test/test_parc_Pkcs12KeyStore.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_SecureRandom.c b/libparc/parc/security/test/test_parc_SecureRandom.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_Security.c b/libparc/parc/security/test/test_parc_Security.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_Signature.c b/libparc/parc/security/test/test_parc_Signature.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_SigningAlgorithm.c b/libparc/parc/security/test/test_parc_SigningAlgorithm.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_SymmetricKeyStore.c b/libparc/parc/security/test/test_parc_SymmetricKeyStore.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_Verifier.c b/libparc/parc/security/test/test_parc_Verifier.c old mode 100755 new mode 100644 diff --git a/libparc/parc/security/test/test_parc_X509Certificate.c b/libparc/parc/security/test/test_parc_X509Certificate.c old mode 100755 new mode 100644 diff --git a/libparc/parc/statistics/parc_BasicStats.h b/libparc/parc/statistics/parc_BasicStats.h old mode 100755 new mode 100644 diff --git a/libparc/parc/statistics/parc_EWMA.c b/libparc/parc/statistics/parc_EWMA.c index 92046ac2..911aba34 100644 --- a/libparc/parc/statistics/parc_EWMA.c +++ b/libparc/parc/statistics/parc_EWMA.c @@ -93,7 +93,7 @@ parcEWMA_Compare(const PARCEWMA *instance, const PARCEWMA *other) } else if (other == NULL) { result = 1; } else { - result = instance->value - other->value; + result = (int)(instance->value - other->value); } return result; @@ -132,7 +132,7 @@ parcEWMA_Equals(const PARCEWMA *x, const PARCEWMA *y) } else { if (x->initialized == y->initialized) { if (_parcEWMA_FloatEquals(x->coefficient, y->coefficient, 0.00001)) { - if (_parcEWMA_FloatEquals(x->value, y->value, 0.00001)) { + if (_parcEWMA_FloatEquals((double)(x->value), (double)(y->value), 0.00001)) { result = true; } } @@ -192,7 +192,7 @@ parcEWMA_Update(PARCEWMA *ewma, const int64_t value) double x = (ewma->coefficient * value); double y = (ewma->coefficient_r * ewma->value); - ewma->value = x + y; + ewma->value = (int64_t)(x + y); } else { ewma->value = value; ewma->initialized = true; diff --git a/libparc/parc/statistics/parc_EWMA.h b/libparc/parc/statistics/parc_EWMA.h old mode 100755 new mode 100644 diff --git a/libparc/parc/testing/parc_MemoryTesting.c b/libparc/parc/testing/parc_MemoryTesting.c old mode 100755 new mode 100644 diff --git a/libparc/parc/testing/parc_MemoryTesting.h b/libparc/parc/testing/parc_MemoryTesting.h old mode 100755 new mode 100644 diff --git a/libparc/parc/testing/test/test_parc_MemoryTesting.c b/libparc/parc/testing/test/test_parc_MemoryTesting.c old mode 100755 new mode 100644 diff --git a/libparc/parc/testing/test/test_parc_ObjectTesting.c b/libparc/parc/testing/test/test_parc_ObjectTesting.c old mode 100755 new mode 100644 diff --git a/libparc/parc/windows/getopt.c b/libparc/parc/windows/getopt.c new file mode 100644 index 00000000..1deaf81e --- /dev/null +++ b/libparc/parc/windows/getopt.c @@ -0,0 +1,149 @@ +/* $NetBSD: getopt.c,v 1.16 1999/12/02 13:15:56 kleink Exp $ */ + +/* + * Copyright (c) 1987, 1993, 1994, 1995 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS + * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if 0 +static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; +#endif + +#include +#include +#include +#include + +#define __P(x) x +#define _DIAGASSERT(x) assert(x) + +#ifdef __weak_alias +__weak_alias(getopt,_getopt); +#endif + + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +static char * _progname __P((char *)); +int getopt_internal __P((int, char * const *, const char *)); + +static char * +_progname(nargv0) + char * nargv0; +{ + char * tmp; + + _DIAGASSERT(nargv0 != NULL); + + tmp = strrchr(nargv0, '/'); + if (tmp) + tmp++; + else + tmp = nargv0; + return(tmp); +} + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +getopt(nargc, nargv, ostr) + int nargc; + char * const nargv[]; + const char *ostr; +{ + static char *__progname = 0; + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + __progname = __progname?__progname:_progname(*nargv); + + _DIAGASSERT(nargv != NULL); + _DIAGASSERT(ostr != NULL); + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-' /* found "--" */ + && place[1] == '\0') { + ++optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (optopt == (int)'-') + return (-1); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)fprintf(stderr, + "%s: illegal option -- %c\n", __progname, optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)fprintf(stderr, + "%s: option requires an argument -- %c\n", + __progname, optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} + diff --git a/libparc/parc/windows/getopt.h b/libparc/parc/windows/getopt.h new file mode 100644 index 00000000..6f0c19ee --- /dev/null +++ b/libparc/parc/windows/getopt.h @@ -0,0 +1,33 @@ +#ifndef __GETOPT_H__ +#define __GETOPT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +extern int opterr; /* if error message should be printed */ +extern int optind; /* index into parent argv vector */ +extern int optopt; /* character checked for validity */ +extern int optreset; /* reset getopt */ +extern char *optarg; /* argument associated with option */ + +struct option +{ + const char *name; + int has_arg; + int *flag; + int val; +}; + +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +int getopt(int, char**, const char*); +int getopt_long(int, char**, const char*, const struct option*, int*); + +#ifdef __cplusplus +} +#endif + +#endif /* __GETOPT_H__ */ diff --git a/libparc/parc/windows/getopt_long.c b/libparc/parc/windows/getopt_long.c new file mode 100644 index 00000000..23321dd1 --- /dev/null +++ b/libparc/parc/windows/getopt_long.c @@ -0,0 +1,233 @@ + +/* + * Copyright (c) 1987, 1993, 1994, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS + * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include "getopt.h" + +extern int opterr; /* if error message should be printed */ +extern int optind; /* index into parent argv vector */ +extern int optopt; /* character checked for validity */ +extern int optreset; /* reset getopt */ +extern char *optarg; /* argument associated with option */ + +#define __P(x) x +#define _DIAGASSERT(x) assert(x) + +static char * __progname __P((char *)); +int getopt_internal __P((int, char * const *, const char *)); + +static char * +__progname(nargv0) + char * nargv0; +{ + char * tmp; + + _DIAGASSERT(nargv0 != NULL); + + tmp = strrchr(nargv0, '/'); + if (tmp) + tmp++; + else + tmp = nargv0; + return(tmp); +} + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +getopt_internal(nargc, nargv, ostr) + int nargc; + char * const *nargv; + const char *ostr; +{ + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + _DIAGASSERT(nargv != NULL); + _DIAGASSERT(ostr != NULL); + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + /* ++optind; */ + place = EMSG; + return (-2); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (optopt == (int)'-') + return (-1); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)fprintf(stderr, + "%s: illegal option -- %c\n", __progname(nargv[0]), optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if ((opterr) && (*ostr != ':')) + (void)fprintf(stderr, + "%s: option requires an argument -- %c\n", + __progname(nargv[0]), optopt); + return (BADARG); + } else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} + +#if 0 +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +getopt2(nargc, nargv, ostr) + int nargc; + char * const *nargv; + const char *ostr; +{ + int retval; + + if ((retval = getopt_internal(nargc, nargv, ostr)) == -2) { + retval = -1; + ++optind; + } + return(retval); +} +#endif + +/* + * getopt_long -- + * Parse argc/argv argument vector. + */ +int +getopt_long(nargc, nargv, options, long_options, index) + int nargc; + char ** nargv; + const char * options; + const struct option * long_options; + int * index; +{ + int retval; + + _DIAGASSERT(nargv != NULL); + _DIAGASSERT(options != NULL); + _DIAGASSERT(long_options != NULL); + /* index may be NULL */ + + if ((retval = getopt_internal(nargc, nargv, options)) == -2) { + char *current_argv = nargv[optind++] + 2, *has_equal; + int i, current_argv_len, match = -1; + + if (*current_argv == '\0') { + return(-1); + } + if ((has_equal = strchr(current_argv, '=')) != NULL) { + current_argv_len = (int)(has_equal - current_argv); + has_equal++; + } else + current_argv_len = (int)strlen(current_argv); + + for (i = 0; long_options[i].name; i++) { + if (strncmp(current_argv, long_options[i].name, current_argv_len)) + continue; + + if (strlen(long_options[i].name) == (unsigned)current_argv_len) { + match = i; + break; + } + if (match == -1) + match = i; + } + if (match != -1) { + if (long_options[match].has_arg == required_argument || + long_options[match].has_arg == optional_argument) { + if (has_equal) + optarg = has_equal; + else + optarg = nargv[optind++]; + } + if ((long_options[match].has_arg == required_argument) + && (optarg == NULL)) { + /* + * Missing argument, leading : + * indicates no error should be generated + */ + if ((opterr) && (*options != ':')) + (void)fprintf(stderr, + "%s: option requires an argument -- %s\n", + __progname(nargv[0]), current_argv); + return (BADARG); + } + } else { /* No matching argument */ + if ((opterr) && (*options != ':')) + (void)fprintf(stderr, + "%s: illegal option -- %s\n", __progname(nargv[0]), current_argv); + return (BADCH); + } + if (long_options[match].flag) { + *long_options[match].flag = long_options[match].val; + retval = 0; + } else + retval = long_options[match].val; + if (index) + *index = match; + } + return(retval); +} diff --git a/libparc/parc/windows/parc_Utils.c b/libparc/parc/windows/parc_Utils.c new file mode 100644 index 00000000..8daf57fd --- /dev/null +++ b/libparc/parc/windows/parc_Utils.c @@ -0,0 +1,128 @@ + +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * 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. + */ + +#include +#include +#include +#include +#ifndef _vscprintf +/* For some reason, MSVC fails to honour this #ifndef. */ +/* Hence function renamed to _vscprintf_so(). */ +int _vscprintf_so(const char *format, va_list pargs) +{ + int retval; + va_list argcopy; + va_copy(argcopy, pargs); + retval = vsnprintf(NULL, 0, format, argcopy); + va_end(argcopy); + return retval; +} +#endif // _vscprintf + +#ifndef vasprintf +int vasprintf(char **strp, const char *fmt, va_list ap) +{ + int len = _vscprintf_so(fmt, ap); + if (len == -1) + return -1; + char *str = malloc((size_t)len + 1); + if (!str) + return -1; + int r = vsnprintf(str, len + 1, fmt, ap); /* "secure" version of vsprintf */ + if (r == -1) + return free(str), -1; + *strp = str; + return r; +} +#endif // vasprintf + +#ifndef dprintf +int dprintf(int fd, char *fmt, ...) { + va_list ap; + FILE *f = _fdopen( fd, "rw" ); + int rc; + + va_start(ap, &fmt); + rc = vfprintf(f, fmt, ap); + fclose(f); + va_end(ap); + return rc; +} +#endif + +#ifndef asprintf +int asprintf(char *strp[], const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int r = vasprintf(strp, fmt, ap); + va_end(ap); + return r; +} +#endif // asprintf + + +int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) + // until 00:00:00 January 1, 1970 + static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime( &system_time ); + SystemTimeToFileTime( &system_time, &file_time ); + time = ((uint64_t)file_time.dwLowDateTime ) ; + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long) ((time - EPOCH) / 10000000L); + tp->tv_usec = (long) (system_time.wMilliseconds * 1000); + return 0; +} + +#ifndef strndup +char *strndup(const char *str, size_t chars) +{ + char *buffer; + int n; + + buffer = (char *) malloc(chars +1); + if (buffer) + { + for (n = 0; ((n < chars) && (str[n] != 0)) ; n++) buffer[n] = str[n]; + buffer[n] = 0; + } + + return buffer; +} +#endif + + +void usleep(__int64 usec) +{ + HANDLE timer; + LARGE_INTEGER ft; + + ft.QuadPart = -(10 * usec); // Convert to 100 nanosecond interval, negative value indicates relative time + + timer = CreateWaitableTimer(NULL, TRUE, NULL); + SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); +} \ No newline at end of file diff --git a/libparc/parc/windows/parc_Utils.h b/libparc/parc/windows/parc_Utils.h new file mode 100644 index 00000000..975eae0f --- /dev/null +++ b/libparc/parc/windows/parc_Utils.h @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * 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. + */ + +#ifndef PARC_UTILS_H +#define PARC_UTILS_H +#define WIN32_LEAN_AND_MEAN +#define HAVE_STRUCT_TIMESPEC +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef IOVEC +#define IOVEC +struct iovec { + void* iov_base; + size_t iov_len; +}; +#endif + +typedef uint16_t in_port_t; + +#ifndef SLEEP +#define SLEEP +#define sleep Sleep +#endif + +#ifndef USLEEP +#define USLEEP +void usleep(__int64 usec); +#endif + +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif + +#define PARCLibrary_DISABLE_ATOMICS +#include +typedef SSIZE_T ssize_t; + +#ifndef __ATTRIBUTE__ +#define __ATTRIBUTE__ +#define __attribute__(A) +#endif + +#ifndef RESTRICT +#define RESTRICT +#define restrict __restrict +#endif + +#ifndef _vscprintf +/* For some reason, MSVC fails to honour this #ifndef. */ +/* Hence function renamed to _vscprintf_so(). */ +int _vscprintf_so(const char *format, va_list pargs); +#endif // _vscprintf + +#ifndef vasprintf +int vasprintf(char **strp, const char *fmt, va_list ap); +#endif // vasprintf + +#ifndef asprintf +int asprintf(char *strp[], const char *fmt, ...); +#endif // asprintf + +#ifndef GETTIMEOFDAY +#define GETTIMEOFDAY +int gettimeofday(struct timeval * tp, struct timezone * tzp); +#endif + +#ifndef strndup +char *strndup(const char *str, size_t chars); +#endif + +#ifndef dprintf +int dprintf(int fd, char *fmt, ...); +#endif + +#ifndef timersub +#define timersub(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((result)->tv_usec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_usec += 1000000; \ + } \ + } while (0) +#endif // timersub + +#ifndef dup +#define dup _dup +#endif + +#ifndef access +#define access _access +#endif + +#ifndef close +#define close _close +#endif + +#ifndef write +#define write _write +#endif + +#ifndef open +#define open _open +#endif + +#ifndef unlink +#define unlink _unlink +#endif + +#ifndef read +#define read _read +#endif + +#ifndef strcasecmp +#define strncasecmp _strnicmp +#endif + +#ifndef strcasecmp + +#define strcasecmp _stricmp +#endif + +#ifndef S_ISREG +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#endif +#ifndef R_OK +#define R_OK 4 /* Test for read permission. */ +#endif +#ifndef W_OK +#define W_OK 2 /* Test for write permission. */ +#endif +#ifndef F_OK +#define F_OK 0 +#endif + +#ifndef STDIN_FILENO +#define STDIN_FILENO _fileno(stdin) +#endif + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO _fileno(stdout) +#endif + +#ifndef STDERR_FILENO +#define STDERR_FILENO _fileno(stderr) +#endif + +#endif \ No newline at end of file diff --git a/libparc/parc/windows/queue.h b/libparc/parc/windows/queue.h new file mode 100644 index 00000000..925ccf14 --- /dev/null +++ b/libparc/parc/windows/queue.h @@ -0,0 +1,488 @@ +/* $OpenBSD: queue.h,v 1.16 2000/09/07 19:47:59 art Exp $ */ +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + */ + +#ifndef SYS_QUEUE_H__ +#define SYS_QUEUE_H__ + + /* + * This file defines five types of data structures: singly-linked lists, + * lists, simple queues, tail queues, and circular queues. + * + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A simple queue is headed by a pair of pointers, one the head of the + * list and the other to the tail of the list. The elements are singly + * linked to save space, so elements can only be removed from the + * head of the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the + * list. A simple queue may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * A circle queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the list. + * A circle queue may be traversed in either direction, but has a more + * complex end of list detection. + * + * For details on the use of these macros, see the queue(3) manual page. + */ + + /* + * Singly-linked List definitions. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#ifndef _WIN32 +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} +#endif + + /* + * Singly-linked List access methods. + */ +#define SLIST_FIRST(head) ((head)->slh_first) +#define SLIST_END(head) NULL +#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_FOREACH(var, head, field) \ + for((var) = SLIST_FIRST(head); \ + (var) != SLIST_END(head); \ + (var) = SLIST_NEXT(var, field)) + + /* + * Singly-linked List functions. + */ +#define SLIST_INIT(head) { \ + SLIST_FIRST(head) = SLIST_END(head); \ +} + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ +} while (0) + + /* + * List definitions. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + + /* + * List access methods + */ +#define LIST_FIRST(head) ((head)->lh_first) +#define LIST_END(head) NULL +#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_FOREACH(var, head, field) \ + for((var) = LIST_FIRST(head); \ + (var)!= LIST_END(head); \ + (var) = LIST_NEXT(var, field)) + + /* + * List functions. + */ +#define LIST_INIT(head) do { \ + LIST_FIRST(head) = LIST_END(head); \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ +} while (0) + +#define LIST_REMOVE(elm, field) do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ +} while (0) + +#define LIST_REPLACE(elm, elm2, field) do { \ + if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ + (elm2)->field.le_next->field.le_prev = \ + &(elm2)->field.le_next; \ + (elm2)->field.le_prev = (elm)->field.le_prev; \ + *(elm2)->field.le_prev = (elm2); \ +} while (0) + + /* + * Simple queue definitions. + */ +#define SIMPLEQ_HEAD(name, type) \ +struct name { \ + struct type *sqh_first; /* first element */ \ + struct type **sqh_last; /* addr of last next element */ \ +} + +#define SIMPLEQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).sqh_first } + +#define SIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqe_next; /* next element */ \ +} + + /* + * Simple queue access methods. + */ +#define SIMPLEQ_FIRST(head) ((head)->sqh_first) +#define SIMPLEQ_END(head) NULL +#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head)) +#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) + +#define SIMPLEQ_FOREACH(var, head, field) \ + for((var) = SIMPLEQ_FIRST(head); \ + (var) != SIMPLEQ_END(head); \ + (var) = SIMPLEQ_NEXT(var, field)) + + /* + * Simple queue functions. + */ +#define SIMPLEQ_INIT(head) do { \ + (head)->sqh_first = NULL; \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (0) + +#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (head)->sqh_first = (elm); \ +} while (0) + +#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.sqe_next = NULL; \ + *(head)->sqh_last = (elm); \ + (head)->sqh_last = &(elm)->field.sqe_next; \ +} while (0) + +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (listelm)->field.sqe_next = (elm); \ +} while (0) + +#define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \ + if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (0) + + /* + * Tail queue definitions. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} + + /* + * tail queue access methods + */ +#define TAILQ_FIRST(head) ((head)->tqh_first) +#define TAILQ_END(head) NULL +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + /* XXX */ +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) +#define TAILQ_EMPTY(head) \ + (TAILQ_FIRST(head) == TAILQ_END(head)) + +#define TAILQ_FOREACH(var, head, field) \ + for((var) = TAILQ_FIRST(head); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_NEXT(var, field)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for((var) = TAILQ_LAST(head, headname); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_PREV(var, headname, field)) + +/* + * Tail queue functions. + */ +#define TAILQ_INIT(head) do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_REPLACE(head, elm, elm2, field) do { \ + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ + (elm2)->field.tqe_next->field.tqe_prev = \ + &(elm2)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm2)->field.tqe_next; \ + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ + *(elm2)->field.tqe_prev = (elm2); \ +} while (0) + + /* + * Circular queue definitions. + */ +#define CIRCLEQ_HEAD(name, type) \ +struct name { \ + struct type *cqh_first; /* first element */ \ + struct type *cqh_last; /* last element */ \ +} + +#define CIRCLEQ_HEAD_INITIALIZER(head) \ + { CIRCLEQ_END(&head), CIRCLEQ_END(&head) } + +#define CIRCLEQ_ENTRY(type) \ +struct { \ + struct type *cqe_next; /* next element */ \ + struct type *cqe_prev; /* previous element */ \ +} + + /* + * Circular queue access methods + */ +#define CIRCLEQ_FIRST(head) ((head)->cqh_first) +#define CIRCLEQ_LAST(head) ((head)->cqh_last) +#define CIRCLEQ_END(head) ((void *)(head)) +#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next) +#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev) +#define CIRCLEQ_EMPTY(head) \ + (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head)) + +#define CIRCLEQ_FOREACH(var, head, field) \ + for((var) = CIRCLEQ_FIRST(head); \ + (var) != CIRCLEQ_END(head); \ + (var) = CIRCLEQ_NEXT(var, field)) + +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ + for((var) = CIRCLEQ_LAST(head); \ + (var) != CIRCLEQ_END(head); \ + (var) = CIRCLEQ_PREV(var, field)) + + /* + * Circular queue functions. + */ +#define CIRCLEQ_INIT(head) do { \ + (head)->cqh_first = CIRCLEQ_END(head); \ + (head)->cqh_last = CIRCLEQ_END(head); \ +} while (0) + +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm)->field.cqe_next; \ + (elm)->field.cqe_prev = (listelm); \ + if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \ + (head)->cqh_last = (elm); \ + else \ + (listelm)->field.cqe_next->field.cqe_prev = (elm); \ + (listelm)->field.cqe_next = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm); \ + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ + if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \ + (head)->cqh_first = (elm); \ + else \ + (listelm)->field.cqe_prev->field.cqe_next = (elm); \ + (listelm)->field.cqe_prev = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.cqe_next = (head)->cqh_first; \ + (elm)->field.cqe_prev = CIRCLEQ_END(head); \ + if ((head)->cqh_last == CIRCLEQ_END(head)) \ + (head)->cqh_last = (elm); \ + else \ + (head)->cqh_first->field.cqe_prev = (elm); \ + (head)->cqh_first = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.cqe_next = CIRCLEQ_END(head); \ + (elm)->field.cqe_prev = (head)->cqh_last; \ + if ((head)->cqh_first == CIRCLEQ_END(head)) \ + (head)->cqh_first = (elm); \ + else \ + (head)->cqh_last->field.cqe_next = (elm); \ + (head)->cqh_last = (elm); \ +} while (0) + +#define CIRCLEQ_REMOVE(head, elm, field) do { \ + if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \ + (head)->cqh_last = (elm)->field.cqe_prev; \ + else \ + (elm)->field.cqe_next->field.cqe_prev = \ + (elm)->field.cqe_prev; \ + if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \ + (head)->cqh_first = (elm)->field.cqe_next; \ + else \ + (elm)->field.cqe_prev->field.cqe_next = \ + (elm)->field.cqe_next; \ +} while (0) + +#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \ + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \ + CIRCLEQ_END(head)) \ + (head).cqh_last = (elm2); \ + else \ + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \ + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \ + CIRCLEQ_END(head)) \ + (head).cqh_first = (elm2); \ + else \ + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \ +} while (0) + +#endif /* !SYS_QUEUE_H__ */ \ No newline at end of file -- cgit 1.2.3-korg