Forums > Dev

get path as char * from path_getdefault()?

November 26, 2006 | 11:32 pm

Hi,

I can’t figure out how to get the default path from path_getdefault
(), and then convert that to a fully qualified OS-friendly char *
path. Anybody know how?

Thanks


November 27, 2006 | 10:54 am

Something like this should do the trick:

char cpath[1024];
short path = path_getdefault();
short err;

if (!(err = path_topotentialname(path, "", cpath, false)))
post("the path is %s", cpath);
else
post("error in path_topotentialname %d", err);

Am 27.11.2006 um 00:32 schrieb Graham Wakefield:

> Hi,
>
> I can’t figure out how to get the default path from path_getdefault
> (), and then convert that to a fully qualified OS-friendly char *
> path. Anybody know how?
>
> Thanks


November 27, 2006 | 7:00 pm

Perfect, thanks!

I didn’t think of passing "" as the filename to path_topotentialname.

On Nov 27, 2006, at 2:54 AM, Jeremy Bernstein wrote:

> char cpath[1024];
> short path = path_getdefault();
> short err;
>
> if (!(err = path_topotentialname(path, "", cpath, false)))
> post("the path is %s", cpath);
> else
> post("error in path_topotentialname %d", err);


November 27, 2006 | 7:22 pm

Ah; it turns out that this returns a path with the volume label also
(e.g. "Macintosh HD:/Users/Documents/MaxMSPobjects/test/") whereas
what I need is without the volume label (e.g. "/Users/Documents/
MaxMSPobjects/test/").

Hmm

On Nov 27, 2006, at 2:54 AM, Jeremy Bernstein wrote:

> char cpath[1024];
> short path = path_getdefault();
> short err;
>
> if (!(err = path_topotentialname(path, "", cpath, false)))
> post("the path is %s", cpath);
> else
> post("error in path_topotentialname %d", err);


November 28, 2006 | 7:33 am

You can strcmp ";/" and get the location where the volume label ends.

wes

On 11/27/06, Graham Wakefield

wrote:
>
> Ah; it turns out that this returns a path with the volume label also (e.g.
> "Macintosh HD:/Users/Documents/MaxMSPobjects/test/")
> whereas what I need is without the volume label (e.g.
> "/Users/Documents/MaxMSPobjects/test/").
>
> Hmm
>
> On Nov 27, 2006, at 2:54 AM, Jeremy Bernstein wrote:
>
>
> char cpath[1024];
>
> short path = path_getdefault();
>
> short err;
>
>
>
>
> if (!(err = path_topotentialname(path, "", cpath, false)))
>
> post("the path is %s", cpath);
>
> else
>
> post("error in path_topotentialname %d", err);
>
>
>
>


November 28, 2006 | 9:27 am

In addition to Wesley’s solution, you can use the path_nameconform()
API function. I think this is correct usage for your expected result:

char srcpath[1024], dstpath[1024];

path_nameconform(srcpath, dstpath, PATH_STYLE_SLASH, PATH_TYPE_BOOT);
post("dstpath: %s", dstpath);

jb

Am 27.11.2006 um 20:22 schrieb Graham Wakefield:

> Ah; it turns out that this returns a path with the volume label
> also (e.g. "Macintosh HD:/Users/Documents/MaxMSPobjects/test/")
> whereas what I need is without the volume label (e.g. "/Users/
> Documents/MaxMSPobjects/test/").


November 28, 2006 | 7:23 pm

Brilliant.

The full code (for the archives):

char srcpath[1024], dstpath[1024];
if (!path_topotentialname(path_getdefault(), "", srcpath, false))
{
path_nameconform(srcpath, dstpath, PATH_STYLE_SLASH, PATH_TYPE_BOOT);
} else {
strcpy(dstpath,"/");
}

G

On Nov 28, 2006, at 1:27 AM, Jeremy Bernstein wrote:

> char srcpath[1024], dstpath[1024];
>
> …
>
> path_nameconform(srcpath, dstpath, PATH_STYLE_SLASH, PATH_TYPE_BOOT);
> post("dstpath: %s", dstpath);


November 28, 2006 | 7:48 pm

Am 28.11.2006 um 20:23 schrieb Graham Wakefield:

> Brilliant.
>
> The full code (for the archives):
>
> char srcpath[1024], dstpath[1024];
> if (!path_topotentialname(path_getdefault(), "", srcpath, false))
> {
> path_nameconform(srcpath, dstpath, PATH_STYLE_SLASH,
> PATH_TYPE_BOOT);
> } else {
> strcpy(dstpath,"/");
> }

Is there a trick to get a filename that POSIX open() calls like even
when the file is on another harddisk? I’m currently using open_dialog
() to let the user choose a file, but then need to open the file with
POSIX open() call in order to get a file handle that I can pass on to
mmap(). The conversion is like the one above, but only works as long
as the files are on the system partition…

Olaf


November 28, 2006 | 8:51 pm

What does the path you’re getting back look like? Does it have
colons in it, per an old-style HFS path. You may need to either use
CFURL or convert the colon-delimited path to a POSIX path manually (/
Volumes//path_to_file).

_Mark

On Nov 28, 2006, at 11:48 AM, Olaf Matthes wrote:

>
> Am 28.11.2006 um 20:23 schrieb Graham Wakefield:
>
>> Brilliant.
>>
>> The full code (for the archives):
>>
>> char srcpath[1024], dstpath[1024];
>> if (!path_topotentialname(path_getdefault(), "", srcpath, false))
>> {
>> path_nameconform(srcpath, dstpath, PATH_STYLE_SLASH,
>> PATH_TYPE_BOOT);
>> } else {
>> strcpy(dstpath,"/");
>> }
>
> Is there a trick to get a filename that POSIX open() calls like
> even when the file is on another harddisk? I’m currently using
> open_dialog() to let the user choose a file, but then need to open
> the file with POSIX open() call in order to get a file handle that
> I can pass on to mmap(). The conversion is like the one above, but
> only works as long as the files are on the system partition…
>
> Olaf
>


November 28, 2006 | 8:54 pm

What does the path you’re getting back look like? Does it have
colons in it, per an old-style HFS path. You may need to either use
CFURL or convert the colon-delimited path to a POSIX path manually (/
Volumes//path_to_file).

_Mark

On Nov 28, 2006, at 11:48 AM, Olaf Matthes wrote:

>
> Am 28.11.2006 um 20:23 schrieb Graham Wakefield:
>
>> Brilliant.
>>
>> The full code (for the archives):
>>
>> char srcpath[1024], dstpath[1024];
>> if (!path_topotentialname(path_getdefault(), "", srcpath, false))
>> {
>> path_nameconform(srcpath, dstpath, PATH_STYLE_SLASH,
>> PATH_TYPE_BOOT);
>> } else {
>> strcpy(dstpath,"/");
>> }
>
> Is there a trick to get a filename that POSIX open() calls like
> even when the file is on another harddisk? I’m currently using
> open_dialog() to let the user choose a file, but then need to open
> the file with POSIX open() call in order to get a file handle that
> I can pass on to mmap(). The conversion is like the one above, but
> only works as long as the files are on the system partition…
>
> Olaf
>


November 28, 2006 | 9:38 pm

Am 28.11.2006 um 21:54 schrieb Mark Pauley:

> What does the path you’re getting back look like? Does it have
> colons in it, per an old-style HFS path. You may need to either
> use CFURL or convert the colon-delimited path to a POSIX path
> manually (/Volumes//path_to_file).

Here’s what I’m doing:

open_dialog(x->x_filename, &x->x_filevol, &type, 0L, 0);
// path_topathname(x->x_filevol, x->x_filename, file);
path_topotentialname(x->x_filevol, x->x_filename, file, false);
path_nameconform(file, x->x_filename, PATH_STYLE_MAX_PLAT,
PATH_TYPE_BOOT);
fh = open(x->x_filename, O_RDONLY);

With files being an a different harddisk I end up with x->x_filenam
being empty. When on the same disk, it contains the full path
including filename that open() wants to see. This is on OS X (because
on Windows there is no mmap(), so I have to use sysfile API there).

Olaf


November 28, 2006 | 10:01 pm

On Nov 28, 2006, at 11:48 AM, Olaf Matthes wrote:

>
> Is there a trick to get a filename that POSIX open() calls like
> even when the file is on another harddisk? I’m currently using
> open_dialog() to let the user choose a file, but then need to open
> the file with POSIX open() call in order to get a file handle that
> I can pass on to mmap(). The conversion is like the one above, but
> only works as long as the files are on the system partition…

In this case, there is no routine provided by max, but is it a simple
string manipulation. If there is an error reported in the string
conversion, strstr for ":/" . The partition name will be first and
then you can just put into a string like Mark suggests.

e.g.

partitionname:/folder/subfolder/file.txt

maps to

/Volumes/partitionname/folder/subfolder/file.txt

Something like the following quickie email client code, as applied to
a failed BOOT_STYLE pathname. Note, as always with email client
coding, there could be typos, oversights, etc. but it should get you
going.

void max_to_osx_pathname(char *maxpathname, char *osxpathname)
{
char *pathstr;
char partitionstr[256];
long i;

if (pathstr=sscanf(maxpathname,":/")
{
// copy partition name form max pathname up to ":/"
for (i=0;i< (maxpathname-pathstr);i++)
partitionstr[i] = maxpthname[i];

// null terminate
partitionstr[i] = 0;

// advance path past ":/"
pathstr+=2;

// write into osxpathname with appropriate format string
sprintf(osxpathname,"/Volumes/%s/%s",,pathstr)
}
else
{
strcpy(osxpathname,maxpathname);
}

}

Note that this /Volumes/ syntax is OS X only. As for windows usage of
open(), you’ll have to consult what version of open you’re using (MS,
Cygwin, or other), and what it supports. I don’t know off the top of
my head.

-Joshua


November 28, 2006 | 10:03 pm

On Nov 28, 2006, at 12:54 PM, Mark Pauley wrote:

> What does the path you’re getting back look like? Does it have
> colons in it, per an old-style HFS path. You may need to either
> use CFURL or convert the colon-delimited path to a POSIX path
> manually (/Volumes//path_to_file).

It’s a Max cross platform path specifier, which is something like a
cross between unix and windows style paths.

partition:/folder/subfolder/file.txt

-Joshua


November 28, 2006 | 11:02 pm

Am 28.11.2006 um 23:01 schrieb Joshua Kit Clayton:

>
> On Nov 28, 2006, at 11:48 AM, Olaf Matthes wrote:
>
>>
>> Is there a trick to get a filename that POSIX open() calls like
>> even when the file is on another harddisk? I’m currently using
>> open_dialog() to let the user choose a file, but then need to open
>> the file with POSIX open() call in order to get a file handle that
>> I can pass on to mmap(). The conversion is like the one above, but
>> only works as long as the files are on the system partition…
>
> In this case, there is no routine provided by max, but is it a
> simple string manipulation. If there is an error reported in the
> string conversion, strstr for ":/" . The partition name will be
> first and then you can just put into a string like Mark suggests.
>
> e.g.
>
> partitionname:/folder/subfolder/file.txt
>
> maps to
>
> /Volumes/partitionname/folder/subfolder/file.txt
>
> Something like the following quickie email client code, as applied
> to a failed BOOT_STYLE pathname. Note, as always with email client
> coding, there could be typos, oversights, etc. but it should get
> you going.

Thanks Joshua! This doesn’t work, but gives me an idea what to do.
Actually, my mistake was to put my path through path_nameconform()
after which I ended up with an empty filename…

Olaf


November 29, 2006 | 12:21 am

On Nov 28, 2006, at 3:02 PM, Olaf Matthes wrote:

>
> As Joshua! This doesn’t work, but gives me an idea what to do.
> Actually, my mistake was to put my path through path_nameconform()
> after which I ended up with an empty filename…

Right, check the return value (if non zero something went wrong, most
likely it’s not on the boot volume), and then just use the original
in some fashion similar to my rough C sketch.

-Joshua


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