Skip to content

Commit

Permalink
Fix build for all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
keisisqrl authored and silseva committed Mar 21, 2023
1 parent ff1d03e commit 1f5e5dd
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,27 @@ static char *find_path(int vid, int pid)
}

io_iterator_t devices = IO_OBJECT_NULL;
kern_return_t ret = IOServiceGetMatchingServices(kIOMainPortDefault,
dict, &devices);

kern_return_t ret;

/* MacOS 12.0 deprecates kIOMasterPortDefault for kIOMainPortDefault
* and build breaks on a deprecation warning.
* Use the clang __builtin_available thing to guard the new version
* and change that warning to non-error to prevent breakage.
*/
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

if (__builtin_available(macOS 12.0, *)) {
ret = IOServiceGetMatchingServices(kIOMainPortDefault,
dict, &devices);
} else {
ret = IOServiceGetMatchingServices(kIOMasterPortDefault,
dict, &devices);
}

#pragma clang diagnostic pop

if (ret != KERN_SUCCESS) {
printf("Cannot find matching IO services.\n");
return 0;
Expand Down

0 comments on commit 1f5e5dd

Please sign in to comment.