00001 /********************************************************************** 00002 Various utilities 00003 00004 (c) 1994, 1995 Innobase Oy 00005 00006 Created 1/20/1994 Heikki Tuuri 00007 ***********************************************************************/ 00008 00009 #ifndef ut0ut_h 00010 #define ut0ut_h 00011 00012 #include "univ.i" 00013 #include <time.h> 00014 #ifndef MYSQL_SERVER 00015 #include <ctype.h> 00016 #endif 00017 00018 typedef time_t ib_time_t; 00019 00020 /************************************************************ 00021 Gets the high 32 bits in a ulint. That is makes a shift >> 32, 00022 but since there seem to be compiler bugs in both gcc and Visual C++, 00023 we do this by a special conversion. */ 00024 00025 ulint 00026 ut_get_high32( 00027 /*==========*/ 00028 /* out: a >> 32 */ 00029 ulint a); /* in: ulint */ 00030 /********************************************************** 00031 Calculates the minimum of two ulints. */ 00032 UNIV_INLINE 00033 ulint 00034 ut_min( 00035 /*===*/ 00036 /* out: minimum */ 00037 ulint n1, /* in: first number */ 00038 ulint n2); /* in: second number */ 00039 /********************************************************** 00040 Calculates the maximum of two ulints. */ 00041 UNIV_INLINE 00042 ulint 00043 ut_max( 00044 /*===*/ 00045 /* out: maximum */ 00046 ulint n1, /* in: first number */ 00047 ulint n2); /* in: second number */ 00048 /******************************************************************** 00049 Calculates minimum of two ulint-pairs. */ 00050 UNIV_INLINE 00051 void 00052 ut_pair_min( 00053 /*========*/ 00054 ulint* a, /* out: more significant part of minimum */ 00055 ulint* b, /* out: less significant part of minimum */ 00056 ulint a1, /* in: more significant part of first pair */ 00057 ulint b1, /* in: less significant part of first pair */ 00058 ulint a2, /* in: more significant part of second pair */ 00059 ulint b2); /* in: less significant part of second pair */ 00060 /********************************************************** 00061 Compares two ulints. */ 00062 UNIV_INLINE 00063 int 00064 ut_ulint_cmp( 00065 /*=========*/ 00066 /* out: 1 if a > b, 0 if a == b, -1 if a < b */ 00067 ulint a, /* in: ulint */ 00068 ulint b); /* in: ulint */ 00069 /*********************************************************** 00070 Compares two pairs of ulints. */ 00071 UNIV_INLINE 00072 int 00073 ut_pair_cmp( 00074 /*========*/ 00075 /* out: -1 if a < b, 0 if a == b, 00076 1 if a > b */ 00077 ulint a1, /* in: more significant part of first pair */ 00078 ulint a2, /* in: less significant part of first pair */ 00079 ulint b1, /* in: more significant part of second pair */ 00080 ulint b2); /* in: less significant part of second pair */ 00081 /***************************************************************** 00082 Calculates fast the remainder when divided by a power of two. */ 00083 UNIV_INLINE 00084 ulint 00085 ut_2pow_remainder( 00086 /*==============*/ /* out: remainder */ 00087 ulint n, /* in: number to be divided */ 00088 ulint m); /* in: divisor; power of 2 */ 00089 /***************************************************************** 00090 Calculates fast value rounded to a multiple of a power of 2. */ 00091 UNIV_INLINE 00092 ulint 00093 ut_2pow_round( 00094 /*==========*/ /* out: value of n rounded down to nearest 00095 multiple of m */ 00096 ulint n, /* in: number to be rounded */ 00097 ulint m); /* in: divisor; power of 2 */ 00098 /***************************************************************** 00099 Calculates fast the 2-logarithm of a number, rounded upward to an 00100 integer. */ 00101 UNIV_INLINE 00102 ulint 00103 ut_2_log( 00104 /*=====*/ 00105 /* out: logarithm in the base 2, rounded upward */ 00106 ulint n); /* in: number */ 00107 /***************************************************************** 00108 Calculates 2 to power n. */ 00109 UNIV_INLINE 00110 ulint 00111 ut_2_exp( 00112 /*=====*/ 00113 /* out: 2 to power n */ 00114 ulint n); /* in: number */ 00115 /***************************************************************** 00116 Calculates fast the number rounded up to the nearest power of 2. */ 00117 00118 ulint 00119 ut_2_power_up( 00120 /*==========*/ 00121 /* out: first power of 2 which is >= n */ 00122 ulint n); /* in: number != 0 */ 00123 /**************************************************************** 00124 Sort function for ulint arrays. */ 00125 00126 void 00127 ut_ulint_sort(ulint* arr, ulint* aux_arr, ulint low, ulint high); 00128 /*============================================================*/ 00129 /************************************************************ 00130 The following function returns elapsed CPU time in milliseconds. */ 00131 00132 ulint 00133 ut_clock(void); 00134 /************************************************************** 00135 Returns system time. We do not specify the format of the time returned: 00136 the only way to manipulate it is to use the function ut_difftime. */ 00137 00138 ib_time_t 00139 ut_time(void); 00140 /*=========*/ 00141 /************************************************************** 00142 Returns system time. */ 00143 00144 void 00145 ut_usectime( 00146 /*========*/ 00147 ulint* sec, /* out: seconds since the Epoch */ 00148 ulint* ms); /* out: microseconds since the Epoch+*sec */ 00149 /************************************************************** 00150 Returns the difference of two times in seconds. */ 00151 00152 double 00153 ut_difftime( 00154 /*========*/ 00155 /* out: time2 - time1 expressed in seconds */ 00156 ib_time_t time2, /* in: time */ 00157 ib_time_t time1); /* in: time */ 00158 /************************************************************** 00159 Prints a timestamp to a file. */ 00160 00161 void 00162 ut_print_timestamp( 00163 /*===============*/ 00164 FILE* file); /* in: file where to print */ 00165 /************************************************************** 00166 Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */ 00167 00168 void 00169 ut_sprintf_timestamp( 00170 /*=================*/ 00171 char* buf); /* in: buffer where to sprintf */ 00172 /************************************************************** 00173 Sprintfs a timestamp to a buffer with no spaces and with ':' characters 00174 replaced by '_'. */ 00175 00176 void 00177 ut_sprintf_timestamp_without_extra_chars( 00178 /*=====================================*/ 00179 char* buf); /* in: buffer where to sprintf */ 00180 /************************************************************** 00181 Returns current year, month, day. */ 00182 00183 void 00184 ut_get_year_month_day( 00185 /*==================*/ 00186 ulint* year, /* out: current year */ 00187 ulint* month, /* out: month */ 00188 ulint* day); /* out: day */ 00189 /***************************************************************** 00190 Runs an idle loop on CPU. The argument gives the desired delay 00191 in microseconds on 100 MHz Pentium + Visual C++. */ 00192 00193 ulint 00194 ut_delay( 00195 /*=====*/ 00196 /* out: dummy value */ 00197 ulint delay); /* in: delay in microseconds on 100 MHz Pentium */ 00198 /***************************************************************** 00199 Prints the contents of a memory buffer in hex and ascii. */ 00200 00201 void 00202 ut_print_buf( 00203 /*=========*/ 00204 FILE* file, /* in: file where to print */ 00205 const void* buf, /* in: memory buffer */ 00206 ulint len); /* in: length of the buffer */ 00207 00208 /************************************************************************** 00209 Outputs a NUL-terminated file name, quoted with apostrophes. */ 00210 00211 void 00212 ut_print_filename( 00213 /*==============*/ 00214 FILE* f, /* in: output stream */ 00215 const char* name); /* in: name to print */ 00216 00217 /* Forward declaration of transaction handle */ 00218 struct trx_struct; 00219 00220 /************************************************************************** 00221 Outputs a NUL-terminated string, quoted as an SQL identifier. */ 00222 00223 void 00224 ut_print_name( 00225 /*==========*/ 00226 FILE* f, /* in: output stream */ 00227 struct trx_struct*trx, /* in: transaction */ 00228 ibool table_id,/* in: TRUE=print a table name, 00229 FALSE=print other identifier */ 00230 const char* name); /* in: name to print */ 00231 00232 /************************************************************************** 00233 Outputs a fixed-length string, quoted as an SQL identifier. */ 00234 00235 void 00236 ut_print_namel( 00237 /*===========*/ 00238 FILE* f, /* in: output stream */ 00239 struct trx_struct*trx, /* in: transaction (NULL=no quotes) */ 00240 ibool table_id,/* in: TRUE=print a table name, 00241 FALSE=print other identifier */ 00242 const char* name, /* in: name to print */ 00243 ulint namelen);/* in: length of name */ 00244 00245 /************************************************************************** 00246 Catenate files. */ 00247 00248 void 00249 ut_copy_file( 00250 /*=========*/ 00251 FILE* dest, /* in: output file */ 00252 FILE* src); /* in: input file to be appended to output */ 00253 00254 #ifndef UNIV_NONINL 00255 #include "ut0ut.ic" 00256 #endif 00257 00258 #endif 00259
1.4.7

