Re: NSArray to argv-style string vector. How ?
Re: NSArray to argv-style string vector. How ?
- Subject: Re: NSArray to argv-style string vector. How ?
- From: Nick Zitzmann <email@hidden>
- Date: Sun, 22 Jun 2003 14:45:02 -0700
On Sunday, June 22, 2003, at 11:28 AM, Rolf wrote:
I need to call AuthoriztionExecuteWithPriveliges(). The fourth
parameter is of type argv-style string vector (char * const
*arguments). Does anybody know how to convert an NSArray of
NSStrings's to fit this fourth parameter ? I'm sure there's an
embarrassingly simple way to do this ..
You could do it dynamically, like this: (code written in Mail,
untested, etc.)
NSArray *array; // or whatever you called your array object
const unsigned arrayCount = [array count];
char *charArray[arrayCount];
int charArrayCount;
for (charArrayCount = 0 ; charArrayCount < arrayCount ;
charArrayCount++)
{
NSString *theString = [array objectAtIndex:charArrayCount];
unsigned int stringLength = [theString length];
charArray[charArrayCount] = malloc(stringLength * sizeof(char));
snprintf(charArray[charArrayCount], stringLength, "%s", [theString
cString]; // I'm assuming you're not using any 2-byte characters here
}
// do your Security calls here
// this will de-allocate the memory we allocated above
while (charArrayCount >= 0)
{
free(charArray[charArrayCount]);
charArrayCount--;
}
Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page:
http://dreamless.home.attbi.com/
"Great spirits have always encountered violent opposition from mediocre
minds." - Albert Einstein
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.