2013-05-22 01:45:24 +04:00
|
|
|
#include "PlatformUtils.h"
|
2014-12-11 06:44:39 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
2014-12-12 01:23:45 +03:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
2013-05-22 01:45:24 +04:00
|
|
|
|
2014-02-17 00:13:21 +04:00
|
|
|
std::string PlatformUtils::pathSeparatorChar()
|
|
|
|
{
|
|
|
|
return ":";
|
|
|
|
}
|
|
|
|
|
2013-05-22 01:45:24 +04:00
|
|
|
std::string PlatformUtils::documentsPath()
|
|
|
|
{
|
|
|
|
return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]);
|
|
|
|
}
|
2014-05-17 09:02:44 +04:00
|
|
|
|
2014-11-02 01:06:36 +03:00
|
|
|
std::string PlatformUtils::userConfigPath()
|
|
|
|
{
|
2014-11-05 15:14:14 +03:00
|
|
|
NSError *error;
|
|
|
|
NSURL *appSupportDir = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error];
|
|
|
|
return std::string([[appSupportDir path] UTF8String]) + std::string("/") + PlatformUtils::OPENSCAD_FOLDER_NAME;
|
2014-11-02 01:06:36 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 01:34:57 +03:00
|
|
|
unsigned long PlatformUtils::stackLimit()
|
|
|
|
{
|
2014-11-25 02:29:13 +03:00
|
|
|
struct rlimit limit;
|
|
|
|
|
|
|
|
int ret = getrlimit(RLIMIT_STACK, &limit);
|
|
|
|
if (ret == 0) {
|
|
|
|
if (limit.rlim_cur > STACK_BUFFER_SIZE) {
|
|
|
|
return limit.rlim_cur - STACK_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
if (limit.rlim_max > STACK_BUFFER_SIZE) {
|
|
|
|
return limit.rlim_max - STACK_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return STACK_LIMIT_DEFAULT;
|
2014-11-25 01:34:57 +03:00
|
|
|
}
|
|
|
|
|
2015-03-05 22:20:46 +03:00
|
|
|
std::string PlatformUtils::sysinfo(bool extended)
|
2014-12-09 21:14:43 +03:00
|
|
|
{
|
2014-12-11 06:44:39 +03:00
|
|
|
std::string result;
|
|
|
|
|
|
|
|
result += "Mac OS X ";
|
|
|
|
result += [[[NSProcessInfo processInfo] operatingSystemVersionString] UTF8String];
|
|
|
|
|
|
|
|
int64_t physical_memory;
|
|
|
|
int32_t numcpu;
|
|
|
|
size_t length64 = sizeof(int64_t);
|
|
|
|
size_t length32 = sizeof(int32_t);;
|
|
|
|
|
|
|
|
sysctlbyname("hw.memsize", &physical_memory, &length64, NULL, 0);
|
|
|
|
sysctlbyname("hw.physicalcpu", &numcpu, &length32, NULL, 0);
|
|
|
|
|
2015-03-05 22:20:46 +03:00
|
|
|
size_t modellen = 0;
|
|
|
|
sysctlbyname("hw.model", NULL, &modellen, NULL, 0);
|
|
|
|
if (modellen) {
|
|
|
|
char *model = (char *)malloc(modellen*sizeof(char));
|
|
|
|
sysctlbyname("hw.model", model, &modellen, NULL, 0);
|
|
|
|
result += " ";
|
|
|
|
result += model;
|
|
|
|
free(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extended) {
|
|
|
|
result += " ";
|
|
|
|
result += boost::lexical_cast<std::string>(numcpu);
|
|
|
|
result += " CPU";
|
|
|
|
if (numcpu > 1) result += "s";
|
2014-12-11 06:44:39 +03:00
|
|
|
|
2015-03-05 22:20:46 +03:00
|
|
|
result += " ";
|
|
|
|
result += PlatformUtils::toMemorySizeString(physical_memory, 2);
|
|
|
|
result += " RAM ";
|
|
|
|
}
|
|
|
|
|
2014-12-11 06:44:39 +03:00
|
|
|
return result;
|
2014-12-09 21:14:43 +03:00
|
|
|
}
|
|
|
|
|
2014-05-17 09:02:44 +04:00
|
|
|
void PlatformUtils::ensureStdIO(void) {}
|
|
|
|
|