Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 2 | /* |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 3 | * Utility routines. |
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) many different people. |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 6 | * If you wrote this, please acknowledge your work. |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 9 | */ |
Denys Vlasenko | ebe6d9d | 2017-10-05 14:40:24 +0200 | [diff] [blame] | 10 | #include "libbb.h" |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 11 | |
Denis Vlasenko | 6bf05cf | 2008-05-07 12:18:48 +0000 | [diff] [blame] | 12 | /* Concatenate path and filename to new allocated buffer. |
13 | * Add '/' only as needed (no duplicate // are produced). | ||||
14 | * If path is NULL, it is assumed to be "/". | ||||
15 | * filename should not be NULL. | ||||
16 | */ | ||||
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 17 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 18 | char* FAST_FUNC concat_path_file(const char *path, const char *filename) |
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 19 | { |
Eric Andersen | c911a43 | 2001-05-15 17:42:16 +0000 | [diff] [blame] | 20 | char *lc; |
Eric Andersen | 5a071bc | 2001-07-07 04:27:35 +0000 | [diff] [blame] | 21 | |
22 | if (!path) | ||||
Mike Frysinger | 9dc93ac | 2005-05-09 21:51:15 +0000 | [diff] [blame] | 23 | path = ""; |
Eric Andersen | c911a43 | 2001-05-15 17:42:16 +0000 | [diff] [blame] | 24 | lc = last_char_is(path, '/'); |
Eric Andersen | 3450636 | 2001-08-02 05:02:46 +0000 | [diff] [blame] | 25 | while (*filename == '/') |
Eric Andersen | 4ad13e5 | 2001-05-07 23:01:32 +0000 | [diff] [blame] | 26 | filename++; |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 27 | return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename); |
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 28 | } |