2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $XConsortium: funcs.h /main/12 1996/09/13 20:48:55 cde-hal $
26 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
55 #if !defined(__osf__) && !defined(linux) && \
56 !defined(CSRG_BASED) && !defined(sun)
59 #if defined(hpux) || defined(sgi) ||defined(__osf__) || \
60 defined(linux) || defined(CSRG_BASED) || defined(sun)
68 #include <sys/types.h>
72 #include "utility/c_stream.h"
73 #include "utility/c_fstream.h"
74 #include "utility/c_stringstream.h"
86 // centerline does not define these
87 #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
88 #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
92 #include "utility/debug.h"
93 #include "utility/types.h"
94 #include "utility/const.h"
95 #include "utility/macro.h"
96 #include "utility/mmdb_exception.h"
99 /* no C++ version of <strings.h>, C version causes conflicts */
101 extern int strcasecmp(const char *, const char *);
102 extern int strncasecmp(const char *, const char *, size_t);
106 int gethostname(char* name, int namelen);
109 int compare_stream(ostringstream& x, ostringstream& y);
111 char * cuserid(char *s);
114 inline float flog2(unsigned int x) {
115 return (float)(log((double)x) / log((double)2));
119 }; // return log_2(x)
120 #endif /* (__osf__) */
122 inline float flog2(const float x) {
123 return (float)log((double)x) / (float)log((float)2);
128 #endif /* (__osf__) */
130 inline int pow2(const int x) {
131 return (int)pow((double)2, (double)x);
136 #endif /* (__osf__) */
138 inline int pow2(const float x) {
139 return (int)pow((double)2, (double)x);
144 #endif /* (__osf__) */
146 int pos_of_LSB(const unsigned int x); // position of the MSB
148 int ceiling(const float); // ceiling of x
149 unsigned getbits(unsigned, unsigned, unsigned);
151 inline void char_swap(char& c1, char& c2) {
152 char tmp = c1; c1 = c2; c2 = tmp;
154 } // switch two chars
156 }; // switch two chars
157 #endif /* (__osf__) */
159 inline void short_swap(short& s1, short& s2) {
160 short tmp = s1; s1 = s2; s2 = tmp;
162 }// switch two shorts
164 };// switch two shorts
165 #endif /* (__osf__) */
167 inline void int_swap(int& i1, int& i2) {
168 int tmp = i1; i1 = i2; i2 = tmp;
172 }; // switch two ints
173 #endif /* (__osf__) */
177 int del_file(const char* file_nm, const char* path_nm = 0);
179 Boolean copy_file(const char* source, const char* sink);
180 Boolean copy_file(const char* path, const char* filenm,
181 const char* source_ext, const char* target_ext);
183 Boolean exist_file(const char* name, const char* path = 0);
184 Boolean cat_file(const char* source1, const char* source2,
186 int check_file(istream&, const char* msg = "");
188 Boolean exist_dir(const char* path);
189 Boolean check_and_create_dir(const char* path);
191 int open_file_prot();
195 Boolean cc_is_digit(istream&); // "cc" stands for current char
197 unsigned long disk_space(const char* path);
198 char* access_info( char* request );
200 Boolean int_eq(void*, void*);
201 Boolean int_ls(void*, void*);
203 // return an lease largest int of x, the returned value is
204 // also a multiple of sizeof(void*)
208 enum lock_t { SHARED, EXCLUSIVE };
210 Boolean fcntl_lock( int fd, lock_t lt );
211 Boolean fcntl_unlock( int fd );
213 Boolean timed_lock( int fd, lock_t lt, int seconds = 5);
214 Boolean timed_unlock( int fd, int seconds = 5);
225 int bytes(char* file_name);
227 char* form(const char* ...);
229 // lsb is considered as the 0th bit
230 void lsb_putbits(unsigned& target, unsigned position_from_lsb,
231 unsigned bits, unsigned source);
232 unsigned lsb_getbits(unsigned source, unsigned position_from_lsb, unsigned bits);
234 Boolean writeToTmpFile(char* unique_nm, char* str, int size);