Skip to content

Commit ed4d903

Browse files
committed
Sysctl (OpenBSD): improves error messages
1 parent 299451c commit ed4d903

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/common/impl/sysctl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
const char* ffSysctlGetString(int mib1, int mib2, FFstrbuf* result) {
77
size_t neededLength;
88
if (sysctl((int[]) { mib1, mib2 }, 2, NULL, &neededLength, NULL, 0) != 0 || neededLength == 1) { // neededLength is 1 for empty strings, because of the null terminator
9-
return "sysctlbyname() failed";
9+
return "sysctl() length query failed";
1010
}
1111

1212
ffStrbufEnsureFree(result, (uint32_t) neededLength - 1);
1313

14-
if (sysctl((int[]) { mib1, mib2 }, 2, result->chars + result->length, &neededLength, NULL, 0) == 0) {
15-
result->length += (uint32_t) neededLength - 1;
14+
if (sysctl((int[]) { mib1, mib2 }, 2, result->chars + result->length, &neededLength, NULL, 0) != 0) {
15+
return "sysctl() failed to retrieve string data";
1616
}
1717

18+
result->length += (uint32_t) neededLength - 1;
1819
result->chars[result->length] = '\0';
1920

2021
return NULL;

0 commit comments

Comments
 (0)