-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
119 lines (89 loc) · 3.1 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Thomas Pantzer: utils.h, v0.1b 28.1.98 18:6
*
*
* Copyright 1998 by Thomas Pantzer
*
* Permission to use, copy, modify, and distribute this software for noncommercial
* use and without fee is hereby granted, provided that the above copyright notice
* appear in all copies and that both that copyright notice and this permission
* notice appear in supporting documentation, and that the name of the Author not be
* used in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. The Author makes no representations about
* the suitability of this software for any purpose. It is provided "as is"
* without expressed or implied warranty.
*
*
* pantec@aix520.informatik.uni-leipzig.de (Thomas Pantzer)
*
*/
#ifndef _UTILS_H
#define _UTILS_H
#include <sys/types.h>
/* #include <sys/socket.h> */
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "tns_util/win32_export.h"
#if _WINDOWS | WIN32
#else
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
extern int __max(int a, int b);
extern int __min(int a, int b);
#endif
TNS_UTIL_API int FD_Ready(int fd);
TNS_UTIL_API int FD_ReadyTo(int fd, int to);
TNS_UTIL_API int FD_Writeable(int fd);
TNS_UTIL_API bool fexist(char *s); // return true if file "s" exists
TNS_UTIL_API long int filelen(char *s); // return -1 if file doesnt exist
TNS_UTIL_API char test_dir(char *s); // true if s is a directory
TNS_UTIL_API char strnrcmp(char *s1, char *s2, unsigned int len);
TNS_UTIL_API long power(int base, int exp);
// #define pow2(x) power(2,x)
#define pow2(x) (1 << x)
TNS_UTIL_API int log2(int q);
TNS_UTIL_API void print_kM(double d);
TNS_UTIL_API char *sprint_kM(double d, char *buf);
// print a number in %3.1f format with proper unit prefixes to stdout
TNS_UTIL_API char *strip_slash(char *fullpath); // basename()
TNS_UTIL_API int fileRead(const char *fn_arg, char *buffer, int len);
TNS_UTIL_API int fileReadInt(const char *fn);
TNS_UTIL_API int getIntFromEnv(const char *name, int defaultValue);
TNS_UTIL_API float getFloatFromEnv(const char *name, float defaultValue);
TNS_UTIL_API bool getBoolFromEnv(const char *name, bool defaultValue);
//extern void ErrorMsg(const char st[]);
#define ErrorMsg(x, y) {fprintf(stderr,"%s: %s\n", x, strerror(y)); }
//extern void ErrorMsg(const char st[],int n);
#ifdef AIX
#include <sys/select.h>
#endif
// #ifndef FD_SET
//
// // AIX comes here
// typedef struct fd_set { int fds_bits[1]; } fd_set;
//
// #define FD_SETSIZE (sizeof (fd_set) * 8)
// #define FD_SET(f,s) ((s)->fds_bits[0] |= (1 << (f)))
// #define FD_CLR(f,s) ((s)->fds_bits[0] &= ~(1 << (f)))
// #define FD_ISSET(f,s) ((s)->fds_bits[0] & (1 << (f)))
// #define FD_ZERO(s) ((s)->fds_bits[0] = 0)
//
// #endif
#ifndef linux
#ifdef sun
/* the probles is probaly gone now
// I can't find the header file for this, but it exists
extern "C" {
extern void usleep(unsigned int);
}
*/
#else
#ifdef hpux
extern void usleep(long int i);
#endif
#endif
#endif
#include "tns_util/copyright.h"
#endif