Forums > Dev

problem with sysfile_writetextfile


Nov 02 2010 | 10:20 am

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

Nov 03 2010 | 9:08 pm

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

Nov 06 2010 | 8:53 am

It works

thank you!

aa

Apr 23 2011 | 1:21 am

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
Jun 20 2013 | 2:13 pm

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);
}

Viewing 5 posts - 1 through 5 (of 5 total)

Forums > Dev