• 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: File not closing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File not closing


  • Subject: Re: File not closing
  • From: Chris Ridd <email@hidden>
  • Date: Fri, 09 May 2003 15:08:28 +0100

On 9/5/03 2:40 pm, Trygve Inda <email@hidden> wrote:

>> On 8/5/03 7:50 pm, Trygve Inda <email@hidden> wrote:
>>> This is possibly a Cocoa/Carbon hybrid question but...
>>>
>>> I have a Carbon app that creates a series of image files in my App Support
>>> folder. These images are set to the desktop with NotificationCenter. Once
>>> the desktop is replaced, the old file (created by my app) is deleted.
>>>
>>> I am running into a conflict with another developer's app (Cocoa) that is
>>> reading the desktop picture whenever it changes and loading it for its own
>>> use...
>>>
>>> So my app sets the desktop, and then a Cocoa app reads in the new desktop
>>> image, but somehow prevents me from deleting it after I have set a new image
>>> about a minute later.
>>>
>>> NSImage *deskImage = [[[NSImage alloc] initWithContentsOfFile:imagePath]
>>> autorelease];
>>>
>>> It seems this call (made by another app) prevents my app from being able to
>>> delete the files it is generating.
>>>
>>> As I am not experienced with Cocoa, what might be causing this? Is there a
>>> better way to do this such that the file is not left open? What does
>>> "autorelease" really do?
>>>
>>> (In My Carbon app, FSDeleteObject returns -47 (file busy)).
>>
>> There should be no problem with deleting a file that's open - Unix file
>> semantics allow that (the blocks used by the deleted file are still usable
>> and only freed when the file is not open by anything.) Dunno what the Carbon
>> semantics are, perhaps they're different.
>>
>> Try using unlink instead of that Carbon call.
>>
>> Cheers,
>>
>> Chris
>
> How can I use unlink with an FSRef and what framework do I need to include?

Unlink's in libSystem, and you'll need to #include <unistd.h> to get the
function prototype. (Try 'man unlink' in the terminal.)

It needs a POSIX filename (I think by definition these are UTF-8 on OS X),
so I'd imagine you'd want to use CFURLCreateFromFSRef with your FSRef, and
then CFURLCopyFileSystemPath (..., kCFURLPOSIXPathStyle ) to get a CFString,
and then CFStringGetCStringPtr(..., kCFStringEncodingUTF8) to finally get
the POSIX filename.

> Thanks,
>
> Trygve
>
>

Cheers,

Chris
_______________________________________________
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.

References: 
 >Re: File not closing (From: Trygve Inda <email@hidden>)

  • Prev by Date: NSComboBoxCell auto completion
  • Next by Date: testing, please ignore
  • Previous by thread: Re: File not closing
  • Next by thread: NBChart plotting framework/palette
  • Index(es):
    • Date
    • Thread