1/*
2******************************************************************************
3*
4* Copyright (C) 1997-2014, International Business Machines
5* Corporation and others. All Rights Reserved.
6*
7******************************************************************************
8*
9* FILE NAME : putil.h
10*
11* Date Name Description
12* 05/14/98 nos Creation (content moved here from utypes.h).
13* 06/17/99 erm Added IEEE_754
14* 07/22/98 stephen Added IEEEremainder, max, min, trunc
15* 08/13/98 stephen Added isNegativeInfinity, isPositiveInfinity
16* 08/24/98 stephen Added longBitsFromDouble
17* 03/02/99 stephen Removed openFile(). Added AS400 support.
18* 04/15/99 stephen Converted to C
19* 11/15/99 helena Integrated S/390 changes for IEEE support.
20* 01/11/00 helena Added u_getVersion.
21******************************************************************************
22*/
23
24#ifndef PUTIL_H
25#define PUTIL_H
26
27#include "unicode/utypes.h"
28 /**
29 * \file
30 * \brief C API: Platform Utilities
31 */
32
33/*==========================================================================*/
34/* Platform utilities */
35/*==========================================================================*/
36
37/**
38 * Platform utilities isolates the platform dependencies of the
39 * libarary. For each platform which this code is ported to, these
40 * functions may have to be re-implemented.
41 */
42
43/**
44 * Return the ICU data directory.
45 * The data directory is where common format ICU data files (.dat files)
46 * are loaded from. Note that normal use of the built-in ICU
47 * facilities does not require loading of an external data file;
48 * unless you are adding custom data to ICU, the data directory
49 * does not need to be set.
50 *
51 * The data directory is determined as follows:
52 * If u_setDataDirectory() has been called, that is it, otherwise
53 * if the ICU_DATA environment variable is set, use that, otherwise
54 * If a data directory was specifed at ICU build time
55 * <code>
56 * \code
57 * #define ICU_DATA_DIR "path"
58 * \endcode
59 * </code> use that,
60 * otherwise no data directory is available.
61 *
62 * @return the data directory, or an empty string ("") if no data directory has
63 * been specified.
64 *
65 * @stable ICU 2.0
66 */
67U_STABLE const char* U_EXPORT2 u_getDataDirectory(void);
68
69
70/**
71 * Set the ICU data directory.
72 * The data directory is where common format ICU data files (.dat files)
73 * are loaded from. Note that normal use of the built-in ICU
74 * facilities does not require loading of an external data file;
75 * unless you are adding custom data to ICU, the data directory
76 * does not need to be set.
77 *
78 * This function should be called at most once in a process, before the
79 * first ICU operation (e.g., u_init()) that will require the loading of an
80 * ICU data file.
81 * This function is not thread-safe. Use it before calling ICU APIs from
82 * multiple threads.
83 *
84 * @param directory The directory to be set.
85 *
86 * @see u_init
87 * @stable ICU 2.0
88 */
89U_STABLE void U_EXPORT2 u_setDataDirectory(const char *directory);
90
91#ifndef U_HIDE_INTERNAL_API
92/**
93 * Return the time zone files override directory, or an empty string if
94 * no directory was specified. Certain time zone resources will be preferrentially
95 * loaded from individual files in this directory.
96 *
97 * @return the time zone data override directory.
98 * @internal
99 */
100U_INTERNAL const char * U_EXPORT2 u_getTimeZoneFilesDirectory(UErrorCode *status);
101
102/**
103 * Set the time zone files override directory.
104 * This function is not thread safe; it must not be called concurrently with
105 * u_getTimeZoneFilesDirectory() or any other use of ICU time zone functions.
106 * This function should only be called before using any ICU service that
107 * will access the time zone data.
108 * @internal
109 */
110U_INTERNAL void U_EXPORT2 u_setTimeZoneFilesDirectory(const char *path, UErrorCode *status);
111#endif /* U_HIDE_INTERNAL_API */
112
113
114/**
115 * @{
116 * Filesystem file and path separator characters.
117 * Example: '/' and ':' on Unix, '\\' and ';' on Windows.
118 * @stable ICU 2.0
119 */
120#if U_PLATFORM_USES_ONLY_WIN32_API
121# define U_FILE_SEP_CHAR '\\'
122# define U_FILE_ALT_SEP_CHAR '/'
123# define U_PATH_SEP_CHAR ';'
124# define U_FILE_SEP_STRING "\\"
125# define U_FILE_ALT_SEP_STRING "/"
126# define U_PATH_SEP_STRING ";"
127#else
128# define U_FILE_SEP_CHAR '/'
129# define U_FILE_ALT_SEP_CHAR '/'
130# define U_PATH_SEP_CHAR ':'
131# define U_FILE_SEP_STRING "/"
132# define U_FILE_ALT_SEP_STRING "/"
133# define U_PATH_SEP_STRING ":"
134#endif
135
136/** @} */
137
138/**
139 * Convert char characters to UChar characters.
140 * This utility function is useful only for "invariant characters"
141 * that are encoded in the platform default encoding.
142 * They are a small, constant subset of the encoding and include
143 * just the latin letters, digits, and some punctuation.
144 * For details, see U_CHARSET_FAMILY.
145 *
146 * @param cs Input string, points to <code>length</code>
147 * character bytes from a subset of the platform encoding.
148 * @param us Output string, points to memory for <code>length</code>
149 * Unicode characters.
150 * @param length The number of characters to convert; this may
151 * include the terminating <code>NUL</code>.
152 *
153 * @see U_CHARSET_FAMILY
154 * @stable ICU 2.0
155 */
156U_STABLE void U_EXPORT2
157u_charsToUChars(const char *cs, UChar *us, int32_t length);
158
159/**
160 * Convert UChar characters to char characters.
161 * This utility function is useful only for "invariant characters"
162 * that can be encoded in the platform default encoding.
163 * They are a small, constant subset of the encoding and include
164 * just the latin letters, digits, and some punctuation.
165 * For details, see U_CHARSET_FAMILY.
166 *
167 * @param us Input string, points to <code>length</code>
168 * Unicode characters that can be encoded with the
169 * codepage-invariant subset of the platform encoding.
170 * @param cs Output string, points to memory for <code>length</code>
171 * character bytes.
172 * @param length The number of characters to convert; this may
173 * include the terminating <code>NUL</code>.
174 *
175 * @see U_CHARSET_FAMILY
176 * @stable ICU 2.0
177 */
178U_STABLE void U_EXPORT2
179u_UCharsToChars(const UChar *us, char *cs, int32_t length);
180
181#endif
182