• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSMutableData +dataWithLength: sets errno?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableData +dataWithLength: sets errno?


  • Subject: Re: NSMutableData +dataWithLength: sets errno?
  • From: Greg Parker <email@hidden>
  • Date: Tue, 14 Mar 2017 16:27:55 -0700

> On Mar 14, 2017, at 4:08 PM, John McCall <email@hidden> wrote:
>
>> On Mar 14, 2017, at 7:00 PM, Carl Hoefs <email@hidden> wrote:
>> macOS 10.12.3, Xcode 8.2.1, ObjC
>>
>> I'm finding the following line to be problematic:
>>
>>   NSMutableData *myData = [NSMutableData dataWithLength:80];
>>
>> I assume this ends up calling calloc(3) to allocate and zero out the data. But for some reason, it's always setting errno to a seemingly random nonzero value, generally either errno=2 (ENOENT) or errno=22 (EINVAL).
>>
>> Now that I know it does this, I can make accommodations for it, but is this expected behavior?
>
> I don't know why it's happening here, but unless you're calling a function that specifically documents its errno behavior, you should assume that every call you make might randomly overwrite errno with gibberish.

The POSIX standard specifically states that errno's value is undefined almost everywhere and can be arbitrarily changed by almost anything.

http://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html <http://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html>


--
Greg Parker     email@hidden <mailto:email@hidden>     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSMutableData +dataWithLength: sets errno?
      • From: Carl Hoefs <email@hidden>
References: 
 >NSMutableData +dataWithLength: sets errno? (From: Carl Hoefs <email@hidden>)
 >Re: NSMutableData +dataWithLength: sets errno? (From: John McCall <email@hidden>)

  • Prev by Date: Re: NSMutableData +dataWithLength: sets errno?
  • Next by Date: Re: NSMutableData +dataWithLength: sets errno?
  • Previous by thread: Re: NSMutableData +dataWithLength: sets errno?
  • Next by thread: Re: NSMutableData +dataWithLength: sets errno?
  • Index(es):
    • Date
    • Thread