I\'m porting a C library to OSX which haven\'t given me much of a headache until now. In the next function:
int createDirectory( char *directory ){
int
OSX does not expand the '~'
character as bash
does (although it uses bash
).
Given this program, running in /tmp
:
#include <stdlib.h>
#include <sys/stat.h>
#include <stdio.h>
int main(void)
{
char *given = "~/Library";
char result[1024];
char *s;
mkdir("~", 0755);
mkdir("~/Library", 0755);
if ((s = realpath(given, result)) != 0) {
printf ("%s\n", s);
} else {
perror("realpath");
}
return 0;
}
I get this result on OSX:
/private/tmp/~/Library
I get this result on Linux (Debian) as well as with Solaris 10:
/tmp/~/Library
As noted in Why doesn't the tilde (~) expand inside double quotes?, this was originally a csh
shell feature which bash
incorporated long ago (citing a page from 1994). It is not implemented in any of the given systems' runtime libraries.