Get path to user's "Application Support" folder

Apprentice
Posts: 7
Joined: 2008.11
Post: #1
I need to get the path to the user's "Application Support" folder, where I intend to do some operations using Boost's file-system library. I tried just using "~/Library/Application Support/", but Boost doesn't seem to recognize it.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
~ is a shell thing.

You should use NSSearchPathForDirectoriesInDomains to find the folder.
Quote this message in a reply
Apprentice
Posts: 7
Joined: 2008.11
Post: #3
Thank you.

Now, most of my project is in C++. I've tried writing a function in Objective C that uses a plain C interface (as in, it doesn't have any Cocoa parameters or return values) but I keep getting linker errors when I try to use the function in C++ code.
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2007.03
Post: #4
did you try

extern "C"
{
// C code
}

?
Quote this message in a reply
Apprentice
Posts: 7
Joined: 2008.11
Post: #5
That did the trick. I forgot about the thing with Obj. C being a strict superset of C. Thank you.

Update

I'm still getting a few problems though. I'm trying to copy the path to a c-string (since C++ can't use NSString). However, the path seems to get cut short, and I end up with "/Users/<my username>/Library/Application Suppor" (note the lack of 't').

This is my function. The path is meant to be stored in the string pointed to by path_dbptr.

Code:
int getApplicationDataPath(char **path_dbptr)
{
    int result = FALSE;
    NSString *destinationPath;

    NSArray *allPaths
      = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
       NSUserDomainMask, TRUE);

    if ([allPaths count] > 0)
    {
        destinationPath = [allPaths objectAtIndex:0];

        *path_dbptr = (char *)malloc([destinationPath
          lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);

        if ([destinationPath getCString:*path_dbptr
          maxLength:[destinationPath
           lengthOfBytesUsingEncoding:NSUTF8StringEncoding]
          encoding:NSUTF8StringEncoding])
        {
            result = TRUE;
        }
    }

    return result;
}
Quote this message in a reply
Member
Posts: 67
Joined: 2006.07
Post: #6
Remember that C strings are null-terminated. Instead of just copying (length) bytes, you'll need to copy (length + 1) bytes.

Since when was "Fred" a placeholder variable?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Drawing a path in-game GregX999 3 3,475 Dec 1, 2010 07:16 AM
Last Post: GregX999
  Path Finding bwalters 22 10,087 Mar 27, 2006 11:36 AM
Last Post: Blacktiger
  file path from NavReplyRecord? frac707 2 3,090 Mar 2, 2005 05:14 AM
Last Post: Hog