macos.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //pinched from ADC - no idea how it works!
  2. #include "macos.h"
  3. static int sysctlbyname_with_pid (const char *name, pid_t pid,
  4. void *oldp, size_t *oldlenp,
  5. void *newp, size_t newlen)
  6. {
  7. if (pid == 0) {
  8. if (sysctlbyname(name, oldp, oldlenp, newp, newlen) == -1) {
  9. return -1;
  10. }
  11. }else{
  12. int mib[CTL_MAXNAME];
  13. size_t len = CTL_MAXNAME;
  14. if (sysctlnametomib(name, mib, &len) == -1) {
  15. return -1;
  16. }
  17. mib[len] = pid;
  18. len++;
  19. if (sysctl(mib, len, oldp, oldlenp, newp, newlen) == -1) {
  20. return -1;
  21. }
  22. }
  23. return 0;
  24. }
  25. int is_pid_native( pid_t pid )
  26. {
  27. int ret = 0;
  28. size_t sz = sizeof(ret);
  29. if (sysctlbyname_with_pid("sysctl.proc_native", pid, &ret, &sz, NULL, 0) == -1) {
  30. if (errno == ENOENT) {
  31. // sysctl doesn't exist, which means that this version of Mac OS
  32. // pre-dates Rosetta, so the application must be native.
  33. return 1;
  34. }
  35. return -1;
  36. }
  37. return ret;
  38. }
  39. BBString *bbStringFromNSString( NSString *s ) {
  40. BBString *bbstring;
  41. int n;
  42. n=[s length];
  43. NSData * data=[s dataUsingEncoding:NSUnicodeStringEncoding];
  44. bbstring=bbStringFromShorts((unsigned short*)[data bytes] + 1,n );
  45. return bbstring;
  46. }
  47. NSString *NSStringFromBBString( BBString *s ) {
  48. if (!s->length) {
  49. return @"";
  50. } else {
  51. return [NSString stringWithCharacters:s->buf length:s->length];
  52. }
  53. }
  54. void NSOSVersion(int * major, int * minor, int * patch) {
  55. NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
  56. *major = version.majorVersion;
  57. *minor = version.minorVersion;
  58. *patch = version.patchVersion;
  59. }