Return to Snippet

Revision: 28446
at July 9, 2010 01:46 by hafthor


Updated Code
#include <sys/sysctl.h>

+(NSString *)getPlatform {
  size_t size=0;
  char *machine=NULL;
  for(;;) {
    sysctlbyname("hw.machine",machine,&size,NULL,0);
    if(!size) break;
    if(machine) {
      NSString *platform=[NSString stringWithUTF8String:machine];
      free(machine);
      return platform;
    }
    machine=malloc(size);
    if(!machine) break;
  }
  return nil;
}

// optimistic version

+(NSString *)getPlatform {
  char machine[256];
  size_t size=sizeof(machine);
  sysctlbyname("hw.machine",machine,&size,NULL,0);
  return size>sizeof(machine) ? nil : [NSString stringWithUTF8String:machine];
}

Revision: 28445
at July 9, 2010 01:45 by hafthor


Updated Code
#include <sys/sysctl.h>

+(NSString *)getPlatform {
  size_t size=0;
  char *machine=NULL;
  for(;;) {
    sysctlbyname("hw.machine",machine,&size,NULL,0);
    if(!size) break;
    if(machine) {
      NSString *platform=[NSString stringWithUTF8String:machine];
      free(machine);
      return platform;
    }
    machine=malloc(size);
    if(!machine) break;
  }
  return nil;
}

// optimistic version

+(NSString *)getPlatform {
  char machine[256];
  size_t size=sizeof(machine);
  sysctlbyname("hw.machine",machine,&size,NULL,0);
  if(size>sizeof(machine)) return nil;
  return [NSString stringWithUTF8String:machine];
}

Revision: 28444
at July 8, 2010 11:08 by hafthor


Updated Code
#include <sys/sysctl.h>

+(NSString *)getPlatform {
  size_t size=0;
  char *machine=NULL;
  for(;;) {
    sysctlbyname("hw.machine",machine,&size,NULL,0);
    if(!size) break;
    if(machine) {
      NSString *platform=[NSString stringWithUTF8String:machine];
      free(machine);
      return platform;
    }
    machine=malloc(size);
    if(!machine) break;
  }
  return nil;
}

Revision: 28443
at July 8, 2010 11:05 by hafthor


Updated Code
#include <sys/sysctl.h>

+(NSString *)getPlatform {
  size_t size=0;
  char *machine=NULL;
  for(;;) {
    sysctlbyname("hw.machine",machine,&size,NULL,0);
    if(machine) {
      NSString *platform=[NSString stringWithUTF8String:machine];
      free(machine);
      return platform;
    }
    if(!size) break;
    machine=malloc(size);
    if(!machine) break;
  }
  return nil;
}

Revision: 28442
at July 8, 2010 11:04 by hafthor


Updated Code
#include <sys/sysctl.h>

+(NSString *)getPlatform {
  size_t size=0;
  char *machine=NULL;
  for(;;) {
    sysctlbyname("hw.machine",machine,&size,NULL,0);
    if(machine) {
      NSString *platform=[NSString stringWithUTF8String:machine];
      free(machine);
      return platform;
    }
    if(!size) return nil;
    machine=malloc(size);
    if(!machine) return nil;
  }
}

Revision: 28441
at July 8, 2010 10:54 by hafthor


Updated Code
#include <sys/sysctl.h>

+(NSString *)getPlatform {
	size_t size=0;
	char *machine=NULL;
	for(;;) {
		sysctlbyname("hw.machine",machine,&size,NULL,0);
		if(machine) {
			NSString *platform=[NSString stringWithUTF8String:machine];
			free(machine);
			return platform;
		}
		if(!size) return nil;
		machine=malloc(size);
		if(!machine) return nil;
	}
}

Revision: 28440
at July 8, 2010 10:50 by hafthor


Updated Code
+(NSString *)getPlatform {
	size_t size=0;
	char *machine=NULL;
	for(;;) {
		sysctlbyname("hw.machine",machine,&size,NULL,0);
		if(machine) {
			NSString *platform=[NSString stringWithUTF8String:machine];
			free(machine);
			return platform;
		}
		if(!size) return nil;
		machine=malloc(size);
		if(!machine) return nil;
	}
}

Revision: 28439
at July 8, 2010 10:47 by hafthor


Initial Code
+(NSString *)getPlatform {
	size_t size=0;
	char *machine=NULL;
	for(;;) {
		sysctlbyname("hw.machine",machine,&size,NULL,0);
		if(machine) {
			NSString *platform=[NSString stringWithUTF8String:machine];
			free(machine);
			return platform;
		}
		if(size==0) return nil;
		machine=malloc(size);
		if(machine==NULL) return nil;
	}
}

Initial URL


Initial Description


Initial Title
Get iPhone/iPad/iPod Touch hardware generation

Initial Tags
iphone

Initial Language
Objective C