Mercurial > minori
comparison dep/animia/src/util/osx.cc @ 182:c413e475f496
dep/animia: various stylistic changes
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 04 Dec 2023 13:19:54 -0500 |
parents | e44b7c428d7c |
children | 649786bae914 |
comparison
equal
deleted
inserted
replaced
181:d26cd2c00270 | 182:c413e475f496 |
---|---|
82 if (!CFDictionaryGetValueIfPresent(dictionary, kLSDisplayNameKey, (CFTypeRef*)&rstr) || !rstr) | 82 if (!CFDictionaryGetValueIfPresent(dictionary, kLSDisplayNameKey, (CFTypeRef*)&rstr) || !rstr) |
83 return false; | 83 return false; |
84 str.reset(rstr); | 84 str.reset(rstr); |
85 } | 85 } |
86 | 86 |
87 result.reserve(CFStringGetMaximumSizeForEncoding(CFStringGetLength(str.get()), kCFStringEncodingUTF8) + 1); | 87 result.resize(CFStringGetMaximumSizeForEncoding(CFStringGetLength(str.get()), kCFStringEncodingUTF8) + 1); |
88 | 88 |
89 if (!CFStringGetCString(str.get(), &result.front(), result.length(), result.length())) | 89 if (!CFStringGetCString(str.get(), &result.front(), result.length(), result.length())) |
90 return false; | 90 return false; |
91 | |
92 result.resize(result.find('\0')); | |
91 | 93 |
92 return true; | 94 return true; |
93 } | 95 } |
94 #endif // HAVE_COREFOUNDATION | 96 #endif // HAVE_COREFOUNDATION |
95 | 97 |
96 static bool GetProcessArgs(pid_t pid, std::string& args) { | 98 static bool GetProcessArgs(pid_t pid, std::string& args) { |
97 /* sysctl shouldn't touch these, so we define them as const */ | 99 /* sysctl shouldn't touch these, so we define them as const */ |
98 const int mib[3] = {CTL_KERN, KERN_PROCARGS2, static_cast<int>(pid)}; | 100 const int mib[3] = {CTL_KERN, KERN_PROCARGS2, static_cast<int>(pid)}; |
99 const size_t mib_size = sizeof(mib)/sizeof(*mib); | 101 const size_t mib_size = sizeof(mib)/sizeof(*mib); |
100 | 102 |
101 /* Get the initial size of the array */ | 103 /* Get the initial size of the array |
104 * | |
105 * NOTE: it IS possible for this value to change inbetween calls to sysctl(). | |
106 * Unfortunately, I couldn't care less about handling this. :) | |
107 */ | |
102 size_t size; | 108 size_t size; |
103 { | 109 { |
104 int ret = sysctl((int*)mib, mib_size, nullptr, &size, nullptr, 0); | 110 int ret = sysctl((int*)mib, mib_size, nullptr, &size, nullptr, 0); |
105 if (ret) | 111 if (ret) |
106 return false; | 112 return false; |