Csound Csound-dev Csound-tekno Search About

[Cs-dev] temporary files and csoundFileOpenWithType()

Date2009-11-05 18:07
FromRory Walsh
Subject[Cs-dev] temporary files and csoundFileOpenWithType()
I have an opcode that opens a file for reading and writing, I'm using
csound->FileOpen2() to open said file. I would like Csound to delete
the file when it's done so I thought I could pass a 1 as the last
parameter to FileOpen2 which seems to call csoundFileOpenWithType() in
envvar.c. The documentation states that:

 * Same as csoundFileOpen() with two additional parameters describing the
 * type of file being opened and whether it is a temporary file.  This
 * function replaces csoundFileOpen().  This additional information is
 * used as metadata to be passed to the host application's FileOpenCallback.
 *
 * int csFileType:
 *   A value from the enumeration CSOUND_FILETYPES (see CsoundCore.h)
 * int isTemporary:
 *   1 if this file will be deleted when Csound is finished.
 *   Otherwise, 0.

void *csoundFileOpenWithType(CSOUND *csound, void *fd, int type,
                     const char *name, void *param, const char *env,
                     int csFileType, int isTemporary)

In my code I have
fd = csound->FileOpen2(csound, &p->outfile, CSFILE_STD, "rory.raw",
"wb+", NULL, CSFTYPE_OTHER_BINARY, 1);

and in my de-init function I use

csound->FileClose(csound, data->outfile);

Two questions:
A) Is this the correct way to close a file that's been opened with FileOpen2()
B) Should this mean that the file is deleted once FileClose() is called?

Rory.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2009-11-05 18:32
FromRory Walsh
SubjectRe: [Cs-dev] temporary files and csoundFileOpenWithType()
Seems that I have it working now, by using tmpnam() to pass a name to
FileOpen2 no files seem to be left on the disk, at least I can't see
them. Saying that I don't ever see them appear in the first place
either? Normally I would see the file appear in the same folder as the
Csd file?

2009/11/5 Rory Walsh :
> I have an opcode that opens a file for reading and writing, I'm using
> csound->FileOpen2() to open said file. I would like Csound to delete
> the file when it's done so I thought I could pass a 1 as the last
> parameter to FileOpen2 which seems to call csoundFileOpenWithType() in
> envvar.c. The documentation states that:
>
>  * Same as csoundFileOpen() with two additional parameters describing the
>  * type of file being opened and whether it is a temporary file.  This
>  * function replaces csoundFileOpen().  This additional information is
>  * used as metadata to be passed to the host application's FileOpenCallback.
>  *
>  * int csFileType:
>  *   A value from the enumeration CSOUND_FILETYPES (see CsoundCore.h)
>  * int isTemporary:
>  *   1 if this file will be deleted when Csound is finished.
>  *   Otherwise, 0.
>
> void *csoundFileOpenWithType(CSOUND *csound, void *fd, int type,
>                     const char *name, void *param, const char *env,
>                     int csFileType, int isTemporary)
>
> In my code I have
> fd = csound->FileOpen2(csound, &p->outfile, CSFILE_STD, "rory.raw",
> "wb+", NULL, CSFTYPE_OTHER_BINARY, 1);
>
> and in my de-init function I use
>
> csound->FileClose(csound, data->outfile);
>
> Two questions:
> A) Is this the correct way to close a file that's been opened with FileOpen2()
> B) Should this mean that the file is deleted once FileClose() is called?
>
> Rory.
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net