const char* LLURL::updateRelativePath(const LLURL &url) { char new_path[LL_MAX_PATH]; char tmp_path[LL_MAX_PATH]; char *parse; if (mPath[0] != '/') { //start with existing path strncpy(new_path,url.mPath, LL_MAX_PATH -1); /* (0, LL_MAX_PATH - 1) */ new_path[LL_MAX_PATH -1] = '\0'; /* (LL_MAX_PATH - 1, 1) */ strncpy(tmp_path,mPath, LL_MAX_PATH -1); /* (0, LL_MAX_PATH - 1) */ tmp_path[LL_MAX_PATH -1] = '\0'; /* (LL_MAX_PATH - 1, 1) */ parse = strtok(tmp_path,"/"); while (parse) { if (!strcmp(parse,".")) { // skip this, it's meaningless } else if (!strcmp(parse,"..")) { if ((parse = strrchr(new_path, '/'))) { *parse = '\0'; if ((parse = strrchr(new_path, '/'))) { *(parse+1) = '\0'; } else { new_path[0] = '\0'; } } else { strcat(new_path,"../"); } } else { strncat(new_path,parse, LL_MAX_PATH - strlen(new_path) -1 ); strcat(new_path,"/"); } parse = strtok(NULL,"/"); } strncpy(mPath,new_path, LL_MAX_PATH -1); mPath[LL_MAX_PATH -1] = '\0'; } return mPath; }