Hello ,...
im working on a patch to smser (smser.sf.net)project.
since i don't how the change of static char* = " ... " to char * Iam avoiding the change in the main program .
in the program there are sevral static char varibales that need to ne changed:
orignal code :
i wish to change it by a function so i do the next. // since diffrent users will run the program from diffrent places .Code:static char* CONFDIR = "/.centericq";
p.s.Code:#include <pwd.h> #include <errno> #include <assert> int change_path() { char *path_to_home = NULL; char *temp; temp = CONFDIR; path_to_home = get_home_dir(); CONFDIR = (char *) malloc ( sizeof(char) * ( strlen(path_to_home) + strlen(temp) + 1)); strcpy(CONFDIR,path_to_home);//copy the actual path to confdir strcpy(CONFDIR + strlen (path_to_home),temp); free(path_to_home); return 0; } char* get_home_dir() { char *path = NULL; int size = 0; struct passwd *passwd; //read man file for getpuid() or passwd = getpwuid(getuid()); size = strlen((passwd->pw_dir)); path = (char *) malloc (sizeof(char) * size); assert(path); strcpy(path, passwd->pw_dir); //will copy the home directory to path /* * maybe just returning the pw_dir ? */ return path; }
im writing from the memory so maybe i wrote some small errors (but this is the genral idea).
is it the right attiude with code changes ? (to write small functions expect changing in the main program).


