Skip to content

Commit

Permalink
[operating_system] added 'is-windows-server' function to the namespace.
Browse files Browse the repository at this point in the history
Adding of this function required for checking at script available to use
some of function on Windows Server platform, for example
'cygpath::get-dos-path'.
Structure OperatingSystem was hidden. Added 'operating_system_init',
'operating_system_is_windows_server' and 'platform_is_windows_server'
functions.

[tests.xml] added calls of functions from 'operating-system' and
'platform' name spaces.

[ant4c.net.framework.module] renamed source files of the module.
Added hash sums of the nuget package to the SHA3-224SUMS and MD5SUMS
files.

[CMakeLists] added workaround approach to use pugixml at some
environment ( OpenBSD 6.8 for example ) where find_package may create
issue for using direct source of the packages in case package from
system repository was not installed ( pkg_add libpugixml ).

More details can be found at the issue discussion
zeux/pugixml#390
and pull request
zeux/pugixml#391
  • Loading branch information
TheVice committed Feb 16, 2021
1 parent cc64949 commit 94a7ead
Show file tree
Hide file tree
Showing 16 changed files with 10,254 additions and 10,000 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ant4c (YYYY.MM)
of inputs with huge (more than 32 KB) length.
* At implementation of 'SHA3/Keccak' algorithm do not loading whole range
of data while calculating hash sum of first one.
* Added 'operating-system::is-windows-server' and
'platform::is-windows-server' functions.

-- TheVice <TheVice> DAY, DD MM YYYY HH:MM:SS +/-..

Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ if(DEFINED PROGRAM_VERSION)
endif()

