/*1* Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License as5* published by the Free Software Foundation; either version 2 of the6* License, or (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program; if not, write to the Free Software15* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-130716* USA17*/1819#include <stdio.h>20#include <stdlib.h>21#include <stdarg.h>22#include <string.h>2324#include "util.h"2526char *xstrdup(const char *s)27{28int len = strlen(s) + 1;29char *dup = xmalloc(len);3031memcpy(dup, s, len);3233return dup;34}3536char *join_path(const char *path, const char *name)37{38int lenp = strlen(path);39int lenn = strlen(name);40int len;41int needslash = 1;42char *str;4344len = lenp + lenn + 2;45if ((lenp > 0) && (path[lenp-1] == '/')) {46needslash = 0;47len--;48}4950str = xmalloc(len);51memcpy(str, path, lenp);52if (needslash) {53str[lenp] = '/';54lenp++;55}56memcpy(str+lenp, name, lenn+1);57return str;58}596061