comparison ios/dw.m @ 2787:56312f9c1d6c

iOS: Return the Application Sandbox's Documents folder from dw_user_dir() instead of the home directory by default. May not have write permission in the actual home directory, causing errors saving configuration files. Fall back to the application sandbox folder or / if everything fails.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 13 Jul 2022 05:20:31 +0000
parents 3934ac8b394c
children b62859fbd9a3
comparison
equal deleted inserted replaced
2786:3934ac8b394c 2787:56312f9c1d6c
4026 { 4026 {
4027 static char _user_dir[PATH_MAX+1] = { 0 }; 4027 static char _user_dir[PATH_MAX+1] = { 0 };
4028 4028
4029 if(!_user_dir[0]) 4029 if(!_user_dir[0])
4030 { 4030 {
4031 char *home = getenv("HOME"); 4031 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
4032 4032 NSUserDomainMask, YES);
4033 if(home) 4033 NSString *nshome = [paths firstObject];
4034 const char *home;
4035
4036 if(nshome && (home = [nshome UTF8String]))
4037 strncpy(_user_dir, home, PATH_MAX);
4038 else if((nshome = NSHomeDirectory()) && (home = [nshome UTF8String]))
4034 strncpy(_user_dir, home, PATH_MAX); 4039 strncpy(_user_dir, home, PATH_MAX);
4035 else 4040 else
4036 strcpy(_user_dir, "/"); 4041 strcpy(_user_dir, "/");
4037 } 4042 }
4038 return _user_dir; 4043 return _user_dir;