if(NOT MSVC)
if(("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}") AND (NOT MINGW))
if(NOT MINGW)
target_compile_options(ant4c PRIVATE "-fPIE")
target_compile_options(ant4c PRIVATE "-fPIC")
target_compile_options(ant4c_app PRIVATE "-fPIE")
set_target_properties(ant4c_app PROPERTIES LINK_FLAGS "-pie -Wl,-z,now")
endif()
Expand Down Expand Up @@ -219,7 +220,11 @@ list(APPEND SOURCES_OF_TESTS
set(pugixml_FOUND 0)
set(GTest_FOUND False)

find_package(pugixml)
if((DEFINED ENV{pugixml_issues_390}) OR (DEFINED pugixml_issues_390))# https://github.com/zeux/pugixml/issues/390
else()
find_package(pugixml)
endif()

find_package(GTest)

if((1 EQUAL ${pugixml_FOUND}) AND ${GTest_FOUND})
Expand Down
1 change: 1 addition & 0 deletions MD5SUMS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ c4a1d31ca9b1715d80a96a5662e5ae86 ant4c-2020.09-1.el7.x86_64.rpm
4628bc67eb8993fdd157b67e27713325 ant4c-2020.09-1.fc33.x86_64.rpm
e48b65d5086d1e3ef9c4f73524254555 ant4c-2020.09-1.x86_64.rpm
cd6f7389d91aaadb4d0f2219ea090024 ant4c.dns.zip
e7490634d2aec451d7600ceab14505ed ant4c.net.framework.module.2020.9.0.nupkg
bf03f07cd71a15c7037d53bef0b315b8 ant4c.regex.zip
296e39f5d916d85b961ea9049ad48a5b libant4c-2020.09_freebsd.tar.bz2
935aca6f8a2bef6cafc7e1698b375948 libant4c-2020.09_openbsd.tar.bz2
Expand Down
1 change: 1 addition & 0 deletions SHA3-224SUMS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ebaf46282f2f6f186027c53879c581c42cc93f476d2e1ac4648a1c7a ant4c-2020.09-1.el8.x8
12b2156cafe01cde2006a76bc652c154c9f699acad911ef217c96c67 ant4c-2020.09-1.fc33.x86_64.rpm
e526c3a1d9577ae0311e6d74858514bf9c5b77c8cb958d06396df64e ant4c-2020.09-1.x86_64.rpm
f688c4c3c0a7c98ecd1f49e3b9e8f52f7a92898719a28f0294c57795 ant4c.dns.zip
091f58f5debc7285281233a97b3a89cd95c4882559b51e3b8ef1693c ant4c.net.framework.module.2020.9.0.nupkg
aa1b0f029777a00f07223ffc96735324604ad17189d7c766657fa73d ant4c.regex.zip
d29d3fdb154efb2bba41a1fc1814b84109514520bb91503d179c2e9c libant4c-2020.09_freebsd.tar.bz2
c5c9e9edaee0726f1e9155a9401f42fbf5178d599e18dcaaca52b322 libant4c-2020.09_openbsd.tar.bz2
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ant4c.net.framework.module.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ uint8_t evaluate_function(const uint8_t* function,

case metahost_runtime_:
if (1 != values_count ||
!metahost_runtime(values[0], values_lengths[0], &values_count) ||
!metahost_runtime(values[0], (uint8_t)values_lengths[0], &values_count) ||
!bool_to_string(values_count, &output_data))
{
return 0;
Expand Down
6 changes: 3 additions & 3 deletions ant4c.net.framework.module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ if(MSVC)

add_library(ant4c.net.framework.module.clr
"${CMAKE_SOURCE_DIR}/ant4c.net.framework.module.AssemblyInfo.cs"
"${CMAKE_SOURCE_DIR}/CustomAppDomainManager.cs"
"${CMAKE_SOURCE_DIR}/IFrameworkNamespace.cs"
"${CMAKE_SOURCE_DIR}/VersionDetector.cs")
"${CMAKE_SOURCE_DIR}/ant4c.net.framework.module.CustomAppDomainManager.cs"
"${CMAKE_SOURCE_DIR}/ant4c.net.framework.module.IFrameworkNamespace.cs"
"${CMAKE_SOURCE_DIR}/ant4c.net.framework.module.VersionDetector.cs")

add_library(ant4c.net.framework.module SHARED
"${CMAKE_SOURCE_DIR}/ant4c.net.framework.module.c"
Expand Down
87 changes: 48 additions & 39 deletions environment.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 - 2020 https://github.com/TheVice/
* Copyright (c) 2019 - 2021 https://github.com/TheVice/
*
*/

Expand All @@ -12,14 +12,14 @@
#include "operating_system.h"
#include "range.h"
#include "text_encoding.h"
#include "version.h"

#include <string.h>

#if !defined(__STDC_SEC_API__)
#define __STDC_SEC_API__ ((__STDC_LIB_EXT1__) || (__STDC_SECURE_LIB__) || (__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_SECURE_LIB__))
#endif

static struct OperatingSystem operating_system;
static uint8_t is_data_of_operating_system_filled = 0;

#define ENVIRONMENT_UNKNOWN_SPECIAL_FOLDER (CDBurning + 1)
Expand Down Expand Up @@ -528,7 +528,6 @@ uint8_t environment_get_folder_path(enum SpecialFolder folder, struct buffer* pa
#endif
#include <sys/utsname.h>

#include <stdio.h>
#include <stdlib.h>

uint8_t environment_get_folder_path(enum SpecialFolder folder, struct buffer* path)
Expand Down Expand Up @@ -721,10 +720,7 @@ struct Version GetWindowsVersion()
ver.major = 6;
}

/*
IsWindowsXPOrGreater();
IsWindowsServer();
*/
/*IsWindowsXPOrGreater();*/
#else
/*TODO: call VerSetConditionMask, VerifyVersionInfoW via pointers.*/
static const struct Version versions[] = { {10, 0, 0, 0}, {6, 3, 0, 0}, {6, 2, 0, 0}, {6, 1, 0, 0}, {6, 0, 0, 0} };
Expand All @@ -750,41 +746,47 @@ struct Version GetWindowsVersion()
return ver;
}

const struct OperatingSystem* environment_get_operating_system()
static uint8_t operating_system[UINT8_MAX];
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
#else
uint8_t IsWindowsServer()
{
OSVERSIONINFOEXW osvi;
memset(&osvi, 0, sizeof(OSVERSIONINFOEXW));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
osvi.wProductType = VER_NT_WORKSTATION;
DWORDLONG const dwlConditionMask = VerSetConditionMask(0, VER_PRODUCT_TYPE, VER_EQUAL);
/**/
return !VerifyVersionInfoW(&osvi, VER_PRODUCT_TYPE, dwlConditionMask);
}
#endif
const void* environment_get_operating_system()
{
if (!is_data_of_operating_system_filled)
{
operating_system.Platform = Win32;
operating_system.Version = GetWindowsVersion();
#if __STDC_SEC_API__
is_data_of_operating_system_filled = (0 == memcpy_s(operating_system.VersionString, INT8_MAX, Win32NT_str,
Win32NT_str_length));

if (is_data_of_operating_system_filled)
#else
memcpy(operating_system.VersionString, Win32NT_str, Win32NT_str_length);
struct Version ver = GetWindowsVersion();
is_data_of_operating_system_filled = operating_system_init(
Win32, 0 < IsWindowsServer(), &ver, (ptrdiff_t)sizeof(operating_system), operating_system);

is_data_of_operating_system_filled = 1;
#endif
if (!is_data_of_operating_system_filled)
{
uint8_t* str_version = operating_system.VersionString + Win32NT_str_length;
*str_version = ' ';
++str_version;
is_data_of_operating_system_filled = 0 < version_to_byte_array(&operating_system.Version, str_version);
return NULL;
}
}

return &operating_system;
return operating_system;
}

#else

const struct OperatingSystem* environment_get_operating_system()
static uint8_t operating_system[sizeof(struct utsname) + INT8_MAX];

const void* environment_get_operating_system()
{
if (!is_data_of_operating_system_filled)
{
struct Version ver;
struct utsname uname_data;
operating_system.Platform = Unix;

if (-1 == uname(&uname_data))
{
Expand All @@ -793,18 +795,27 @@ const struct OperatingSystem* environment_get_operating_system()

if (!version_parse((const uint8_t*)uname_data.version,
(const uint8_t*)uname_data.version + strlen(uname_data.version),
&operating_system.Version))
&ver))
{
return NULL;
}

sprintf((char* const)operating_system.VersionString, "%s %s %s %s",
uname_data.sysname, uname_data.release,
uname_data.version, uname_data.machine);
is_data_of_operating_system_filled = 1;
const uint8_t* version_string[] =
{
(const uint8_t*)uname_data.sysname, (const uint8_t*)uname_data.release,
(const uint8_t*)uname_data.version, (const uint8_t*)uname_data.machine
};
/**/
is_data_of_operating_system_filled = operating_system_init(
Unix, &ver, version_string, (ptrdiff_t)sizeof(operating_system), operating_system);

if (!is_data_of_operating_system_filled)
{
return NULL;
}
}

return &operating_system;
return operating_system;
}

#endif
Expand Down Expand Up @@ -1072,10 +1083,10 @@ uint8_t environment_is64bit_operating_system()
#else
static const uint8_t* x86_64 = (const uint8_t*)"x86_64";
static const uint8_t* amd64 = (const uint8_t*)"amd64";
const struct OperatingSystem* os = environment_get_operating_system();
return string_contains(os->VersionString, os->VersionString + common_count_bytes_until(os->VersionString, 0),
const uint8_t* version_string = operating_system_to_string(environment_get_operating_system());
return string_contains(version_string, version_string + common_count_bytes_until(version_string, 0),
x86_64, x86_64 + 6) ||
string_contains(os->VersionString, os->VersionString + common_count_bytes_until(os->VersionString, 0),
string_contains(version_string, version_string + common_count_bytes_until(version_string, 0),
amd64, amd64 + 5);
#endif
}
Expand Down Expand Up @@ -1221,10 +1232,8 @@ uint8_t environment_exec_function(uint8_t function, const struct buffer* argumen
return !arguments_count && environment_get_machine_name(output);

case get_operating_system:
{
const struct OperatingSystem* os = environment_get_operating_system();
return !arguments_count && common_append_string_to_buffer(os->VersionString, output);
}
return !arguments_count &&
common_append_string_to_buffer(operating_system_to_string(environment_get_operating_system()), output);

case get_user_name:
return !arguments_count && environment_get_user_name(output);
Expand Down
5 changes: 2 additions & 3 deletions environment.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 - 2020 https://github.com/TheVice/
* Copyright (c) 2019 - 2021 https://github.com/TheVice/
*
*/

Expand All @@ -12,7 +12,6 @@
#include <stdint.h>

struct buffer;
struct OperatingSystem;

static const uint8_t environment_posix_delimiter = ':';
static const uint8_t environment_windows_delimiter = ';';
Expand Down Expand Up @@ -76,7 +75,7 @@ enum SpecialFolder

uint8_t environment_get_folder_path(enum SpecialFolder folder, struct buffer* path);
uint8_t environment_get_machine_name(struct buffer* name);
const struct OperatingSystem* environment_get_operating_system();
const void* environment_get_operating_system();
uint8_t environment_get_user_name(struct buffer* name);
uint8_t environment_get_variable(const uint8_t* variable_name_start, const uint8_t* variable_name_finish,
struct buffer* variable);
Expand Down
16 changes: 16 additions & 0 deletions help.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2720,9 +2720,11 @@ Get integer part from double digital value.
| <<operating_system-get_platform,operating-system::get-platform>> | Get platform of the operation system.
| <<operating_system-get_version,operating-system::get-version>> | Get version of the operation system.
| <<operating_system-to_string,operating-system::to-string>> | Get string representation of the the operation system.
| <<operating_system-is_windows_server,operating-system::is-windows-server>> | Check is specified operation system Windows Server.
| <<platform-get_name,platform::get-name>> | Get name of current platform.
| <<platform-is_unix,platform::is-unix>> | Check is current platform UNIX like.
| <<platform-is_windows,platform::is-windows>> | Check is current platform Windows.
| <<platform-is_windows_server,platform::is-windows-server>> | Check is current platform Windows Server.
|===

[[operating_system-get_platform]]
Expand Down Expand Up @@ -2753,6 +2755,13 @@ Get version of operating system.

Get string representation of operating system.

[[operating_system-is_windows_server]]
==== is-windows-server

*bool* 'operating-system::is-windows-server'(*operating system*)

Return *true* if specified operation system from Windows Server family.

[[platform-get_name]]
==== get-name

Expand All @@ -2774,6 +2783,13 @@ Return *true* if current platform UNIX like.

Return *true* if current platform from Windows family.

[[platform-is_windows_server]]
==== is-windows-server

*bool* 'platform::is-windows-server'()

Return *true* if current platform from Windows Server family.

=== Path unit

.Functions from path unit.
Expand Down
Loading

0 comments on commit 94a7ead

Please sign in to comment.