2001-10-24 10:30:29 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2001-04-10 04:18:12 +05:30
|
|
|
/*
|
2001-10-24 10:30:29 +05:30
|
|
|
* Utility routines.
|
2001-04-10 04:18:12 +05:30
|
|
|
*
|
2004-03-15 13:59:22 +05:30
|
|
|
* Copyright (C) many different people.
|
2003-07-15 02:51:08 +05:30
|
|
|
* If you wrote this, please acknowledge your work.
|
2001-10-24 10:30:29 +05:30
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2001-10-24 10:30:29 +05:30
|
|
|
*/
|
|
|
|
|
2008-05-07 17:48:48 +05:30
|
|
|
/* Concatenate path and filename to new allocated buffer.
|
|
|
|
* Add '/' only as needed (no duplicate // are produced).
|
|
|
|
* If path is NULL, it is assumed to be "/".
|
|
|
|
* filename should not be NULL.
|
|
|
|
*/
|
2001-04-10 04:18:12 +05:30
|
|
|
|
|
|
|
#include "libbb.h"
|
|
|
|
|
2008-06-27 08:22:20 +05:30
|
|
|
char* FAST_FUNC concat_path_file(const char *path, const char *filename)
|
2001-04-10 04:18:12 +05:30
|
|
|
{
|
2001-05-15 23:12:16 +05:30
|
|
|
char *lc;
|
2001-07-07 09:57:35 +05:30
|
|
|
|
|
|
|
if (!path)
|
2005-05-10 03:21:15 +05:30
|
|
|
path = "";
|
2001-05-15 23:12:16 +05:30
|
|
|
lc = last_char_is(path, '/');
|
2001-08-02 10:32:46 +05:30
|
|
|
while (*filename == '/')
|
2001-05-08 04:31:32 +05:30
|
|
|
filename++;
|
2006-08-03 21:11:12 +05:30
|
|
|
return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
|
2001-04-10 04:18:12 +05:30
|
|
|
}
|