bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
os_utils.h
1/*
2 * FILENAME: os_utils.h
3 *
4 * CAVEAT:
5 * No claims are made as to the suitability of the accompanying
6 * source code for any purpose. Although this source code has been
7 * used by the NOAA, no warranty, expressed or implied, is made by
8 * NOAA or the United States Government as to the accuracy and
9 * functioning of this source code, nor shall the fact of distribution
10 * constitute any such endorsement, and no responsibility is assumed
11 * by NOAA in connection therewith. The source code contained
12 * within was developed by an agency of the U.S. Government.
13 * NOAA's National Geophysical Data Center has no objection to the
14 * use of this source code for any purpose since it is not subject to
15 * copyright protection in the U.S. If this source code is incorporated
16 * into other software, a statement identifying this source code may be
17 * required under 17 U.S.C. 403 to appear with any copyright notice.
18 */
19
20#ifndef OS_UTILS_H__
21#define OS_UTILS_H__
22
23#define UNIX_EOL_STRING "\n"
24#define UNIX_EOL_LENGTH 1
25
26#define MAC_EOL_STRING "\r"
27#define MAC_EOL_LENGTH 1
28
29#define DOS_EOL_STRING "\r\n"
30#define DOS_EOL_LENGTH 2
31
32#if FF_OS == FF_OS_UNIX
33
34#define NATIVE_EOL_STRING UNIX_EOL_STRING
35#define NATIVE_EOL_LENGTH UNIX_EOL_LENGTH
36
37#endif /* #if FF_CC == FF_CC_UNIX */
38
39#if FF_OS == FF_OS_MAC
40
41#define NATIVE_EOL_STRING MAC_EOL_STRING
42#define NATIVE_EOL_LENGTH MAC_EOL_LENGTH
43
44#endif /* FF_CC == FF_CC_MACCW */
45
46#if FF_OS == FF_OS_DOS
47
48#define NATIVE_EOL_STRING DOS_EOL_STRING
49#define NATIVE_EOL_LENGTH DOS_EOL_LENGTH
50
51#endif /* FF_CC == FF_CC_MSVC1 || FF_CC == FF_CC_MSVC4 */
52
53#if FF_CC == FF_CC_UNIX
54#define osf_strcmp strcmp
55#endif
56
57#if FF_CC == FF_CC_MACCW
58Handle PathNameFromFSSpec(FSSpecPtr myFSSPtr);
59#define osf_strcmp os_strcmpi
60#endif
61
62#if FF_CC == FF_CC_MSVC1 || FF_CC == FF_CC_MSVC4
63#define osf_strcmp os_strcmpi
64#endif
65
66#ifndef max /* maximum macro */
67#define max(a,b) ((a) > (b) ? (a) : (b))
68#endif
69
70#ifndef min /* minimum macro */
71#define min(a,b) ((a) < (b) ? (a) : (b))
72#endif
73
74#ifndef ROUND
75/* usage: int_var = (int_var_type)ROUND(expr); -- expr should be floating point type */
76#define ROUND(a) ((a) < 0 ? ceil((a) - 0.5 - DOUBLE_UP) : floor((a) + 0.5 + DOUBLE_UP))
77#else
78#error "ROUND macro is already defined -- contact support"
79#endif
80
81#ifndef TRUNC
82#define TRUNC(a) ((a) < 0 ? ceil(a) : floor(a))
83#else
84#error "TRUNC macro is already defined -- contact support"
85#endif
86
87#define FF_STRLEN(a) ((a)?strlen(a):0)
88#define ok_strlen(a) FF_STRLEN(a) /* phase this out */
89
90#define FF_SUBSTRCMP(a,b) (((a)&&(b))?strncmp(a,b,min(FF_STRLEN(a),FF_STRLEN(b))):1)
91
92#define OS_INVERSE_ESCAPE 0
93#define OS_NORMAL_ESCAPE 1
94
95#define UNION_EOL_CHARS "\x0a\x0d"
96
97#define WHITESPACE "\x09\x0a\x0b\x0c\x0d\x20"
98#define LINESPACE "\x09\x0b\x0c\x20"
99
100/* casts below are to ensure logical, rather than arithmetic, bit shifts */
101#define FLIP_4_BYTES(a) ( (((a) & 0x000000FFu) << 24) | \
102 (((a) & 0x0000FF00u) << 8) | \
103 (((unsigned long)(a) & 0x00FF0000u) >> 8) | \
104 (((unsigned long)(a) & 0xFF000000u) >> 24) )
105
106#define FLIP_2_BYTES(a) ( (((unsigned short)(a) & 0xFF00u) >> 8) | \
107 (((a) & 0x00FFu) << 8) )
108
109/* prototypes for functions in os_utils.c */
110
111#ifndef _BOOLEAN_DEFINED
112#define _BOOLEAN_DEFINED
113
114#ifndef _WINNT_ /* specific to MSVC++ 4.0 */
115typedef short BOOLEAN; /* Boolean type */
116#endif
117#endif /* _BOOLEAN_DEFINED 3/25/99 jhrg */
118
119#ifdef TRUE
120#undef TRUE
121#endif
122#define TRUE 1
123#ifdef FALSE
124#undef FALSE
125#endif
126#define FALSE 0
127
128char *os_strlwr(char *string);
129char *os_strupr(char *);
130unsigned long os_filelength(char *filename);
131BOOLEAN os_file_exist(char *filename);
132int os_strcmpi(const char* s1, const char* s2);
133int os_strncmpi(const char* s1, const char* s2, size_t n);
134
135#if FF_OS == FF_OS_MAC
136void *os_mac_load_env(char * buffer); /* -rf02,-rf03 */
137#endif
138
139char *os_get_env(char *variable_name);
140
141int os_path_cmp_paths(char *s, char *t);
142BOOLEAN os_path_is_native(char *path);
143char *os_path_make_native(char *native_path, char *path);
144void os_path_find_parts(char *path, char **pathname, char **filename, char **fileext);
145void os_path_find_parent(char *path, char **parentdir);
146char *os_path_return_ext(char *pfname);
147char *os_path_return_name(char *pfname);
148char *os_path_return_path(char *pfname);
149void os_path_get_parts(char *path, char *pathname, char *filename, char *fileext);
150char *os_path_put_parts(char *fullpath, char *dirpath, char *filename, char *fileext);
151void os_str_replace_char(char *string, char oldc, char newc);
152BOOLEAN os_path_prepend_special(char *in_name, char *home_path, char *out_name);
153char *os_str_trim_whitespace(char *dest, char *source);
154char *os_str_trim_linespace(char *line);
155void os_str_replace_unescaped_char1_with_char2(char char1, char char2, char *str);
156void os_str_replace_escaped_char1_with_char2(const char escape, char char1, char char2, char *str);
157
158char *os_strdup(char *);
159char *os_strrstr(const char *s1, const char *s2);
160#endif /* (NOT) OS_UTILS_H__ */
161