Thanks, Graham.

On Mar 8, 2011, at 12:39 AM, Graham Cox wrote:

You could just make it bigger - it's a very transient piece of memory on the stack (or, if that's a problem, just malloc and free a chunk). Since getxattr allows you to pass in the max size of the buffer, it's also safe from a buffer overflow attack.


Another solution was suggested offline:

On Mar 7, 2011, at 10:14 PM, Scott Ribe wrote:
From the xattr man page:
When value is set to NULL, getxattr() returns current size of the named attribute. This facility can be used to determine the size of a buffer sufficiently large to hold the data currently associated with the attribute.
--
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice


My response:

Thanks, Scott. Obviously I should RTFM 8-)

I coded it to get the attribute size as you've described, allocate a large enough buffer, and call getxattr() again for the data. It works great!


I found, though, that strangely I don't have any documentation of the getxattr() behaviour you've described. 1) I was using the book "Advanced Mac OS X Programming", by Dalrymple and Hillegass. It has a section on xattributes, but doesn't mention
     the ability to set value to NULL in getxattr().
2) I tried to get the xattr man page, but typing 'man xattr' and 'man getxattr()' into the terminal didn't return anything. a) I thought man pages were only for commands. Can we get man pages for C functions too?
   b) I'm still on OS X 10.5. Maybe that's why I don't get anything?

------------------------------------------------
In further discussion with Scott, it looks like the xattribute docs aren't in the 10.5 man pages
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to