GLBasic forum

Main forum => Bug Reports => Topic started by: MrTAToad on 2009-Nov-22

Title: CREATEDIR on Linux and Mac doesn't work
Post by: MrTAToad on 2009-Nov-22
I've tried the following with a Linux and Mac executable, but no directory is created and the "An Error" message is displayed :

Code (glbasic) Select
a$=PLATFORMINFO$("DOCUMENTS")+"/temp"
DEBUG "A$ : "+a$+"\n"
IF CREATEDIR(a$)=TRUE
DEBUG "Directory created"
ELSE
DEBUG "An error"
ENDIF


GETLASTERROR returns a successful operation...  It seems that this shortcut is not available for path calls from within applications...  So, instead of using ~, the full path may be needed instead (ie /home/user - which does work)

The directory can be created from Terminal okay though...

Works fine in Windows.
Title: Re: CREATEDIR on Linux and Mac doesn't work
Post by: Kitty Hello on 2009-Nov-23
is the environment variable "HOME" defined on a mac?
Title: Re: CREATEDIR on Linux and Mac doesn't work
Post by: MrTAToad on 2009-Nov-23
I need to check, but I believe it does - unfortunately, if I remember correctly its "~/"
Title: Re: CREATEDIR on Linux and Mac doesn't work
Post by: Kitty Hello on 2009-Nov-24
aw, bad. How would I get the real directory then - or: how to create a directory with SHELLCMD :P
Title: Re: CREATEDIR on Linux and Mac doesn't work
Post by: MrTAToad on 2009-Nov-24
Take a peek at : http://developer.apple.com/mac/library/qa/qa2007/qa1549.html (http://developer.apple.com/mac/library/qa/qa2007/qa1549.html) or you use FSFindFolder followed by FSRefMakePath with a value of "docs" as a 32-bit value (for documents directory).  If you want to get the user's home directory you want "cusr"

By the way, on a Linux machine, $HOME may not exist/contain a value  :S so you might need to use _getpwuid with the users ID (_getuid) and get the directory out of the password structure...




Title: Re: CREATEDIR on Linux and Mac doesn't work
Post by: Kitty Hello on 2009-Nov-24
ok. shellcmd then.
mkdir "~/test"
does that work?
Title: Re: CREATEDIR on Linux and Mac doesn't work
Post by: MrTAToad on 2009-Nov-25
It does on Linux - and works on Mac too.

You could always use this (Linux only):

Code (glbasic) Select
INLINE
#ifndef WIN32
typedef struct __password {
char *pw_name; // user name
char *pw_passwd; // user password
int pw_uid; //user id
int pw_gid; // group id
char *pw_gecos; // real name
char *pw_dir; // home directory
char *pw_shell; // shell program
} __password;

extern "C" char *getenv(char *);
extern "C" struct __password *getpwuid(int uid);
extern "C" int getuid(void);
#endif
ENDINLINE

FUNCTION getHome$:
LOCAL temp$

temp$=""

INLINE
char *ptr;

#ifdef WIN32
#else
ptr=getenv("$HOME");
if (!ptr)
{
struct __password *password;

password=getpwuid(getuid());
if (password)
{
if (password->pw_dir)
{
temp_Str.assign(password->pw_dir);
}
}
}
else
{
temp_Str.assign(ptr);
}
#endif
ENDINLINE

RETURN temp$
ENDFUNCTION


It appears that $HOME cant be used programmatically on MacOS (getenv is de-appreciated) - the password section just returns ":" - so I need to see if ":/test" is a valid directory  :S

And, no its not...
Title: Re: CREATEDIR on Linux and Mac doesn't work
Post by: MrTAToad on 2009-Nov-26
There is an additional problem on the Mac - DOESDIREXIST doesn't work with "~/" either...