1/*
2 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _DISK_DEVICE_UTILS_H
6#define _DISK_DEVICE_UTILS_H
7
8#include <stdlib.h>
9#include <string.h>
10
11#include <SupportDefs.h>
12
13
14namespace BPrivate {
15
16
17// set_string
18static inline status_t
19set_string(char*& location, const char* newString)
20{
21	char* string = NULL;
22	if (newString) {
23		string = strdup(newString);
24		if (!string)
25			return B_NO_MEMORY;
26	}
27
28	free(location);
29	location = string;
30
31	return B_OK;
32}
33
34
35#define SET_STRING_RETURN_ON_ERROR(location, string)	\
36{														\
37	status_t error = set_string(location, string);		\
38	if (error != B_OK)									\
39		return error;									\
40}
41
42
43static inline int
44compare_string(const char* a, const char* b)
45{
46	if (a == NULL)
47		return (b == NULL ? 0 : -1);
48	if (b == NULL)
49		return 1;
50	return strcmp(a, b);
51}
52
53
54}	// namespace BPrivate
55
56using BPrivate::set_string;
57using BPrivate::compare_string;
58
59#endif	// _DISK_DEVICE_UTILS_H
60