diff --git a/opennurbs_defines.cpp b/opennurbs_defines.cpp index 92d97fb1..dfc1af6b 100644 --- a/opennurbs_defines.cpp +++ b/opennurbs_defines.cpp @@ -503,7 +503,7 @@ int ON::CloseAllFiles() //fcloseall is not supported on OS X return EOF; #elif defined(ON_COMPILER_GNU) -#error TODO - call gcc fcloseall() + fcloseall(); #else // I can't find an fcloseall() or _fcloseall() in // gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) diff --git a/opennurbs_file_utilities.cpp b/opennurbs_file_utilities.cpp index 4776529d..b790efdc 100644 --- a/opennurbs_file_utilities.cpp +++ b/opennurbs_file_utilities.cpp @@ -2739,7 +2739,7 @@ ON__UINT64 ON_SecondsSinceJanOne1970UTC() __time64_t t = _time64(nullptr); return (ON__UINT64)t; -#elif defined(ON_COMPILER_CLANG) +#elif defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) //__time64_t t = _time64(nullptr); time_t t = time(nullptr); @@ -2779,7 +2779,7 @@ const ON_wString SecondsSinceJanOne1970UTCToString( sec = uct.tm_sec; } -#elif defined(ON_COMPILER_CLANG) +#elif defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) const time_t t = (time_t)seconds_since_epoch; const struct tm* ptr = gmtime( &t ); diff --git a/opennurbs_locale.cpp b/opennurbs_locale.cpp index effb512b..45c46a5b 100644 --- a/opennurbs_locale.cpp +++ b/opennurbs_locale.cpp @@ -1324,7 +1324,7 @@ public: static bool Validate_sprintf_s() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // Test formatted printing char buffer[64] = { 0 }; size_t buffer_capacity = (sizeof(buffer) / sizeof(buffer[0])) - 1; @@ -1343,7 +1343,7 @@ public: static bool Validate_sprintf_l() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) // Test formatted printing char buffer[64] = { 0 }; @@ -1368,7 +1368,7 @@ public: static bool Validate_sprintf_s_l() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) // Test formatted printing char buffer[64] = { 0 }; @@ -1405,7 +1405,7 @@ public: static bool Validate_sscanf_s() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // Test formatted scanning double a = ON_UNSET_VALUE; // Testing C-runtime - do not using ON_String::Scan @@ -1422,7 +1422,7 @@ public: static bool Validate_sscanf_l() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) // Test formatted scanning double a = ON_UNSET_VALUE; @@ -1447,7 +1447,7 @@ public: static bool Validate_sscanf_s_l() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) // Test formatted scanning double a = ON_UNSET_VALUE; @@ -1602,7 +1602,7 @@ bool ON_Locale::SetPeriodAsCRuntimeDecimalPoint() if (prev_type != _DISABLE_PER_THREAD_LOCALE && prev_type >= 0) _configthreadlocale(prev_type); -#elif defined(ON_COMPILER_CLANG) +#elif defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // Apple's Clang compiler const char* s = setlocale(LC_NUMERIC, "C"); rc = (0 != s && 'C' == s[0] && 0 == s[1]); diff --git a/opennurbs_string_format.cpp b/opennurbs_string_format.cpp index bac30138..805be8d7 100644 --- a/opennurbs_string_format.cpp +++ b/opennurbs_string_format.cpp @@ -803,7 +803,7 @@ int ON_String::FormatVargsIntoBuffer( if (0 == buffer || buffer_capacity <= 0) return -1; buffer[0] = 0; -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // CLang modifies args so a copy is required va_list args_copy; va_copy (args_copy, args); @@ -854,7 +854,7 @@ int ON_String::FormatVargsOutputCount( if ( nullptr == format || 0 == format[0] ) return 0; -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // CLang modifies args so a copy is required va_list args_copy; va_copy (args_copy, args); @@ -1075,10 +1075,18 @@ int ON_wString::FormatVargsIntoBuffer( int len = vswprintf(buffer, buffer_capacity, format, args_copy); va_end(args_copy); +#else + +#if defined(ON_COMPILER_GNU) + va_list args_copy; + va_copy (args_copy, args); + int len = vswprintf(buffer, buffer_capacity, format, args_copy); + va_end(args_copy); #else // Using ON_Locale::Ordinal.NumericLocalePtr() insures that a period // will be use for the decimal point in formatted printing. int len = _vswprintf_p_l(buffer, buffer_capacity, format, ON_Locale::Ordinal.NumericLocalePtr(), args); +#endif #endif if (((size_t)len) >= buffer_capacity) len = -1; @@ -1214,9 +1222,38 @@ int ON_wString::FormatVargsOutputCount( break; } return -1; +#else +#if defined(ON_COMPILER_GNU) + wchar_t stack_buffer[1024]; + ON_wStringBuffer buffer(stack_buffer, sizeof(stack_buffer) / sizeof(stack_buffer[0])); + size_t buffer_capacity = buffer.m_buffer_capacity; + for(;;) + { + va_list args_copy; + va_copy(args_copy, args); + + const int formatted_string_count = vswprintf(buffer.m_buffer, buffer.m_buffer_capacity, format, args_copy); + va_end(args_copy); + if (formatted_string_count >= 0) + { + // formatted_string_count = number of wchar_t elements not including null terminator + return formatted_string_count; + } + if ( buffer_capacity >= 1024*16*16*16 ) + break; + buffer_capacity *= 16; + if (false == buffer.GrowBuffer(buffer_capacity)) + break; + if (nullptr == buffer.m_buffer) + break; + if (buffer_capacity < buffer.m_buffer_capacity) + break; + } + return -1; #else // Using ON_Locale::Ordinal.NumericLocalePtr() insures that a period // will be use for the decimal point in formatted printing. return _vscwprintf_p_l(format, ON_Locale::Ordinal.NumericLocalePtr(), args); #endif +#endif } diff --git a/opennurbs_string_scan.cpp b/opennurbs_string_scan.cpp index 652120de..539d95d4 100644 --- a/opennurbs_string_scan.cpp +++ b/opennurbs_string_scan.cpp @@ -85,7 +85,7 @@ int ON_String::ScanBufferVargs( va_list args ) { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_RUNTIME_LINUX) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) if (nullptr == buffer || nullptr == format) return -1; @@ -148,7 +148,7 @@ int ON_wString::ScanBufferVargs( va_list args ) { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_RUNTIME_LINUX) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) if (nullptr == buffer || nullptr == format) return -1; @@ -397,7 +397,7 @@ const char* ON_String::ToNumber( local_buffer[local_buffer_count++] = 0; double x = value_on_failure; -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_RUNTIME_LINUX) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) if (1 == sscanf(local_buffer, "%lg", &x)) { @@ -639,7 +639,7 @@ const wchar_t* ON_wString::ToNumber( local_buffer[local_buffer_count++] = 0; double x = value_on_failure; -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_RUNTIME_LINUX) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) if (1 == sscanf(local_buffer, "%lg", &x)) { diff --git a/opennurbs_subd_heap.cpp b/opennurbs_subd_heap.cpp index 47d31a1a..00856d06 100644 --- a/opennurbs_subd_heap.cpp +++ b/opennurbs_subd_heap.cpp @@ -660,7 +660,7 @@ bool ON_SubD_FixedSizeHeap::ReturnPtrArray( m_p_index -= capacity; return true; } - return ON_SUBD_RETURN_ERROR(nullptr); + return ON_SUBD_RETURN_ERROR(false); } @@ -1388,4 +1388,3 @@ void ON_SubDHeap::ReturnArray( } return; } - diff --git a/opennurbs_system.h b/opennurbs_system.h index e2ff70a5..b9e4951a 100644 --- a/opennurbs_system.h +++ b/opennurbs_system.h @@ -540,7 +540,7 @@ typedef ON__UINT32 wchar_t; #pragma ON_PRAGMA_WARNING_AFTER_DIRTY_INCLUDE #pragma ON_PRAGMA_WARNING_BEFORE_DIRTY_INCLUDE -#if defined(ON_RUNTIME_ANDROID) +#if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) #include "android_uuid/uuid.h" #else #include diff --git a/opennurbs_uuid.cpp b/opennurbs_uuid.cpp index 44f75a65..cb5bced4 100644 --- a/opennurbs_uuid.cpp +++ b/opennurbs_uuid.cpp @@ -15,7 +15,9 @@ */ #include "opennurbs.h" - +#if defined(ON_RUNTIME_LINUX) +#include "android_uuid/uuid.h" +#endif #if !defined(ON_COMPILING_OPENNURBS) // This check is included in all opennurbs source .c and .cpp files to insure // ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled. @@ -221,6 +223,12 @@ bool ON_CreateUuid( ON_UUID& new_uuid ) return true; #else + +#if defined(ON_RUNTIME_LINUX) + uuid_generate((unsigned char*)&new_uuid); + return true; +#else + // You must supply a way to create unique ids or you // will not be able to write 3dm files. #error TODO - generate uuid @@ -228,6 +236,7 @@ bool ON_CreateUuid( ON_UUID& new_uuid ) return false; #endif +#endif #endif }