external code
Monkey Targets Forums/Desktop/external code
| ||
I need to get the users home directory and created an external module, but the code is not returning the proper value. Can someone tell me what is wrong with the code. #include <pwd.h> static String getPath() { char *path = getpwuid(getuid())->pw_dir; return String(path); } I am not a c coder, so there could be mistakes :) |
| ||
Can't you printf the result to see if it's right? Cheers Charlie |
| ||
Okay, this code finally works :) #include <pwd.h> char* getPath() { char *path = NULL; int size = 0; struct passwd *passwd; passwd = getpwuid(getuid()); size = strlen((passwd->pw_dir)); path = (char *) malloc (sizeof(char) * size); strcpy(path, passwd->pw_dir); return path; } |