problem with sysfile_writetextfile

Nov 2, 2010 at 10:20am

problem with sysfile_writetextfile

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

#53056
Nov 3, 2010 at 9:08pm

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

#190812
Nov 6, 2010 at 8:53am

It works

thank you!

aa

#190813
Apr 23, 2011 at 1:21am

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

#190814
Jun 20, 2013 at 2:13pm

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

#253479

You must be logged in to reply to this topic.