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 )
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})
${LIBEVENT_LIBRARIES}
${OPENSSL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
+ ${PTHREAD_LIBRARIES}
+ ${WSOCK32_LIBRARY}
+ ${WS2_32_LIBRARY}
)
endif()
--- /dev/null
+# Copyright (c) 2019 Cisco and/or its affiliates.\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at:\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+########################################\r
+#\r
+# Find the PThread libraries and includes\r
+# This module sets:\r
+# PTHREAD_FOUND: True if Libconsumer-producer was found\r
+# PTHREADR_LIBRARY: The Libconsumer-producer library\r
+# PTHREAD_LIBRARIES: The Libconsumer-producer library and dependencies\r
+# PTHREAD_INCLUDE_DIR: The Libconsumer-producer include dir\r
+#\r
+\r
+\r
+set(PTHREAD_SEARCH_PATH_LIST\r
+ ${PTHREAD_HOME}\r
+ $ENV{PTHREAD_HOME}\r
+ /usr/local\r
+ /opt\r
+ /usr\r
+)\r
+\r
+find_path(PTHREAD_INCLUDE_DIR pthread.h\r
+ HINTS ${PTHREAD_SEARCH_PATH_LIST}\r
+ PATH_SUFFIXES include\r
+ DOC "Find the pthreadincludes"\r
+)\r
+\r
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)\r
+ find_library(PTHREAD_LIBRARY NAMES pthreadVC2.lib\r
+ HINTS ${PTHREAD_SEARCH_PATH_LIST}\r
+ PATH_SUFFIXES lib/x64\r
+ DOC "Find the pthread libraries"\r
+ )\r
+elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)\r
+ find_library(PTHREAD_LIBRARY NAMES pthreadVC2.lib\r
+ HINTS ${PTHREAD_SEARCH_PATH_LIST}\r
+ PATH_SUFFIXES lib/x32\r
+ DOC "Find the pthread libraries"\r
+ )\r
+endif()\r
+\r
+\r
+set(PTHREAD_LIBRARIES ${PTHREAD_LIBRARY})\r
+set(PTHREAD_INCLUDE_DIRS ${PTHREAD_INCLUDE_DIR})\r
+\r
+include(FindPackageHandleStandardArgs)\r
+find_package_handle_standard_args(Pthread DEFAULT_MSG PTHREAD_LIBRARIES PTHREAD_INCLUDE_DIRS)
\ No newline at end of file
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
)
endif()
+if(WIN32)\r
+ list(APPEND LIBPARC_SOURCE_FILES\r
+ ${WINDOWS_UTILITY_SOURCE_FILES}\r
+ ${WINDOWS_UTILITY_HEADER_FILES}\r
+ )\r
+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})
)
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
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)
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_Memory.h>
#include "internal_parc_Event.h"
'~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'
};
+#ifndef min
#define min(a, b) ((a < b) ? a : b)
+#endif
/**
* Encode the 3-byte quantum pointed to by <code>quantum</code> into 4 encoded characters.
}
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;
}
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;
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);
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) {
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;
}
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);
}
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,
}
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);
}
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;
* }
* @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.
#include <stdio.h>
#include <string.h>
+#ifndef _WIN32
#include <sys/time.h>
+#endif
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Buffer.h>
struct parc_buffer_composer;
typedef struct parc_buffer_composer PARCBufferComposer;
+#include <config.h>
#include <parc/algol/parc_Buffer.h>
extern parcObjectDescriptor_Declaration(PARCBufferComposer);
}
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);
}
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,
}
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);
_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;
}
}
printf(" %s\n", accumulator);
+ free(accumulator);
}
void
* }
* @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`.
* }
* @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.
* 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)
+
+\r
+#define EXPAND( x ) x\r
+#define parcCMacro_IfElse(A, B, ...) EXPAND(parcCMacro_ThirdParam( __VA_ARGS__ , A, B, NOOP))
/** \cond */
#define _parcCMacro_Cat_(A, B) A ## B
* limitations under the License.
*/
-/**
- */
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
#include <config.h>
-
#include <stdio.h>
#include <string.h>
-#include <sys/time.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Memory.h>
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;
}
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
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;
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;
#ifndef PARC_parc_Clock_h
#define PARC_parc_Clock_h
-#include <inttypes.h>
+#ifndef _WIN32
#include <sys/time.h>
+#endif
+
+#include <inttypes.h>
struct parc_clock;
typedef struct parc_clock PARCClock;
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
+#ifndef _WIN32
+#include <sys/queue.h>
+#endif
+#include <config.h>
#include <stdio.h>
-#include <sys/queue.h>
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_Deque.h>
-
#include <parc/algol/parc_DisplayIndented.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Memory.h>
* @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)`.
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#include <unistd.h>
#include <string.h>
#include <ctype.h>
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_DisplayIndented.h>
static char *_spaces = " ";
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);
}
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;
}
}
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;
offset += bytesInLine;
}
printf(" %s]\n", accumulator);
+ free(accumulator);
}
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <stdlib.h>
+#ifndef _WIN32
#include <unistd.h>
+#include <pwd.h>
+#endif
+#include <config.h>
+#include <sys/types.h>
+#include <stdlib.h>
#include <parc/algol/parc_Environment.h>
#include <parc/algol/parc_File.h>
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
+
}
{
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
int
parcEventQueue_GetFileDescriptor(PARCEventQueue *parcEventQueue)
{
- return bufferevent_getfd(parcEventQueue->buffereventBuffer);
+ return (int)bufferevent_getfd(parcEventQueue->buffereventBuffer);
}
PARCEventType
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
#ifndef libparc_parc_EventQueue_h
#define libparc_parc_EventQueue_h
-#include <sys/types.h>
+#ifndef _WIN32
#include <sys/socket.h>
+#endif
+
+#include <sys/types.h>
#include <parc/algol/parc_Event.h>
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+#include <config.h>
#include <stdio.h>
-#include <unistd.h>
#include "internal_parc_Event.h"
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_EventScheduler.h>
#include <parc/algol/parc_FileOutputStream.h>
#include <parc/logging/parc_Log.h>
* Current implementation based on top of libevent2
*/
+#ifndef _WIN32
#include <sys/errno.h>
+#endif
+
#include <event2/listener.h>
/**
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);
#ifndef libparc_parc_EventSocket_h
#define libparc_parc_EventSocket_h
-#include <sys/types.h>
+#ifndef _WIN32
#include <sys/socket.h>
+#endif
+
+#include <sys/types.h>
/**
* Current implementation based on top of libevent2
#define __USE_XOPEN_EXTENDED
#endif //__USE_XOPEN_EXTENDED
-#include <stdio.h>
+#ifndef _WIN32
#include <unistd.h>
+#include <ftw.h>
+#endif
+
+#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
-
-#include <ftw.h>
#include <inttypes.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include <parc/assert/parc_Assert.h>
-
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_PathName.h>
#include <parc/algol/parc_File.h>
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;
return result;
}
+#ifndef _WIN32
static int
_deleteNode(const char *path, const struct stat *stat, int flag, struct FTW *ftwbuf)
{
}
return result;
}
+#endif
/**
* @function parcFile_Delete
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);
}
/**
*/
+#ifndef _WIN32
#include <config.h>
+#endif
#include <stdio.h>
#include <string.h>
-#include <sys/time.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Buffer.h>
#include <parc/algol/parc_Memory.h>
-
#include <parc/algol/parc_RandomAccessFile.h>
-
#include <parc/algol/parc_FileChunker.h>
PARCChunkerInterface *PARCFileChunkerAsChunker = &(PARCChunkerInterface) {
{
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);
* limitations under the License.
*/
-/**
- */
-#include <config.h>
+#ifndef _WIN32
+#include <sys/uio.h>
+#include <unistd.h>
+#endif
+#include <config.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
-#include <sys/uio.h>
-#include <unistd.h>
#include <sys/stat.h>
#include <parc/assert/parc_Assert.h>
{
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;
}
* limitations under the License.
*/
-/**
- */
-#include <config.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+#include <config.h>
#include <stdio.h>
-#include <unistd.h>
#include <parc/assert/parc_Assert.h>
-
#include <parc/algol/parc_FileOutputStream.h>
#include <parc/algol/parc_Object.h>
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;
}
* website for details on the algorithm: http://www.isthe.com/chongo/tech/comp/fnv
*
*/
-#include <config.h>
-#include <stdint.h>
+#ifndef _WIN32
#include <unistd.h>
+#endif
+#include <config.h>
+#include <stdint.h>
#include <parc/algol/parc_Hash.h>
#include <parc/algol/parc_Object.h>
}
static void
-_expand(PARCHashCodeTable *hashCodeTable)
+_expandTable(PARCHashCodeTable *hashCodeTable)
{
LinearAddressingHashTable temp_table;
LinearAddressingHashTable *old_table = &hashCodeTable->hashtable;
parcAssertNotNull(data, "Parameter data must be non-null");
if (table->hashtable.tableSize >= table->hashtable.expandThreshold) {
- _expand(table);
+ _expandTable(table);
}
HashCodeType hashcode = table->keyHashCodeFunc(key);
do {
result = _innerTableAdd(&table->hashtable, table->keyEqualsFunc, hashcode, key, data);
if (result == ADD_NOSPACE) {
- _expand(table);
+ _expandTable(table);
}
} while (result == ADD_NOSPACE);
{
PARCHashCode keyHash = parcObject_HashCode(key);
- int bucket = keyHash % hashMap->capacity;
+ int bucket = (int)(keyHash % hashMap->capacity);
_PARCHashMapEntry *result = NULL;
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();
}
{
PARCHashCode keyHash = parcObject_HashCode(key);
- int bucket = keyHash % hashMap->capacity;
+ int bucket = (int)(keyHash % hashMap->capacity);
bool result = false;
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();
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;
}
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);
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);
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
+#ifndef _WIN32
+#include <sys/queue.h>
+#endif
+#include <config.h>
#include <stdio.h>
-#include <sys/queue.h>
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_LinkedList.h>
-
#include <parc/algol/parc_DisplayIndented.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Memory.h>
* @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)`.
}
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]);
int
parcList_HashCode(const PARCList *list)
{
- return (list->interface->HashCode)(list->instance);
+ return (int)(list->interface->HashCode)(list->instance);
}
ssize_t
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;
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
-
+#ifndef _WIN32
#include <unistd.h>
+#endif
+
+#include <config.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
-
#include <stdint.h>
#include <stdbool.h>
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_SafeMemory.h>
#include <parc/algol/parc_StdlibMemory.h>
((PARCMemoryDeallocate *) parcMemory->Deallocate)(pointer);
}
+#ifdef _WIN32
+void
+parcMemory_DeallocateAlignImpl(void **pointer)
+{
+ ((PARCMemoryDeallocateAlign *) parcMemory->DeallocateAlign)(pointer);
+}
+#endif
+
void *
parcMemory_Reallocate(void *pointer, size_t newSize)
{
.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
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);
*/
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,
*/
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,
*
* @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
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
-
+#ifndef _WIN32
#include <sys/socket.h>
-#include <ctype.h>
-#include <sys/types.h>
#include <netdb.h>
+#endif
+#include <config.h>
+#include <ctype.h>
+#include <sys/types.h>
#include <parc/algol/parc_Network.h>
-
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_BufferComposer.h>
#include <parc/algol/parc_Buffer.h>
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;
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);
}
parcTrapIllegalValue(address, "Bad scheme '%s'", address);
+ return NULL;
}
bool
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);
#ifndef libparc_parc_Networking_h
#define libparc_parc_Networking_h
+#ifndef _WIN32
#include <arpa/inet.h>
#include <netinet/in.h>
+#endif
#include <parc/algol/parc_BufferComposer.h>
#include <parc/algol/parc_Buffer.h>
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
+#ifndef _WIN32
+#include <unistd.h>
+#include <sys/errno.h>
+#include <sys/time.h>
+#endif
+#include <config.h>
#include <stdio.h>
#include <inttypes.h>
-#include <unistd.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/errno.h>
#include <pthread.h>
#include <time.h>
-#include <sys/time.h>
-
#include <stdint.h>
#include <stdbool.h>
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_DisplayIndented.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Memory.h>
_PARCObjectHeader *header = _parcObject_Header(object);
+#ifndef _WIN32
parcAtomicUint64_Increment(&header->references);
+#else
+ InterlockedIncrement((unsigned volatile *)(&header->references));
+#endif
return (PARCObject *) object;
}
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
+
}
}
size_t totalMemoryLength = prefixLength + descriptor->objectSize;
void *origin = NULL;
+
+ //origin = parcMemory_AllocateAndClear(totalMemoryLength);
parcMemory_MemAlign(&origin, sizeof(void *), totalMemoryLength);
if (origin == NULL) {
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)) {
}
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 {
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.");
_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;
.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;
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;
{
_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
+
;
}
}; \
_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) = { \
}; \
_Pragma("GCC diagnostic warning \"-Woverride-init\"") \
const PARCObjectDescriptor parcObject_DescriptorName(_subtype)
-#endif
+#else\r
+#define parcObject_Extends(_subtype, _superType, ...) \\r
+ parcObjectDescriptor_Declaration(_subtype) = { \\r
+ .super = &parcObject_DescriptorName(_superType), \\r
+ .name = #_subtype, \\r
+ .objectSize = 0, \\r
+ .objectAlignment = 0, \\r
+ .destroy = NULL, \\r
+ .destructor = NULL, \\r
+ .release = NULL, \\r
+ .copy = NULL, \\r
+ .toString = NULL, \\r
+ .equals = NULL, \\r
+ .compare = NULL, \\r
+ .hashCode = NULL, \\r
+ .toJSON = NULL, \\r
+ .display = NULL, \\r
+ .isLockable = true, \\r
+ .typeState = NULL, \\r
+ __VA_ARGS__ \\r
+ }; \\r
+ const PARCObjectDescriptor parcObject_DescriptorName(_subtype)\r
+#endif\r
/**
* Define a new PARC Object implementation, by composing a new PARC Object Descriptor referencing an old one.
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+#include <config.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include <unistd.h>
-
#include <parc/algol/parc_Deque.h>
-
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_DisplayIndented.h>
#include <parc/algol/parc_Memory.h>
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();
* @endcode
*/
static void
-_expand(PARCPriorityQueue *queue)
+_expandTable(PARCPriorityQueue *queue)
{
queue->capacity *= 2;
queue->array = parcMemory_Reallocate(queue->array, sizeof(HeapEntry) * queue->capacity);
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
}
const char *
-parcProperties_GetProperty(const PARCProperties *properties, const char *name)
+parcProperties_GetProperty(const PARCProperties *properties, const char *restrict name)
{
char *result = NULL;
# include <execinfo.h>
#endif
+#ifndef _WIN32
#include <unistd.h>
+#include <sys/errno.h>
+#include <sys/queue.h>
+#endif
+
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <sys/errno.h>
-#include <sys/queue.h>
#include <pthread.h>
-
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
{
bool result = true;
- PARCSafeMemoryState state = _parcSafeMemory_GetState(memory);
+ PARCSafeMemoryState state = _parcSafeMemory_GetState((const PARCSafeMemoryUsable *)memory);
if (state != PARCSafeMemoryState_OK) {
return false;
}
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,
* limitations under the License.
*/
-/**
- */
-#include <config.h>
+#ifndef _WIN32
+#include <sys/errno.h>
+#endif
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/errno.h>
#include <stdbool.h>
#include <string.h>
-#include <strings.h>
#include <pthread.h>
#include <parc/assert/parc_Assert.h>
-
#include <parc/algol/parc_StdlibMemory.h>
static uint32_t _parcStdlibMemory_OutstandingAllocations;
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();
_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)
{
.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
*/
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
* limitations under the License.
*/
-/**
- */
-#include <config.h>
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
+#include <config.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
-#include <sys/time.h>
#include <parc/assert/parc_Assert.h>
-
#include <parc/algol/parc_Time.h>
#include <parc/algol/parc_Memory.h>
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;
}
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;
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);
}
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);
}
#ifndef libparc_parc_Time_h
#define libparc_parc_Time_h
+#ifndef _WIN32
#include <sys/time.h>
+#endif
+
#include <stdint.h>
/**
* limitations under the License.
*/
-/**
- *
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
-
+#ifndef _WIN32
#include <unistd.h>
+#endif
+
+#include <config.h>
#include <stdio.h>
#include <string.h>
-#include <strings.h>
#include <ctype.h>
#include <stdarg.h>
-
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_URI.h>
-
#include <parc/algol/parc_URIPath.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Buffer.h>
* limitations under the License.
*/
-/**
- *
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
-
+#ifndef _WIN32
#include <unistd.h>
+#endif
+
+#include <config.h>
#include <stdio.h>
#include <string.h>
-#include <strings.h>
#include <ctype.h>
#include <stdarg.h>
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_URIAuthority.h>
-
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_SafeMemory.h>
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
-
+#ifndef _WIN32
#include <unistd.h>
+#include <strings.h>
+#endif
+
+#include <config.h>
#include <stdio.h>
#include <string.h>
-#include <strings.h>
#include <ctype.h>
#include <stdarg.h>
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_URIPath.h>
-
#include <parc/algol/parc_URISegment.h>
#include <parc/algol/parc_ArrayList.h>
#include <parc/algol/parc_Memory.h>
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
-
+#ifndef _WIN32
#include <unistd.h>
+#endif
+
+#include <config.h>
#include <stdio.h>
#include <string.h>
-#include <strings.h>
#include <ctype.h>
#include <stdarg.h>
-
+#include <parc/assert/parc_Assert.h>
#include <parc/algol/parc_URISegment.h>
-
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Object.h>
}
PARCURISegment *
-parcURISegment_Create(size_t length, const unsigned char segment[length])
+parcURISegment_Create(size_t length, const unsigned char *segment)
{
PARCURISegment *result = NULL;
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, ...) \\r
+ parcLog_PrintError(M,##__VA_ARGS__); \\r
+ assert(((alignment & (~alignment + 1)) == alignment) \\r
+ ? (((uintptr_t)address) % alignment) == 0 ? 1 : 0 \\r
: 0);
#endif
* limitations under the License.
*/
-/**
- */
+#ifndef _WIN32
+#include <unistd.h>
+#endif
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
-
#include <parc/assert/parc_Assert.h>
-
#include <parc/concurrent/parc_Notifier.h>
#include <parc/algol/parc_Object.h>
-#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
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) {
}
}
perror("fcntl error");
+#endif
+
return false;
}
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;
// we missed some notifications, so re-signal ourself
parcNotifier_Notify(notifier);
}
-}
+}
\ No newline at end of file
* @endcode
*/
void parcNotifier_StartEvents(PARCNotifier *notifier);
+
#endif // libparc_parc_Notifier_h
*
*/
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
-#include <unistd.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Object.h>
#include <parc/assert/parc_Assert.h>
-
#include <parc/concurrent/parc_RingBuffer_1x1.h>
-#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)
#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
* limitations under the License.
*/
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
-/**
- */
#include <config.h>
-#include <sys/time.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_DisplayIndented.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Time.h>
-
#include <parc/concurrent/parc_ScheduledTask.h>
#include <parc/concurrent/parc_FutureTask.h>
parcSortedList_Notify(pool->workQueue);
} else {
- parcSortedList_WaitFor(pool->workQueue, executionDelay);
+ parcSortedList_WaitFor(pool->workQueue, (const unsigned long)executionDelay);
}
} else {
parcSortedList_Wait(pool->workQueue);
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
} 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;
/* CPU Cache line size */
#define LEVEL1_DCACHE_LINESIZE @LEVEL1_DCACHE_LINESIZE@
+#ifndef _WIN32
#define _GNU_SOURCE
+#else
+#include <parc/windows/parc_Utils.h>
+#endif
#define HAVE_REALLOC @HAVE_REALLOC@
\ No newline at end of file
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
+#ifndef _WIN32
#include <sys/time.h>
+#endif
+
+#include <config.h>
#include <inttypes.h>
#if __APPLE__
#ifndef libparc_parc_TimingLinux_h
#define libparc_parc_TimingLinux_h
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
+
#include <stdint.h>
#include <time.h>
-#include <sys/time.h>
#ifdef PARCTIMING_GENERIC
* limitations under the License.
*/
-/**
- */
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
+
#include <config.h>
#include <stdio.h>
-#include <sys/time.h>
#include <parc/assert/parc_Assert.h>
-
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Memory.h>
}
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);
}
bool
-parcLog_Warning(PARCLog *logger, const char *format, ...)
+parcLog_Warning(PARCLog *logger, const char *restrict format, ...)
{
va_list ap;
va_start(ap, format);
}
bool
-parcLog_Info(PARCLog *logger, const char *format, ...)
+parcLog_Info(PARCLog *logger, const char *restrict format, ...)
{
va_list ap;
va_start(ap, format);
}
bool
-parcLog_Notice(PARCLog *logger, const char *format, ...)
+parcLog_Notice(PARCLog *logger, const char *restrict format, ...)
{
va_list ap;
va_start(ap, format);
}
bool
-parcLog_Debug(PARCLog *logger, const char *format, ...)
+parcLog_Debug(PARCLog *logger, const char *restrict format, ...)
{
bool result = false;
}
bool
-parcLog_Error(PARCLog *logger, const char *format, ...)
+parcLog_Error(PARCLog *logger, const char *restrict format, ...)
{
va_list ap;
va_start(ap, format);
}
bool
-parcLog_Critical(PARCLog *logger, const char *format, ...)
+parcLog_Critical(PARCLog *logger, const char *restrict format, ...)
{
va_list ap;
va_start(ap, format);
}
bool
-parcLog_Alert(PARCLog *logger, const char *format, ...)
+parcLog_Alert(PARCLog *logger, const char *restrict format, ...)
{
va_list ap;
va_start(ap, format);
}
bool
-parcLog_Emergency(PARCLog *logger, const char *format, ...)
+parcLog_Emergency(PARCLog *logger, const char *restrict format, ...)
{
va_list ap;
va_start(ap, format);
#ifndef PARC_Library_parc_LogEntry_h
#define PARC_Library_parc_LogEntry_h
-#include <stdlib.h>
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
+#include <stdlib.h>
#include <parc/algol/parc_Buffer.h>
-#include <sys/time.h>
+
struct PARCLogEntry;
typedef struct PARCLogEntry PARCLogEntry;
PARCLogLevel result = PARCLogLevel_All;
for (size_t i = 0; levelToString[i] != NULL; i++) {
if (strcasecmp(levelAsString, levelToString[i]) == 0) {
- result = i;
+ result = (PARCLogLevel)i;
}
}
* limitations under the License.
*/
-/**
- */
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
#include <config.h>
#include <inttypes.h>
-#include <unistd.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_OutputStream.h>
*/
__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]];
* 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);
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;
}
}
default:
parcTrapIllegalValue(suite, "Unknown crypto suite: %d", suite);
+ return -1;
}
}
return PARCCryptoSuite_NULL_CRC32C;
default:
parcTrapIllegalValue(suite, "Unknown signing algorithm suite: %d", signAlgo);
+ return PARCSigningAlgorithm_UNKNOWN;
}
}
default:
parcTrapIllegalValue(suit, "Unknown crypto suite: %d", suite);
+ return PARCSigningAlgorithm_UNKNOWN;
}
}
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);
* limitations under the License.
*/
-/**
- */
-#include <config.h>
-
-#include <parc/assert/parc_Assert.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+#include <config.h>
#include <sys/stat.h>
-#include <unistd.h>
+#include <parc/assert/parc_Assert.h>
#include <parc/security/parc_Identity.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_DisplayIndented.h>
-
#include <parc/security/parc_Pkcs12KeyStore.h>
#include <parc/security/parc_PublicKeySigner.h>
-
#include <parc/security/parc_IdentityFile.h>
struct parc_identity_file {
default:
parcTrapUnexpectedState("unsupported hash type: %d", hashType);
+ return NULL;
}
}
{
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) {
{
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) {
* limitations under the License.
*/
-/**
- */
+#ifndef _WIN32
+#include <unistd.h>
+#endif
#include <config.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
-#include <unistd.h>
#include <parc/assert/parc_Assert.h>
-
#include <parc/algol/parc_Object.h>
-
#include <parc/security/parc_Security.h>
#include <parc/security/parc_Signer.h>
#include <parc/security/parc_KeyStore.h>
#include <parc/algol/parc_Memory.h>
-
#include <parc/security/parc_Certificate.h>
#include <parc/security/parc_CertificateFactory.h>
#include <parc/security/parc_CertificateType.h>
#include <parc/security/parc_ContainerEncoding.h>
#include <parc/security/parc_KeyType.h>
-
#include <parc/security/parc_Pkcs12KeyStore.h>
#include <openssl/pkcs12.h>
{
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);
// 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,
// 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,
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));
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);
{
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);
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);
* limitations under the License.\r
*/\r
\r
+#ifndef _WIN32\r
+#include <unistd.h>\r
+#endif\r
\r
-/**\r
- */\r
#include <config.h>\r
-\r
#include <stdlib.h>\r
#include <fcntl.h>\r
-#include <unistd.h>\r
\r
#include <parc/algol/parc_Object.h>\r
#include <parc/algol/parc_DisplayIndented.h>\r
#include <parc/algol/parc_Memory.h>\r
-\r
#include <parc/security/parc_SecureRandom.h>\r
\r
struct parc_securerandom {\r
_parcSecureRandom_ReSeed(PARCSecureRandom *random, PARCBuffer *buffer)\r
{\r
size_t length = parcBuffer_Remaining(buffer);\r
- int wrote_bytes = write(random->randomfd, parcBuffer_Overlay(buffer, length), length);\r
+ int wrote_bytes = write(random->randomfd, parcBuffer_Overlay(buffer, length), (long)length);\r
}\r
\r
PARCSecureRandom *\r
parcSecureRandom_NextBytes(PARCSecureRandom *random, PARCBuffer *buffer)\r
{\r
size_t length = parcBuffer_Remaining(buffer);\r
- ssize_t result = read(random->randomfd, parcBuffer_Overlay(buffer, 0), length);\r
+ ssize_t result = read(random->randomfd, parcBuffer_Overlay(buffer, 0), (unsigned int)length);\r
return result;\r
}\r
\r
#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 <openssl/evp.h>
#include <openssl/err.h>
#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
parcAssertTrue(unlockSuccessful, "Unable to unlock the PARC Security framework.");
}
+#ifndef _WIN32
#pragma GCC diagnostic pop
+#endif
\ No newline at end of file
* @endcode
*/
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
#include <config.h>
#include <stdio.h>
#include <fcntl.h>
-#include <unistd.h>
#include <string.h>
#include <limits.h>
-#include <unistd.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
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 *
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;
} else if (other == NULL) {
result = 1;
} else {
- result = instance->value - other->value;
+ result = (int)(instance->value - other->value);
}
return result;
} 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;
}
}
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;
--- /dev/null
+/* $NetBSD: getopt.c,v 1.16 1999/12/02 13:15:56 kleink Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1987, 1993, 1994, 1995\r
+ * The Regents of the University of California. All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the names of the copyright holders nor the names of its\r
+ * contributors may be used to endorse or promote products derived from\r
+ * this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS \r
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE\r
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#if 0\r
+static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";\r
+#endif\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#define __P(x) x\r
+#define _DIAGASSERT(x) assert(x)\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(getopt,_getopt);\r
+#endif\r
+\r
+\r
+int opterr = 1, /* if error message should be printed */\r
+ optind = 1, /* index into parent argv vector */\r
+ optopt, /* character checked for validity */\r
+ optreset; /* reset getopt */\r
+char *optarg; /* argument associated with option */\r
+\r
+static char * _progname __P((char *));\r
+int getopt_internal __P((int, char * const *, const char *));\r
+\r
+static char *\r
+_progname(nargv0)\r
+ char * nargv0;\r
+{\r
+ char * tmp;\r
+\r
+ _DIAGASSERT(nargv0 != NULL);\r
+\r
+ tmp = strrchr(nargv0, '/');\r
+ if (tmp)\r
+ tmp++;\r
+ else\r
+ tmp = nargv0;\r
+ return(tmp);\r
+}\r
+\r
+#define BADCH (int)'?'\r
+#define BADARG (int)':'\r
+#define EMSG ""\r
+\r
+/*\r
+ * getopt --\r
+ * Parse argc/argv argument vector.\r
+ */\r
+int\r
+getopt(nargc, nargv, ostr)\r
+ int nargc;\r
+ char * const nargv[];\r
+ const char *ostr;\r
+{\r
+ static char *__progname = 0;\r
+ static char *place = EMSG; /* option letter processing */\r
+ char *oli; /* option letter list index */\r
+ __progname = __progname?__progname:_progname(*nargv);\r
+\r
+ _DIAGASSERT(nargv != NULL);\r
+ _DIAGASSERT(ostr != NULL);\r
+\r
+ if (optreset || !*place) { /* update scanning pointer */\r
+ optreset = 0;\r
+ if (optind >= nargc || *(place = nargv[optind]) != '-') {\r
+ place = EMSG;\r
+ return (-1);\r
+ }\r
+ if (place[1] && *++place == '-' /* found "--" */\r
+ && place[1] == '\0') {\r
+ ++optind;\r
+ place = EMSG;\r
+ return (-1);\r
+ }\r
+ } /* option letter okay? */\r
+ if ((optopt = (int)*place++) == (int)':' ||\r
+ !(oli = strchr(ostr, optopt))) {\r
+ /*\r
+ * if the user didn't specify '-' as an option,\r
+ * assume it means -1.\r
+ */\r
+ if (optopt == (int)'-')\r
+ return (-1);\r
+ if (!*place)\r
+ ++optind;\r
+ if (opterr && *ostr != ':')\r
+ (void)fprintf(stderr,\r
+ "%s: illegal option -- %c\n", __progname, optopt);\r
+ return (BADCH);\r
+ }\r
+ if (*++oli != ':') { /* don't need argument */\r
+ optarg = NULL;\r
+ if (!*place)\r
+ ++optind;\r
+ }\r
+ else { /* need an argument */\r
+ if (*place) /* no white space */\r
+ optarg = place;\r
+ else if (nargc <= ++optind) { /* no arg */\r
+ place = EMSG;\r
+ if (*ostr == ':')\r
+ return (BADARG);\r
+ if (opterr)\r
+ (void)fprintf(stderr,\r
+ "%s: option requires an argument -- %c\n",\r
+ __progname, optopt);\r
+ return (BADCH);\r
+ }\r
+ else /* white space */\r
+ optarg = nargv[optind];\r
+ place = EMSG;\r
+ ++optind;\r
+ }\r
+ return (optopt); /* dump back option letter */\r
+}\r
+\r
--- /dev/null
+#ifndef __GETOPT_H__\r
+#define __GETOPT_H__\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+extern int opterr; /* if error message should be printed */\r
+extern int optind; /* index into parent argv vector */\r
+extern int optopt; /* character checked for validity */\r
+extern int optreset; /* reset getopt */\r
+extern char *optarg; /* argument associated with option */\r
+\r
+struct option\r
+{\r
+ const char *name;\r
+ int has_arg;\r
+ int *flag;\r
+ int val;\r
+};\r
+\r
+#define no_argument 0\r
+#define required_argument 1\r
+#define optional_argument 2\r
+\r
+int getopt(int, char**, const char*);\r
+int getopt_long(int, char**, const char*, const struct option*, int*);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* __GETOPT_H__ */\r
--- /dev/null
+\r
+/*\r
+ * Copyright (c) 1987, 1993, 1994, 1996\r
+ * The Regents of the University of California. All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the names of the copyright holders nor the names of its\r
+ * contributors may be used to endorse or promote products derived from\r
+ * this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS \r
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE\r
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include "getopt.h"\r
+\r
+extern int opterr; /* if error message should be printed */\r
+extern int optind; /* index into parent argv vector */\r
+extern int optopt; /* character checked for validity */\r
+extern int optreset; /* reset getopt */\r
+extern char *optarg; /* argument associated with option */\r
+\r
+#define __P(x) x\r
+#define _DIAGASSERT(x) assert(x)\r
+\r
+static char * __progname __P((char *));\r
+int getopt_internal __P((int, char * const *, const char *));\r
+\r
+static char *\r
+__progname(nargv0)\r
+ char * nargv0;\r
+{\r
+ char * tmp;\r
+\r
+ _DIAGASSERT(nargv0 != NULL);\r
+\r
+ tmp = strrchr(nargv0, '/');\r
+ if (tmp)\r
+ tmp++;\r
+ else\r
+ tmp = nargv0;\r
+ return(tmp);\r
+}\r
+\r
+#define BADCH (int)'?'\r
+#define BADARG (int)':'\r
+#define EMSG ""\r
+\r
+/*\r
+ * getopt --\r
+ * Parse argc/argv argument vector.\r
+ */\r
+int\r
+getopt_internal(nargc, nargv, ostr)\r
+ int nargc;\r
+ char * const *nargv;\r
+ const char *ostr;\r
+{\r
+ static char *place = EMSG; /* option letter processing */\r
+ char *oli; /* option letter list index */\r
+\r
+ _DIAGASSERT(nargv != NULL);\r
+ _DIAGASSERT(ostr != NULL);\r
+\r
+ if (optreset || !*place) { /* update scanning pointer */\r
+ optreset = 0;\r
+ if (optind >= nargc || *(place = nargv[optind]) != '-') {\r
+ place = EMSG;\r
+ return (-1);\r
+ }\r
+ if (place[1] && *++place == '-') { /* found "--" */\r
+ /* ++optind; */\r
+ place = EMSG;\r
+ return (-2);\r
+ }\r
+ } /* option letter okay? */\r
+ if ((optopt = (int)*place++) == (int)':' ||\r
+ !(oli = strchr(ostr, optopt))) {\r
+ /*\r
+ * if the user didn't specify '-' as an option,\r
+ * assume it means -1.\r
+ */\r
+ if (optopt == (int)'-')\r
+ return (-1);\r
+ if (!*place)\r
+ ++optind;\r
+ if (opterr && *ostr != ':')\r
+ (void)fprintf(stderr,\r
+ "%s: illegal option -- %c\n", __progname(nargv[0]), optopt);\r
+ return (BADCH);\r
+ }\r
+ if (*++oli != ':') { /* don't need argument */\r
+ optarg = NULL;\r
+ if (!*place)\r
+ ++optind;\r
+ } else { /* need an argument */\r
+ if (*place) /* no white space */\r
+ optarg = place;\r
+ else if (nargc <= ++optind) { /* no arg */\r
+ place = EMSG;\r
+ if ((opterr) && (*ostr != ':'))\r
+ (void)fprintf(stderr,\r
+ "%s: option requires an argument -- %c\n",\r
+ __progname(nargv[0]), optopt);\r
+ return (BADARG);\r
+ } else /* white space */\r
+ optarg = nargv[optind];\r
+ place = EMSG;\r
+ ++optind;\r
+ }\r
+ return (optopt); /* dump back option letter */\r
+}\r
+\r
+#if 0\r
+/*\r
+ * getopt --\r
+ * Parse argc/argv argument vector.\r
+ */\r
+int\r
+getopt2(nargc, nargv, ostr)\r
+ int nargc;\r
+ char * const *nargv;\r
+ const char *ostr;\r
+{\r
+ int retval;\r
+\r
+ if ((retval = getopt_internal(nargc, nargv, ostr)) == -2) {\r
+ retval = -1;\r
+ ++optind; \r
+ }\r
+ return(retval);\r
+}\r
+#endif\r
+\r
+/*\r
+ * getopt_long --\r
+ * Parse argc/argv argument vector.\r
+ */\r
+int\r
+getopt_long(nargc, nargv, options, long_options, index)\r
+ int nargc;\r
+ char ** nargv;\r
+ const char * options;\r
+ const struct option * long_options;\r
+ int * index;\r
+{\r
+ int retval;\r
+\r
+ _DIAGASSERT(nargv != NULL);\r
+ _DIAGASSERT(options != NULL);\r
+ _DIAGASSERT(long_options != NULL);\r
+ /* index may be NULL */\r
+\r
+ if ((retval = getopt_internal(nargc, nargv, options)) == -2) {\r
+ char *current_argv = nargv[optind++] + 2, *has_equal;\r
+ int i, current_argv_len, match = -1;\r
+\r
+ if (*current_argv == '\0') {\r
+ return(-1);\r
+ }\r
+ if ((has_equal = strchr(current_argv, '=')) != NULL) {\r
+ current_argv_len = (int)(has_equal - current_argv);\r
+ has_equal++;\r
+ } else\r
+ current_argv_len = (int)strlen(current_argv);\r
+\r
+ for (i = 0; long_options[i].name; i++) { \r
+ if (strncmp(current_argv, long_options[i].name, current_argv_len))\r
+ continue;\r
+\r
+ if (strlen(long_options[i].name) == (unsigned)current_argv_len) { \r
+ match = i;\r
+ break;\r
+ }\r
+ if (match == -1)\r
+ match = i;\r
+ }\r
+ if (match != -1) {\r
+ if (long_options[match].has_arg == required_argument ||\r
+ long_options[match].has_arg == optional_argument) {\r
+ if (has_equal)\r
+ optarg = has_equal;\r
+ else\r
+ optarg = nargv[optind++];\r
+ }\r
+ if ((long_options[match].has_arg == required_argument)\r
+ && (optarg == NULL)) {\r
+ /*\r
+ * Missing argument, leading :\r
+ * indicates no error should be generated\r
+ */\r
+ if ((opterr) && (*options != ':'))\r
+ (void)fprintf(stderr,\r
+ "%s: option requires an argument -- %s\n",\r
+ __progname(nargv[0]), current_argv);\r
+ return (BADARG);\r
+ }\r
+ } else { /* No matching argument */\r
+ if ((opterr) && (*options != ':'))\r
+ (void)fprintf(stderr,\r
+ "%s: illegal option -- %s\n", __progname(nargv[0]), current_argv);\r
+ return (BADCH);\r
+ }\r
+ if (long_options[match].flag) {\r
+ *long_options[match].flag = long_options[match].val;\r
+ retval = 0;\r
+ } else \r
+ retval = long_options[match].val;\r
+ if (index)\r
+ *index = match;\r
+ }\r
+ return(retval);\r
+}\r
--- /dev/null
+\r
+/*\r
+ * Copyright (c) 2019 Cisco and/or its affiliates.\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at:\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include <parc/windows/parc_Utils.h>\r
+#include <Windows.h>\r
+#include <stdint.h>\r
+#include <stdio.h>\r
+#ifndef _vscprintf\r
+/* For some reason, MSVC fails to honour this #ifndef. */\r
+/* Hence function renamed to _vscprintf_so(). */\r
+int _vscprintf_so(const char *format, va_list pargs)\r
+{\r
+ int retval;\r
+ va_list argcopy;\r
+ va_copy(argcopy, pargs);\r
+ retval = vsnprintf(NULL, 0, format, argcopy);\r
+ va_end(argcopy);\r
+ return retval;\r
+}\r
+#endif // _vscprintf\r
+\r
+#ifndef vasprintf\r
+int vasprintf(char **strp, const char *fmt, va_list ap)\r
+{\r
+ int len = _vscprintf_so(fmt, ap);\r
+ if (len == -1)\r
+ return -1;\r
+ char *str = malloc((size_t)len + 1);\r
+ if (!str)\r
+ return -1;\r
+ int r = vsnprintf(str, len + 1, fmt, ap); /* "secure" version of vsprintf */\r
+ if (r == -1)\r
+ return free(str), -1;\r
+ *strp = str;\r
+ return r;\r
+}\r
+#endif // vasprintf\r
+\r
+#ifndef dprintf\r
+int dprintf(int fd, char *fmt, ...) {\r
+ va_list ap;\r
+ FILE *f = _fdopen( fd, "rw" );\r
+ int rc;\r
+\r
+ va_start(ap, &fmt);\r
+ rc = vfprintf(f, fmt, ap);\r
+ fclose(f);\r
+ va_end(ap);\r
+ return rc;\r
+}\r
+#endif\r
+\r
+#ifndef asprintf\r
+int asprintf(char *strp[], const char *fmt, ...)\r
+{\r
+ va_list ap;\r
+ va_start(ap, fmt);\r
+ int r = vasprintf(strp, fmt, ap);\r
+ va_end(ap);\r
+ return r;\r
+}\r
+#endif // asprintf\r
+\r
+\r
+int gettimeofday(struct timeval * tp, struct timezone * tzp)\r
+{\r
+ // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's\r
+ // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)\r
+ // until 00:00:00 January 1, 1970\r
+ static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);\r
+\r
+ SYSTEMTIME system_time;\r
+ FILETIME file_time;\r
+ uint64_t time;\r
+\r
+ GetSystemTime( &system_time );\r
+ SystemTimeToFileTime( &system_time, &file_time );\r
+ time = ((uint64_t)file_time.dwLowDateTime ) ;\r
+ time += ((uint64_t)file_time.dwHighDateTime) << 32;\r
+\r
+ tp->tv_sec = (long) ((time - EPOCH) / 10000000L);\r
+ tp->tv_usec = (long) (system_time.wMilliseconds * 1000);\r
+ return 0;\r
+}\r
+\r
+#ifndef strndup\r
+char *strndup(const char *str, size_t chars)\r
+{\r
+ char *buffer;\r
+ int n;\r
+\r
+ buffer = (char *) malloc(chars +1);\r
+ if (buffer)\r
+ {\r
+ for (n = 0; ((n < chars) && (str[n] != 0)) ; n++) buffer[n] = str[n];\r
+ buffer[n] = 0;\r
+ }\r
+\r
+ return buffer;\r
+}\r
+#endif\r
+\r
+\r
+void usleep(__int64 usec)\r
+{\r
+ HANDLE timer;\r
+ LARGE_INTEGER ft;\r
+\r
+ ft.QuadPart = -(10 * usec); // Convert to 100 nanosecond interval, negative value indicates relative time\r
+\r
+ timer = CreateWaitableTimer(NULL, TRUE, NULL);\r
+ SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);\r
+ WaitForSingleObject(timer, INFINITE);\r
+ CloseHandle(timer);\r
+}
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright (c) 2019 Cisco and/or its affiliates.\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at:\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#ifndef PARC_UTILS_H\r
+#define PARC_UTILS_H\r
+#define WIN32_LEAN_AND_MEAN\r
+#define HAVE_STRUCT_TIMESPEC\r
+#include <Windows.h>\r
+#include <stdint.h>\r
+#include <io.h>\r
+#include <stdlib.h>\r
+#include <winsock2.h>\r
+#include <WS2tcpip.h>\r
+#include <parc/windows/getopt.h>\r
+#include <parc/windows/queue.h>\r
+\r
+#ifndef IOVEC\r
+#define IOVEC\r
+struct iovec {\r
+ void* iov_base;\r
+ size_t iov_len;\r
+};\r
+#endif\r
+\r
+typedef uint16_t in_port_t;\r
+\r
+#ifndef SLEEP\r
+#define SLEEP\r
+#define sleep Sleep\r
+#endif\r
+\r
+#ifndef USLEEP\r
+#define USLEEP\r
+void usleep(__int64 usec);\r
+#endif\r
+\r
+#ifndef S_ISDIR\r
+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)\r
+#endif\r
+\r
+#define PARCLibrary_DISABLE_ATOMICS\r
+#include <BaseTsd.h>\r
+typedef SSIZE_T ssize_t;\r
+\r
+#ifndef __ATTRIBUTE__\r
+#define __ATTRIBUTE__\r
+#define __attribute__(A)\r
+#endif\r
+\r
+#ifndef RESTRICT\r
+#define RESTRICT\r
+#define restrict __restrict\r
+#endif\r
+\r
+#ifndef _vscprintf\r
+/* For some reason, MSVC fails to honour this #ifndef. */\r
+/* Hence function renamed to _vscprintf_so(). */\r
+int _vscprintf_so(const char *format, va_list pargs);\r
+#endif // _vscprintf\r
+\r
+#ifndef vasprintf\r
+int vasprintf(char **strp, const char *fmt, va_list ap);\r
+#endif // vasprintf\r
+\r
+#ifndef asprintf\r
+int asprintf(char *strp[], const char *fmt, ...);\r
+#endif // asprintf\r
+\r
+#ifndef GETTIMEOFDAY\r
+#define GETTIMEOFDAY\r
+int gettimeofday(struct timeval * tp, struct timezone * tzp);\r
+#endif\r
+\r
+#ifndef strndup\r
+char *strndup(const char *str, size_t chars);\r
+#endif\r
+\r
+#ifndef dprintf\r
+int dprintf(int fd, char *fmt, ...);\r
+#endif\r
+\r
+#ifndef timersub\r
+#define timersub(a, b, result) \\r
+ do { \\r
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \\r
+ (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \\r
+ if ((result)->tv_usec < 0) { \\r
+ --(result)->tv_sec; \\r
+ (result)->tv_usec += 1000000; \\r
+ } \\r
+ } while (0)\r
+#endif // timersub\r
+\r
+#ifndef dup\r
+#define dup _dup\r
+#endif\r
+\r
+#ifndef access\r
+#define access _access\r
+#endif\r
+\r
+#ifndef close\r
+#define close _close\r
+#endif\r
+\r
+#ifndef write\r
+#define write _write\r
+#endif\r
+\r
+#ifndef open\r
+#define open _open\r
+#endif\r
+\r
+#ifndef unlink\r
+#define unlink _unlink\r
+#endif\r
+\r
+#ifndef read\r
+#define read _read\r
+#endif\r
+\r
+#ifndef strcasecmp\r
+#define strncasecmp _strnicmp\r
+#endif\r
+\r
+#ifndef strcasecmp\r
+\r
+#define strcasecmp _stricmp\r
+#endif\r
+\r
+#ifndef S_ISREG\r
+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)\r
+#endif\r
+#ifndef R_OK\r
+#define R_OK 4 /* Test for read permission. */\r
+#endif\r
+#ifndef W_OK\r
+#define W_OK 2 /* Test for write permission. */\r
+#endif\r
+#ifndef F_OK\r
+#define F_OK 0\r
+#endif\r
+\r
+#ifndef STDIN_FILENO\r
+#define STDIN_FILENO _fileno(stdin)\r
+#endif\r
+\r
+#ifndef STDOUT_FILENO\r
+#define STDOUT_FILENO _fileno(stdout)\r
+#endif\r
+\r
+#ifndef STDERR_FILENO\r
+#define STDERR_FILENO _fileno(stderr)\r
+#endif\r
+\r
+#endif
\ No newline at end of file
--- /dev/null
+/* $OpenBSD: queue.h,v 1.16 2000/09/07 19:47:59 art Exp $ */\r
+/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1991, 1993\r
+ * The Regents of the University of California. All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * @(#)queue.h 8.5 (Berkeley) 8/20/94\r
+ */\r
+\r
+#ifndef SYS_QUEUE_H__\r
+#define SYS_QUEUE_H__\r
+\r
+ /*\r
+ * This file defines five types of data structures: singly-linked lists,\r
+ * lists, simple queues, tail queues, and circular queues.\r
+ *\r
+ *\r
+ * A singly-linked list is headed by a single forward pointer. The elements\r
+ * are singly linked for minimum space and pointer manipulation overhead at\r
+ * the expense of O(n) removal for arbitrary elements. New elements can be\r
+ * added to the list after an existing element or at the head of the list.\r
+ * Elements being removed from the head of the list should use the explicit\r
+ * macro for this purpose for optimum efficiency. A singly-linked list may\r
+ * only be traversed in the forward direction. Singly-linked lists are ideal\r
+ * for applications with large datasets and few or no removals or for\r
+ * implementing a LIFO queue.\r
+ *\r
+ * A list is headed by a single forward pointer (or an array of forward\r
+ * pointers for a hash table header). The elements are doubly linked\r
+ * so that an arbitrary element can be removed without a need to\r
+ * traverse the list. New elements can be added to the list before\r
+ * or after an existing element or at the head of the list. A list\r
+ * may only be traversed in the forward direction.\r
+ *\r
+ * A simple queue is headed by a pair of pointers, one the head of the\r
+ * list and the other to the tail of the list. The elements are singly\r
+ * linked to save space, so elements can only be removed from the\r
+ * head of the list. New elements can be added to the list before or after\r
+ * an existing element, at the head of the list, or at the end of the\r
+ * list. A simple queue may only be traversed in the forward direction.\r
+ *\r
+ * A tail queue is headed by a pair of pointers, one to the head of the\r
+ * list and the other to the tail of the list. The elements are doubly\r
+ * linked so that an arbitrary element can be removed without a need to\r
+ * traverse the list. New elements can be added to the list before or\r
+ * after an existing element, at the head of the list, or at the end of\r
+ * the list. A tail queue may be traversed in either direction.\r
+ *\r
+ * A circle queue is headed by a pair of pointers, one to the head of the\r
+ * list and the other to the tail of the list. The elements are doubly\r
+ * linked so that an arbitrary element can be removed without a need to\r
+ * traverse the list. New elements can be added to the list before or after\r
+ * an existing element, at the head of the list, or at the end of the list.\r
+ * A circle queue may be traversed in either direction, but has a more\r
+ * complex end of list detection.\r
+ *\r
+ * For details on the use of these macros, see the queue(3) manual page.\r
+ */\r
+\r
+ /*\r
+ * Singly-linked List definitions.\r
+ */\r
+#define SLIST_HEAD(name, type) \\r
+struct name { \\r
+ struct type *slh_first; /* first element */ \\r
+}\r
+\r
+#define SLIST_HEAD_INITIALIZER(head) \\r
+ { NULL }\r
+\r
+#ifndef _WIN32\r
+#define SLIST_ENTRY(type) \\r
+struct { \\r
+ struct type *sle_next; /* next element */ \\r
+}\r
+#endif\r
+\r
+ /*\r
+ * Singly-linked List access methods.\r
+ */\r
+#define SLIST_FIRST(head) ((head)->slh_first)\r
+#define SLIST_END(head) NULL\r
+#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))\r
+#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)\r
+\r
+#define SLIST_FOREACH(var, head, field) \\r
+ for((var) = SLIST_FIRST(head); \\r
+ (var) != SLIST_END(head); \\r
+ (var) = SLIST_NEXT(var, field))\r
+\r
+ /*\r
+ * Singly-linked List functions.\r
+ */\r
+#define SLIST_INIT(head) { \\r
+ SLIST_FIRST(head) = SLIST_END(head); \\r
+}\r
+\r
+#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \\r
+ (elm)->field.sle_next = (slistelm)->field.sle_next; \\r
+ (slistelm)->field.sle_next = (elm); \\r
+} while (0)\r
+\r
+#define SLIST_INSERT_HEAD(head, elm, field) do { \\r
+ (elm)->field.sle_next = (head)->slh_first; \\r
+ (head)->slh_first = (elm); \\r
+} while (0)\r
+\r
+#define SLIST_REMOVE_HEAD(head, field) do { \\r
+ (head)->slh_first = (head)->slh_first->field.sle_next; \\r
+} while (0)\r
+\r
+ /*\r
+ * List definitions.\r
+ */\r
+#define LIST_HEAD(name, type) \\r
+struct name { \\r
+ struct type *lh_first; /* first element */ \\r
+}\r
+\r
+#define LIST_HEAD_INITIALIZER(head) \\r
+ { NULL }\r
+\r
+#define LIST_ENTRY(type) \\r
+struct { \\r
+ struct type *le_next; /* next element */ \\r
+ struct type **le_prev; /* address of previous next element */ \\r
+}\r
+\r
+ /*\r
+ * List access methods\r
+ */\r
+#define LIST_FIRST(head) ((head)->lh_first)\r
+#define LIST_END(head) NULL\r
+#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))\r
+#define LIST_NEXT(elm, field) ((elm)->field.le_next)\r
+\r
+#define LIST_FOREACH(var, head, field) \\r
+ for((var) = LIST_FIRST(head); \\r
+ (var)!= LIST_END(head); \\r
+ (var) = LIST_NEXT(var, field))\r
+\r
+ /*\r
+ * List functions.\r
+ */\r
+#define LIST_INIT(head) do { \\r
+ LIST_FIRST(head) = LIST_END(head); \\r
+} while (0)\r
+\r
+#define LIST_INSERT_AFTER(listelm, elm, field) do { \\r
+ if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \\r
+ (listelm)->field.le_next->field.le_prev = \\r
+ &(elm)->field.le_next; \\r
+ (listelm)->field.le_next = (elm); \\r
+ (elm)->field.le_prev = &(listelm)->field.le_next; \\r
+} while (0)\r
+\r
+#define LIST_INSERT_BEFORE(listelm, elm, field) do { \\r
+ (elm)->field.le_prev = (listelm)->field.le_prev; \\r
+ (elm)->field.le_next = (listelm); \\r
+ *(listelm)->field.le_prev = (elm); \\r
+ (listelm)->field.le_prev = &(elm)->field.le_next; \\r
+} while (0)\r
+\r
+#define LIST_INSERT_HEAD(head, elm, field) do { \\r
+ if (((elm)->field.le_next = (head)->lh_first) != NULL) \\r
+ (head)->lh_first->field.le_prev = &(elm)->field.le_next;\\r
+ (head)->lh_first = (elm); \\r
+ (elm)->field.le_prev = &(head)->lh_first; \\r
+} while (0)\r
+\r
+#define LIST_REMOVE(elm, field) do { \\r
+ if ((elm)->field.le_next != NULL) \\r
+ (elm)->field.le_next->field.le_prev = \\r
+ (elm)->field.le_prev; \\r
+ *(elm)->field.le_prev = (elm)->field.le_next; \\r
+} while (0)\r
+\r
+#define LIST_REPLACE(elm, elm2, field) do { \\r
+ if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \\r
+ (elm2)->field.le_next->field.le_prev = \\r
+ &(elm2)->field.le_next; \\r
+ (elm2)->field.le_prev = (elm)->field.le_prev; \\r
+ *(elm2)->field.le_prev = (elm2); \\r
+} while (0)\r
+\r
+ /*\r
+ * Simple queue definitions.\r
+ */\r
+#define SIMPLEQ_HEAD(name, type) \\r
+struct name { \\r
+ struct type *sqh_first; /* first element */ \\r
+ struct type **sqh_last; /* addr of last next element */ \\r
+}\r
+\r
+#define SIMPLEQ_HEAD_INITIALIZER(head) \\r
+ { NULL, &(head).sqh_first }\r
+\r
+#define SIMPLEQ_ENTRY(type) \\r
+struct { \\r
+ struct type *sqe_next; /* next element */ \\r
+}\r
+\r
+ /*\r
+ * Simple queue access methods.\r
+ */\r
+#define SIMPLEQ_FIRST(head) ((head)->sqh_first)\r
+#define SIMPLEQ_END(head) NULL\r
+#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))\r
+#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)\r
+\r
+#define SIMPLEQ_FOREACH(var, head, field) \\r
+ for((var) = SIMPLEQ_FIRST(head); \\r
+ (var) != SIMPLEQ_END(head); \\r
+ (var) = SIMPLEQ_NEXT(var, field))\r
+\r
+ /*\r
+ * Simple queue functions.\r
+ */\r
+#define SIMPLEQ_INIT(head) do { \\r
+ (head)->sqh_first = NULL; \\r
+ (head)->sqh_last = &(head)->sqh_first; \\r
+} while (0)\r
+\r
+#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \\r
+ if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \\r
+ (head)->sqh_last = &(elm)->field.sqe_next; \\r
+ (head)->sqh_first = (elm); \\r
+} while (0)\r
+\r
+#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \\r
+ (elm)->field.sqe_next = NULL; \\r
+ *(head)->sqh_last = (elm); \\r
+ (head)->sqh_last = &(elm)->field.sqe_next; \\r
+} while (0)\r
+\r
+#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \\r
+ if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\\r
+ (head)->sqh_last = &(elm)->field.sqe_next; \\r
+ (listelm)->field.sqe_next = (elm); \\r
+} while (0)\r
+\r
+#define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \\r
+ if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \\r
+ (head)->sqh_last = &(head)->sqh_first; \\r
+} while (0)\r
+\r
+ /*\r
+ * Tail queue definitions.\r
+ */\r
+#define TAILQ_HEAD(name, type) \\r
+struct name { \\r
+ struct type *tqh_first; /* first element */ \\r
+ struct type **tqh_last; /* addr of last next element */ \\r
+}\r
+\r
+#define TAILQ_HEAD_INITIALIZER(head) \\r
+ { NULL, &(head).tqh_first }\r
+\r
+#define TAILQ_ENTRY(type) \\r
+struct { \\r
+ struct type *tqe_next; /* next element */ \\r
+ struct type **tqe_prev; /* address of previous next element */ \\r
+}\r
+\r
+ /*\r
+ * tail queue access methods\r
+ */\r
+#define TAILQ_FIRST(head) ((head)->tqh_first)\r
+#define TAILQ_END(head) NULL\r
+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)\r
+#define TAILQ_LAST(head, headname) \\r
+ (*(((struct headname *)((head)->tqh_last))->tqh_last))\r
+ /* XXX */\r
+#define TAILQ_PREV(elm, headname, field) \\r
+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))\r
+#define TAILQ_EMPTY(head) \\r
+ (TAILQ_FIRST(head) == TAILQ_END(head))\r
+\r
+#define TAILQ_FOREACH(var, head, field) \\r
+ for((var) = TAILQ_FIRST(head); \\r
+ (var) != TAILQ_END(head); \\r
+ (var) = TAILQ_NEXT(var, field))\r
+\r
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \\r
+ for((var) = TAILQ_LAST(head, headname); \\r
+ (var) != TAILQ_END(head); \\r
+ (var) = TAILQ_PREV(var, headname, field))\r
+\r
+/*\r
+ * Tail queue functions.\r
+ */\r
+#define TAILQ_INIT(head) do { \\r
+ (head)->tqh_first = NULL; \\r
+ (head)->tqh_last = &(head)->tqh_first; \\r
+} while (0)\r
+\r
+#define TAILQ_INSERT_HEAD(head, elm, field) do { \\r
+ if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \\r
+ (head)->tqh_first->field.tqe_prev = \\r
+ &(elm)->field.tqe_next; \\r
+ else \\r
+ (head)->tqh_last = &(elm)->field.tqe_next; \\r
+ (head)->tqh_first = (elm); \\r
+ (elm)->field.tqe_prev = &(head)->tqh_first; \\r
+} while (0)\r
+\r
+#define TAILQ_INSERT_TAIL(head, elm, field) do { \\r
+ (elm)->field.tqe_next = NULL; \\r
+ (elm)->field.tqe_prev = (head)->tqh_last; \\r
+ *(head)->tqh_last = (elm); \\r
+ (head)->tqh_last = &(elm)->field.tqe_next; \\r
+} while (0)\r
+\r
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \\r
+ if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\\r
+ (elm)->field.tqe_next->field.tqe_prev = \\r
+ &(elm)->field.tqe_next; \\r
+ else \\r
+ (head)->tqh_last = &(elm)->field.tqe_next; \\r
+ (listelm)->field.tqe_next = (elm); \\r
+ (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \\r
+} while (0)\r
+\r
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \\r
+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \\r
+ (elm)->field.tqe_next = (listelm); \\r
+ *(listelm)->field.tqe_prev = (elm); \\r
+ (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \\r
+} while (0)\r
+\r
+#define TAILQ_REMOVE(head, elm, field) do { \\r
+ if (((elm)->field.tqe_next) != NULL) \\r
+ (elm)->field.tqe_next->field.tqe_prev = \\r
+ (elm)->field.tqe_prev; \\r
+ else \\r
+ (head)->tqh_last = (elm)->field.tqe_prev; \\r
+ *(elm)->field.tqe_prev = (elm)->field.tqe_next; \\r
+} while (0)\r
+\r
+#define TAILQ_REPLACE(head, elm, elm2, field) do { \\r
+ if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \\r
+ (elm2)->field.tqe_next->field.tqe_prev = \\r
+ &(elm2)->field.tqe_next; \\r
+ else \\r
+ (head)->tqh_last = &(elm2)->field.tqe_next; \\r
+ (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \\r
+ *(elm2)->field.tqe_prev = (elm2); \\r
+} while (0)\r
+\r
+ /*\r
+ * Circular queue definitions.\r
+ */\r
+#define CIRCLEQ_HEAD(name, type) \\r
+struct name { \\r
+ struct type *cqh_first; /* first element */ \\r
+ struct type *cqh_last; /* last element */ \\r
+}\r
+\r
+#define CIRCLEQ_HEAD_INITIALIZER(head) \\r
+ { CIRCLEQ_END(&head), CIRCLEQ_END(&head) }\r
+\r
+#define CIRCLEQ_ENTRY(type) \\r
+struct { \\r
+ struct type *cqe_next; /* next element */ \\r
+ struct type *cqe_prev; /* previous element */ \\r
+}\r
+\r
+ /*\r
+ * Circular queue access methods\r
+ */\r
+#define CIRCLEQ_FIRST(head) ((head)->cqh_first)\r
+#define CIRCLEQ_LAST(head) ((head)->cqh_last)\r
+#define CIRCLEQ_END(head) ((void *)(head))\r
+#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)\r
+#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)\r
+#define CIRCLEQ_EMPTY(head) \\r
+ (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))\r
+\r
+#define CIRCLEQ_FOREACH(var, head, field) \\r
+ for((var) = CIRCLEQ_FIRST(head); \\r
+ (var) != CIRCLEQ_END(head); \\r
+ (var) = CIRCLEQ_NEXT(var, field))\r
+\r
+#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \\r
+ for((var) = CIRCLEQ_LAST(head); \\r
+ (var) != CIRCLEQ_END(head); \\r
+ (var) = CIRCLEQ_PREV(var, field))\r
+\r
+ /*\r
+ * Circular queue functions.\r
+ */\r
+#define CIRCLEQ_INIT(head) do { \\r
+ (head)->cqh_first = CIRCLEQ_END(head); \\r
+ (head)->cqh_last = CIRCLEQ_END(head); \\r
+} while (0)\r
+\r
+#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \\r
+ (elm)->field.cqe_next = (listelm)->field.cqe_next; \\r
+ (elm)->field.cqe_prev = (listelm); \\r
+ if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \\r
+ (head)->cqh_last = (elm); \\r
+ else \\r
+ (listelm)->field.cqe_next->field.cqe_prev = (elm); \\r
+ (listelm)->field.cqe_next = (elm); \\r
+} while (0)\r
+\r
+#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \\r
+ (elm)->field.cqe_next = (listelm); \\r
+ (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \\r
+ if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \\r
+ (head)->cqh_first = (elm); \\r
+ else \\r
+ (listelm)->field.cqe_prev->field.cqe_next = (elm); \\r
+ (listelm)->field.cqe_prev = (elm); \\r
+} while (0)\r
+\r
+#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \\r
+ (elm)->field.cqe_next = (head)->cqh_first; \\r
+ (elm)->field.cqe_prev = CIRCLEQ_END(head); \\r
+ if ((head)->cqh_last == CIRCLEQ_END(head)) \\r
+ (head)->cqh_last = (elm); \\r
+ else \\r
+ (head)->cqh_first->field.cqe_prev = (elm); \\r
+ (head)->cqh_first = (elm); \\r
+} while (0)\r
+\r
+#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \\r
+ (elm)->field.cqe_next = CIRCLEQ_END(head); \\r
+ (elm)->field.cqe_prev = (head)->cqh_last; \\r
+ if ((head)->cqh_first == CIRCLEQ_END(head)) \\r
+ (head)->cqh_first = (elm); \\r
+ else \\r
+ (head)->cqh_last->field.cqe_next = (elm); \\r
+ (head)->cqh_last = (elm); \\r
+} while (0)\r
+\r
+#define CIRCLEQ_REMOVE(head, elm, field) do { \\r
+ if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \\r
+ (head)->cqh_last = (elm)->field.cqe_prev; \\r
+ else \\r
+ (elm)->field.cqe_next->field.cqe_prev = \\r
+ (elm)->field.cqe_prev; \\r
+ if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \\r
+ (head)->cqh_first = (elm)->field.cqe_next; \\r
+ else \\r
+ (elm)->field.cqe_prev->field.cqe_next = \\r
+ (elm)->field.cqe_next; \\r
+} while (0)\r
+\r
+#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \\r
+ if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \\r
+ CIRCLEQ_END(head)) \\r
+ (head).cqh_last = (elm2); \\r
+ else \\r
+ (elm2)->field.cqe_next->field.cqe_prev = (elm2); \\r
+ if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \\r
+ CIRCLEQ_END(head)) \\r
+ (head).cqh_first = (elm2); \\r
+ else \\r
+ (elm2)->field.cqe_prev->field.cqe_next = (elm2); \\r
+} while (0)\r
+\r
+#endif /* !SYS_QUEUE_H__ */
\ No newline at end of file