MCPcopy Create free account
hub / github.com/ddnet/ddnet / os_version_str

Function os_version_str

src/base/os.cpp:144–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142#endif // !defined(CONF_PLATFORM_ANDROID)
143
144bool os_version_str(char *version, size_t length)
145{
146#if defined(CONF_FAMILY_WINDOWS)
147 const WCHAR *module_path = L"kernel32.dll";
148 DWORD handle;
149 DWORD size = GetFileVersionInfoSizeW(module_path, &handle);
150 if(!size)
151 {
152 return false;
153 }
154 void *data = malloc(size);
155 if(!GetFileVersionInfoW(module_path, handle, size, data))
156 {
157 free(data);
158 return false;
159 }
160 VS_FIXEDFILEINFO *fileinfo;
161 UINT unused;
162 if(!VerQueryValueW(data, L"\\", (void **)&fileinfo, &unused))
163 {
164 free(data);
165 return false;
166 }
167 str_format(version, length, "Windows %hu.%hu.%hu.%hu",
168 HIWORD(fileinfo->dwProductVersionMS),
169 LOWORD(fileinfo->dwProductVersionMS),
170 HIWORD(fileinfo->dwProductVersionLS),
171 LOWORD(fileinfo->dwProductVersionLS));
172 free(data);
173 return true;
174#else
175 struct utsname u;
176 if(uname(&u))
177 {
178 return false;
179 }
180 char extra[128];
181 extra[0] = 0;
182
183 do
184 {
185 IOHANDLE os_release = io_open("/etc/os-release", IOFLAG_READ);
186 char buf[4096];
187 int read;
188 int offset;
189 char *newline;
190 if(!os_release)
191 {
192 break;
193 }
194 read = io_read(os_release, buf, sizeof(buf) - 1);
195 io_close(os_release);
196 buf[read] = 0;
197 if(str_startswith(buf, "PRETTY_NAME="))
198 {
199 offset = 0;
200 }
201 else

Callers 4

InitChecksumMethod · 0.85
mainFunction · 0.85
CEngineMethod · 0.85
TESTFunction · 0.85

Calls 6

str_formatFunction · 0.85
io_openFunction · 0.85
io_readFunction · 0.85
io_closeFunction · 0.85
str_startswithFunction · 0.85
str_findFunction · 0.85

Tested by 1

TESTFunction · 0.68