librazor/util.c
changeset 457 51a084acef49
parent 447 0a5e583393e1
child 458 3f841a46eab5
     1.1 --- a/librazor/util.c	Tue Sep 09 15:27:12 2014 +0100
     1.2 +++ b/librazor/util.c	Fri Oct 17 10:08:28 2014 +0100
     1.3 @@ -344,24 +344,6 @@
     1.4  	return concat;
     1.5  }
     1.6  
     1.7 -/**
     1.8 - * razor_path_add_root:
     1.9 - *
    1.10 - * Adds a root to a path. path must be an absolute pathname. In POSIX
    1.11 - * environments this is equivalent to the concationation of root and path.
    1.12 - * In Microsoft Windows an adjustment may need to be made for a drive letter
    1.13 - * in path (which will be dropped).
    1.14 - *
    1.15 - * Returns: The new pathname.
    1.16 - **/
    1.17 -RAZOR_EXPORT char *razor_path_add_root(const char *path, const char *root)
    1.18 -{
    1.19 -	if (root && *root)
    1.20 -		return razor_concat(root, SKIP_DRIVE_LETTER(path), NULL);
    1.21 -	else
    1.22 -		return strdup(path);
    1.23 -}
    1.24 -
    1.25  RAZOR_EXPORT const char *razor_system_arch(void)
    1.26  {
    1.27  #ifdef MSWIN_API
    1.28 @@ -394,12 +376,15 @@
    1.29  	int n;
    1.30  	char *utf8;
    1.31  
    1.32 +	if (len == 0)
    1.33 +		return strdup("");
    1.34 +
    1.35  	n = WideCharToMultiByte(CP_UTF8, 0, utf16, len, NULL, 0, NULL, NULL);
    1.36 -	if (len >= 0 && utf16[len])
    1.37 +	if (len > 0)
    1.38  		n++;
    1.39  	utf8 = malloc(n);
    1.40  	(void)WideCharToMultiByte(CP_UTF8, 0, utf16, len, utf8, n, NULL, NULL);
    1.41 -	if (len >= 0 && utf16[len])
    1.42 +	if (len > 0)
    1.43  		utf8[n - 1] = 0;
    1.44  
    1.45  	return utf8;
    1.46 @@ -410,12 +395,17 @@
    1.47  	int n;
    1.48  	wchar_t *utf16;
    1.49  
    1.50 +	if (len == 0) {
    1.51 +		utf16 = calloc(1, sizeof(wchar_t));
    1.52 +		return utf16;
    1.53 +	}
    1.54 +
    1.55  	n = MultiByteToWideChar(CP_UTF8, 0, utf8, len, NULL, 0);
    1.56 -	if (len >= 0 && utf8[len])
    1.57 +	if (len > 0)
    1.58  		n++;
    1.59  	utf16 = malloc(n * sizeof(wchar_t));
    1.60  	(void)MultiByteToWideChar(CP_UTF8, 0, utf8, len, utf16, n);
    1.61 -	if (len >= 0 && utf8[len])
    1.62 +	if (len > 0)
    1.63  		utf16[n - 1] = 0;
    1.64  
    1.65  	return utf16;