vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / add-ons / icu / ICUThreadLocalStorageValue.cpp
blobe671f29667d3781c62b2093cabe0eac55152d7da
1 /*
2 * Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "ICUThreadLocalStorageValue.h"
9 #include <new>
11 #include <unicode/ucnv.h>
14 namespace BPrivate {
15 namespace Libroot {
18 ICUThreadLocalStorageValue::ICUThreadLocalStorageValue()
19 : converter(NULL)
21 charset[0] = '\0';
25 ICUThreadLocalStorageValue::~ICUThreadLocalStorageValue()
27 if (converter != NULL)
28 ucnv_close(converter);
32 status_t
33 ICUThreadLocalStorageValue::GetInstanceForKey(pthread_key_t tlsKey,
34 ICUThreadLocalStorageValue*& instanceOut)
36 ICUThreadLocalStorageValue* tlsValue = NULL;
37 void* value = pthread_getspecific(tlsKey);
38 if (value == NULL) {
39 tlsValue = new (std::nothrow) ICUThreadLocalStorageValue();
40 if (tlsValue == NULL)
41 return B_NO_MEMORY;
42 pthread_setspecific(tlsKey, tlsValue);
43 } else
44 tlsValue = static_cast<ICUThreadLocalStorageValue*>(value);
46 instanceOut = tlsValue;
48 return B_OK;
52 } // namespace Libroot
53 } // namespace BPrivate