mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-02-02 15:46:18 +03:00
Replace unnecessarily complicated path concatenation with something simpler and
easily adaptable to different platform path structures. svn path=/trunk/netsurf/; revision=10621
This commit is contained in:
parent
bffa2b64de
commit
d6eb28d5de
15
amiga/misc.c
15
amiga/misc.c
@ -106,6 +106,21 @@ char *filename_from_path(char *path)
|
||||
return strdup(FilePart(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path component/filename to an existing path
|
||||
*
|
||||
* \param path buffer containing path + free space
|
||||
* \param length length of buffer "path"
|
||||
* \param newpart string containing path component to add to path
|
||||
* \return true on success
|
||||
*/
|
||||
|
||||
bool path_add_part(char *path, int length, char *newpart)
|
||||
{
|
||||
if(AddPart(path, newpart, length)) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a string without escape chars or |M chars.
|
||||
* (based on remove_underscores from utils.c)
|
||||
|
@ -1197,3 +1197,22 @@ char *filename_from_path(char *path)
|
||||
|
||||
return strdup(leafname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path component/filename to an existing path
|
||||
*
|
||||
* \param path buffer containing path + free space
|
||||
* \param length length of buffer "path"
|
||||
* \param newpart string containing path component to add to path
|
||||
* \return true on success
|
||||
*/
|
||||
|
||||
bool path_add_part(char *path, int length, char *newpart)
|
||||
{
|
||||
if(path[strlen(path)] != '/')
|
||||
strncat(path, "/", length);
|
||||
|
||||
strncat(path, newpart, length);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -759,21 +759,19 @@ void save_complete_list_dump(void)
|
||||
bool save_complete_inventory(const char *path,
|
||||
struct save_complete_entry *list)
|
||||
{
|
||||
char urlpath[256];
|
||||
char fullpath[256];
|
||||
FILE *fp;
|
||||
char *pathstring, *standardpath = (path[0] == '/') ?
|
||||
(char *)(path + 1) : (char *)path;
|
||||
struct save_complete_entry *entry;
|
||||
bool error;
|
||||
|
||||
snprintf(urlpath, sizeof urlpath, "file:///%s/Inventory",
|
||||
standardpath);
|
||||
pathstring = url_to_path(urlpath);
|
||||
if (pathstring == NULL) {
|
||||
strncpy(fullpath, path, sizeof fullpath);
|
||||
error = path_add_part(fullpath, sizeof fullpath, path);
|
||||
|
||||
if (error == false) {
|
||||
warn_user("NoMemory", 0);
|
||||
return false;
|
||||
}
|
||||
fp = fopen(pathstring, "w");
|
||||
free(pathstring);
|
||||
fp = fopen(fullpath, "w");
|
||||
if (!fp) {
|
||||
LOG(("fopen(): errno = %i", errno));
|
||||
warn_user("SaveError", strerror(errno));
|
||||
|
@ -59,3 +59,22 @@ char *filename_from_path(char *path)
|
||||
|
||||
return strdup(leafname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path component/filename to an existing path
|
||||
*
|
||||
* \param path buffer containing path + free space
|
||||
* \param length length of buffer "path"
|
||||
* \param newpart string containing path component to add to path
|
||||
* \return true on success
|
||||
*/
|
||||
|
||||
bool path_add_part(char *path, int length, char *newpart)
|
||||
{
|
||||
if(path[strlen(path)] != '/')
|
||||
strncat(path, "/", length);
|
||||
|
||||
strncat(path, newpart, length);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -978,3 +978,22 @@ char *filename_from_path(char *path)
|
||||
|
||||
return strdup(leafname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path component/filename to an existing path
|
||||
*
|
||||
* \param path buffer containing path + free space
|
||||
* \param length length of buffer "path"
|
||||
* \param newpart string containing path component to add to path
|
||||
* \return true on success
|
||||
*/
|
||||
|
||||
bool path_add_part(char *path, int length, char *newpart)
|
||||
{
|
||||
if(path[strlen(path)] != '/')
|
||||
strncat(path, "/", length);
|
||||
|
||||
strncat(path, newpart, length);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
19
riscos/gui.c
19
riscos/gui.c
@ -2478,3 +2478,22 @@ char *filename_from_path(char *path)
|
||||
|
||||
return leafname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path component/filename to an existing path
|
||||
*
|
||||
* \param path buffer containing path + free space
|
||||
* \param length length of buffer "path"
|
||||
* \param newpart string containing path component to add to path
|
||||
* \return true on success
|
||||
*/
|
||||
|
||||
bool path_add_part(char *path, int length, char *newpart)
|
||||
{
|
||||
if(path[strlen(path)] != '.')
|
||||
strncat(path, ".", length);
|
||||
|
||||
strncat(path, newpart, length);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -121,4 +121,5 @@ query_id query_user(const char *query, const char *detail,
|
||||
void query_close(query_id);
|
||||
void PDF_Password(char **owner_pass, char **user_pass, char *path);
|
||||
char *filename_from_path(char *path);
|
||||
bool path_add_part(char *path, int length, char *newpart);
|
||||
#endif
|
||||
|
@ -65,3 +65,22 @@ char *filename_from_path(char *path)
|
||||
|
||||
return strdup(leafname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path component/filename to an existing path
|
||||
*
|
||||
* \param path buffer containing path + free space
|
||||
* \param length length of buffer "path"
|
||||
* \param newpart string containing path component to add to path
|
||||
* \return true on success
|
||||
*/
|
||||
|
||||
bool path_add_part(char *path, int length, char *newpart)
|
||||
{
|
||||
if(path[strlen(path)] != '\\')
|
||||
strncat(path, "\\", length);
|
||||
|
||||
strncat(path, newpart, length);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user