problem with sysfile_writetextfile

andrea agostini's icon

Hi.

I have a problem with sysfile_writetextfile() - it simply doesn't write anything. The file is created, but left empty.

Here is my function. As you can see, it's mostly copied from the SDK. And yes, it's deferred.

void llll_writetextfile(t_object *x, char *filename, short path, char *buf)
{
    long err;
    t_filehandle fh;
    err = path_createsysfile(filename, path, 'TEXT', &fh);
    if (err)
        return;
    err = sysfile_writetextfile(fh, &buf, TEXT_LB_NATIVE);
    err = sysfile_close(fh);
}

I have checked it in the debugger, and everything looks fine - buf and filename are valid and meaningful, err is always 0. I really can't see what's happening.

(I'm on OSX 10.6.4)

thanks
aa

Joshua Kit Clayton's icon

I believe you'll need to use a t_handle as allocated with sysmem_newhandle(). It can't just be any char **. Let us know if that doesn't work. You can either copy your pointer to a handle manually, or use sysmem_ptrandhand() to do this.

`
t_handle h = sysmem_newhandle(0);
sysmem_ptrandhand(buf,h,strlen(buf)); // +1 if you want to copy the null termination, but not necessary here

...

sysmem_freehandle(h);
`

-Joshua

andrea agostini's icon

It works

thank you!

aa

$Adam's icon

Hi,

just a note for the person maintaining the docs: the latest documentation (5.1.7) is still using char*, which is a little confusing. Maybe this could be fixed in a future release.

Thanks,
Ádám

MIB's icon

exactly what I was looking for! Thanks!
Also, this is still not updated in the 6.1.1 SDK:

SDK: void myobject_writefile(t_myobject *x, char *filename, short path)
{
char *buf = "write me into a file";
long err;
t_filehandle fh;
err = path_createsysfile(filename, path, 'TEXT', &fh);
if (err)
return;
err = sysfile_writetextfile(fh, &buf, TEXT_LB_NATIVE);
sysfile_close(fh);
}

This works for me:

void buffTest_writefile(t_buffTest *x, char *filename, short path)
{
char *buf = "write me to a file";
t_handle h = sysmem_newhandle(0);
sysmem_ptrandhand(buf,h,strlen(buf));
long err;
t_filehandle fh;
err = path_createsysfile(filename, path, 'TEXT', &fh);
if (err)
return;
err = sysfile_writetextfile(fh, h, TEXT_LB_NATIVE);
sysfile_close(fh);
sysmem_freehandle(h);
}