#include "univ.i"
#include "db0err.h"
#include "os0sync.h"
#include <time.h>
#include <ctype.h>
#include <stdarg.h>
#include "ut0ut.ic"
Go to the source code of this file.
| 
Macros | 
| #define | TEMP_INDEX_PREFIX   '\377' | 
| #define | TEMP_INDEX_PREFIX_STR   "\377" | 
| #define | UT_RELAX_CPU()   ((void)0) /* avoid warning for an empty statement */ | 
| #define | UT_WAIT_FOR(cond, max_wait_us) | 
| #define | ut_is_2pow(n)   UNIV_LIKELY(!((n) & ((n) - 1))) | 
| #define | ut_2pow_remainder(n, m)   ((n) & ((m) - 1)) | 
| #define | ut_2pow_round(n, m)   ((n) & ~((m) - 1)) | 
| #define | ut_calc_align_down(n, m)   ut_2pow_round(n, m) | 
| #define | ut_calc_align(n, m)   (((n) + ((m) - 1)) & ~((m) - 1)) | 
| #define | UT_BITS_IN_BYTES(b)   (((b) + 7) / 8) | 
| #define | ut_vsnprintf(buf, size, fmt, ap)   ((void) vsnprintf(buf, size, fmt, ap)) | 
| #define | ut_snprintf   snprintf | 
| 
Functions | 
| template<class T > | 
| T | ut_min (T a, T b) | 
| template<class T > | 
| T | ut_max (T a, T b) | 
| UNIV_INLINE ulint | ut_min (ulint n1, ulint n2) | 
| UNIV_INLINE ulint | ut_max (ulint n1, ulint n2) | 
| UNIV_INLINE void | ut_pair_min (ulint *a, ulint *b, ulint a1, ulint b1, ulint a2, ulint b2) | 
| UNIV_INLINE int | ut_ulint_cmp (ulint a, ulint b) | 
| UNIV_INLINE int | ut_pair_cmp (ulint a1, ulint a2, ulint b1, ulint b2) | 
| UNIV_INLINE ulint | ut_2_log (ulint n) | 
| UNIV_INLINE ulint | ut_2_exp (ulint n) | 
| UNIV_INTERN ulint | ut_2_power_up (ulint n) __attribute__((const )) | 
| UNIV_INTERN ib_time_t | ut_time (void) | 
| UNIV_INTERN int | ut_usectime (ulint *sec, ulint *ms) | 
| UNIV_INTERN ullint | ut_time_us (ullint *tloc) | 
| UNIV_INTERN ulint | ut_time_ms (void) | 
| UNIV_INTERN double | ut_difftime (ib_time_t time2, ib_time_t time1) | 
| UNIV_INTERN void | ut_print_timestamp (FILE *file) UNIV_COLD __attribute__((nonnull)) | 
| UNIV_INTERN void | ut_sprintf_timestamp (char *buf) | 
| UNIV_INTERN ulint | ut_delay (ulint delay) | 
| UNIV_INTERN void | ut_print_buf (FILE *file, const void *buf, ulint len) | 
| UNIV_INTERN void | ut_print_filename (FILE *f, const char *name) | 
| UNIV_INTERN void | ut_print_name (FILE *f, const trx_t *trx, ibool table_id, const char *name) | 
| UNIV_INTERN void | ut_print_namel (FILE *f, const trx_t *trx, ibool table_id, const char *name, ulint namelen) | 
| UNIV_INTERN char * | ut_format_name (const char *name, ibool is_table, char *formatted, ulint formatted_size) | 
| UNIV_INTERN void | ut_copy_file (FILE *dest, FILE *src) | 
| UNIV_INTERN const char * | ut_strerr (dberr_t num) | 
| UNIV_INTERN void | ut_ulint_sort (ulint *arr, ulint *aux_arr, ulint low, ulint high) __attribute__((nonnull)) | 
Detailed Description
Various utilities
Created 1/20/1994 Heikki Tuuri 
Definition in file ut0ut.h.
Macro Definition Documentation
      
        
          | #define TEMP_INDEX_PREFIX   '\377' | 
      
 
Index name prefix in fast index creation 
Definition at line 47 of file ut0ut.h.
 
 
      
        
          | #define TEMP_INDEX_PREFIX_STR   "\377" | 
      
 
Index name prefix in fast index creation, as a string constant 
Definition at line 49 of file ut0ut.h.
 
 
      
        
          | #define ut_2pow_remainder | ( |  | n, | 
        
          |  |  |  | m | 
        
          |  | ) |  | ((n) & ((m) - 1)) | 
      
 
Calculates fast the remainder of n/m when m is a power of two. 
- Parameters
- 
  
    | n | in: numerator |  | m | in: denominator, must be a power of two |  
 
- Returns
- the remainder of n/m 
Definition at line 162 of file ut0ut.h.
 
 
      
        
          | #define ut_2pow_round | ( |  | n, | 
        
          |  |  |  | m | 
        
          |  | ) |  | ((n) & ~((m) - 1)) | 
      
 
Calculates the biggest multiple of m that is not bigger than n when m is a power of two. In other words, rounds n down to m * k. 
- Parameters
- 
  
    | n | in: number to round down |  | m | in: alignment, must be a power of two |  
 
- Returns
- n rounded down to the biggest possible integer multiple of m 
Definition at line 169 of file ut0ut.h.
 
 
      
        
          | #define UT_BITS_IN_BYTES | ( |  | b | ) | (((b) + 7) / 8) | 
      
 
Determine how many bytes (groups of 8 bits) are needed to
 store the given number of bits. 
- Parameters
- 
  
  
- Returns
- number of bytes (octets) needed to represent b 
Definition at line 213 of file ut0ut.h.
 
 
      
        
          | #define ut_calc_align | ( |  | n, | 
        
          |  |  |  | m | 
        
          |  | ) |  | (((n) + ((m) - 1)) & ~((m) - 1)) | 
      
 
Calculates the smallest multiple of m that is not smaller than n when m is a power of two. In other words, rounds n up to m * k. 
- Parameters
- 
  
    | n | in: number to round up |  | m | in: alignment, must be a power of two |  
 
- Returns
- n rounded up to the smallest possible integer multiple of m 
Definition at line 181 of file ut0ut.h.
 
 
Align a number down to a multiple of a power of two.
 - Parameters
- 
  
    | n | in: number to round down |  | m | in: alignment, must be a power of two |  
 
- Returns
- n rounded down to the biggest possible integer multiple of m 
Definition at line 174 of file ut0ut.h.
 
 
      
        
          | #define ut_is_2pow | ( |  | n | ) | UNIV_LIKELY(!((n) & ((n) - 1))) | 
      
 
Determines if a number is zero or a power of two. 
- Parameters
- 
  
  
- Returns
- nonzero if n is zero or a power of two; zero otherwise 
Definition at line 156 of file ut0ut.h.
 
 
      
        
          | #define ut_snprintf   snprintf | 
      
 
A wrapper for snprintf(3), formatted output conversion into a limited buffer. 
Definition at line 452 of file ut0ut.h.
 
 
A wrapper for vsnprintf(3), formatted output conversion into a limited buffer. Note: this function DOES NOT return the number of characters that would have been printed if the buffer was unlimited because VC's _vsnprintf() returns -1 in this case and we would need to call _vscprintf() in addition to estimate that but we would need another copy of "ap" for that and VC does not provide va_copy(). 
Definition at line 447 of file ut0ut.h.
 
 
      
        
          | #define UT_WAIT_FOR | ( |  | cond, | 
        
          |  |  |  | max_wait_us | 
        
          |  | ) |  |  | 
      
 
Value:do {                                                            \
        ullint  start_us;                                       \
        while (!(cond)                                          \
        }                                                       \
} while (0)
Delays execution for at most max_wait_us microseconds or returns earlier if cond becomes true. 
- Parameters
- 
  
    | cond | in: condition to wait for; evaluated every 2 ms |  | max_wait_us | in: maximum delay to wait, in microseconds |  
 
Definition at line 87 of file ut0ut.h.
 
 
Typedef Documentation
Time stamp 
Definition at line 52 of file ut0ut.h.
 
 
Function Documentation
      
        
          | UNIV_INLINE ulint ut_2_exp | ( | ulint | n | ) |  | 
      
 
Calculates 2 to power n. 
- Returns
- 2 to power n in: number 
 
 
      
        
          | UNIV_INLINE ulint ut_2_log | ( | ulint | n | ) |  | 
      
 
Calculates fast the 2-logarithm of a number, rounded upward to an integer. 
- Returns
- logarithm in the base 2, rounded upward in: number 
 
 
      
        
          | UNIV_INTERN ulint ut_2_power_up | ( | ulint | n | ) | const | 
      
 
Calculates fast the number rounded up to the nearest power of 2. 
- Returns
- first power of 2 which is >= n 
- Parameters
- 
  
  
 
 
      
        
          | UNIV_INTERN void ut_copy_file | ( | FILE * | dest, | 
        
          |  |  | FILE * | src | 
        
          |  | ) |  |  | 
      
 
Catenate files. in: input file to be appended to output
Catenate files. 
- Parameters
- 
  
    | dest | in: output file |  | src | in: input file to be appended to output |  
 
Definition at line 612 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN ulint ut_delay | ( | ulint | delay | ) |  | 
      
 
Runs an idle loop on CPU. The argument gives the desired delay in microseconds on 100 MHz Pentium + Visual C++. 
- Returns
- dummy value in: delay in microseconds on 100 MHz Pentium
Runs an idle loop on CPU. The argument gives the desired delay in microseconds on 100 MHz Pentium + Visual C++. 
- Returns
- dummy value 
- Parameters
- 
  
    | delay | in: delay in microseconds on 100 MHz Pentium |  
 
Definition at line 400 of file ut0ut.cc.
 
 
Returns the difference of two times in seconds. 
- Returns
- time2 - time1 expressed in seconds in: time
Returns the difference of two times in seconds. 
- Returns
- time2 - time1 expressed in seconds 
- Parameters
- 
  
    | time2 | in: time |  | time1 | in: time |  
 
Definition at line 204 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN char* ut_format_name | ( | const char * | name, | 
        
          |  |  | ibool | is_table, | 
        
          |  |  | char * | formatted, | 
        
          |  |  | ulint | formatted_size | 
        
          |  | ) |  |  | 
      
 
Formats a table or index name, quoted as an SQL identifier. If the name contains a slash '/', the result will contain two identifiers separated by a period (.), as in SQL database_name.identifier. 
- Returns
- pointer to 'formatted' out: no more than this number of bytes will be written to 'formatted'
Formats a table or index name, quoted as an SQL identifier. If the name contains a slash '/', the result will contain two identifiers separated by a period (.), as in SQL database_name.identifier. 
- Returns
- pointer to 'formatted' 
- Parameters
- 
  
    | name | in: table or index name, must be '\0'-terminated |  | is_table | in: if TRUE then 'name' is a table name |  | formatted | out: formatted result, will be '\0'-terminated |  | formatted_size | out: no more than this number of bytes will be written to 'formatted' |  
 
Definition at line 571 of file ut0ut.cc.
 
 
      
        
          | UNIV_INLINE ulint ut_max | ( | ulint | n1, | 
        
          |  |  | ulint | n2 | 
        
          |  | ) |  |  | 
      
 
Calculates the maximum of two ulints. 
- Returns
- maximum in: second number 
- Parameters
- 
  
  
 
 
      
        
          | UNIV_INLINE ulint ut_min | ( | ulint | n1, | 
        
          |  |  | ulint | n2 | 
        
          |  | ) |  |  | 
      
 
Calculates the minimum of two ulints. 
- Returns
- minimum in: second number 
- Parameters
- 
  
  
 
 
      
        
          | UNIV_INLINE int ut_pair_cmp | ( | ulint | a1, | 
        
          |  |  | ulint | a2, | 
        
          |  |  | ulint | b1, | 
        
          |  |  | ulint | b2 | 
        
          |  | ) |  |  | 
      
 
Compares two pairs of ulints. 
- Returns
- -1 if a < b, 0 if a == b, 1 if a > b in: less significant part of second pair 
- Parameters
- 
  
    | a1 | in: more significant part of first pair |  | a2 | in: less significant part of first pair |  | b1 | in: more significant part of second pair |  
 
 
 
      
        
          | UNIV_INLINE void ut_pair_min | ( | ulint * | a, | 
        
          |  |  | ulint * | b, | 
        
          |  |  | ulint | a1, | 
        
          |  |  | ulint | b1, | 
        
          |  |  | ulint | a2, | 
        
          |  |  | ulint | b2 | 
        
          |  | ) |  |  | 
      
 
Calculates minimum of two ulint-pairs. in: less significant part of second pair 
- Parameters
- 
  
    | a | out: more significant part of minimum |  | b | out: less significant part of minimum |  | a1 | in: more significant part of first pair |  | b1 | in: less significant part of first pair |  | a2 | in: more significant part of second pair |  
 
 
 
      
        
          | UNIV_INTERN void ut_print_buf | ( | FILE * | file, | 
        
          |  |  | const void * | buf, | 
        
          |  |  | ulint | len | 
        
          |  | ) |  |  | 
      
 
Prints the contents of a memory buffer in hex and ascii. in: length of the buffer
Prints the contents of a memory buffer in hex and ascii. 
- Parameters
- 
  
    | file | in: file where to print |  | buf | in: memory buffer |  | len | in: length of the buffer |  
 
Definition at line 425 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN void ut_print_filename | ( | FILE * | f, | 
        
          |  |  | const char * | name | 
        
          |  | ) |  |  | 
      
 
Outputs a NUL-terminated file name, quoted with apostrophes. in: name to print
Outputs a NUL-terminated file name, quoted with apostrophes. 
- Parameters
- 
  
    | f | in: output stream |  | name | in: name to print |  
 
Definition at line 495 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN void ut_print_name | ( | FILE * | f, | 
        
          |  |  | const trx_t * | trx, | 
        
          |  |  | ibool | table_id, | 
        
          |  |  | const char * | name | 
        
          |  | ) |  |  | 
      
 
Outputs a fixed-length string, quoted as an SQL identifier. If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier. in: name to print
Outputs a fixed-length string, quoted as an SQL identifier. If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier. 
- Parameters
- 
  
    | f | in: output stream |  | trx | in: transaction |  | table_id | in: TRUE=print a table name, FALSE=print other identifier |  | name | in: name to print |  
 
Definition at line 524 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN void ut_print_namel | ( | FILE * | f, | 
        
          |  |  | const trx_t * | trx, | 
        
          |  |  | ibool | table_id, | 
        
          |  |  | const char * | name, | 
        
          |  |  | ulint | namelen | 
        
          |  | ) |  |  | 
      
 
Outputs a fixed-length string, quoted as an SQL identifier. If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier. in: length of name
Outputs a fixed-length string, quoted as an SQL identifier. If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier. 
- Parameters
- 
  
    | f | in: output stream |  | trx | in: transaction (NULL=no quotes) |  | table_id | in: TRUE=print a table name, FALSE=print other identifier |  | name | in: name to print |  | namelen | in: length of name |  
 
Definition at line 542 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN void ut_print_timestamp | ( | FILE * | file | ) |  | 
      
 
Prints a timestamp to a file. 
- Parameters
- 
  
    | file | in: file where to print |  
 
Definition at line 218 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN void ut_sprintf_timestamp | ( | char * | buf | ) |  | 
      
 
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. in: buffer where to sprintf
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. 
- Parameters
- 
  
    | buf | in: buffer where to sprintf |  
 
Definition at line 271 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN const char* ut_strerr | ( | dberr_t | num | ) |  | 
      
 
Convert an error number to a human readable text message. The returned string is static and should not be freed or modified. 
- Returns
- string, describing the error in: error number
Convert an error number to a human readable text message. The returned string is static and should not be freed or modified. 
- Returns
- string, describing the error 
- Parameters
- 
  
  
Definition at line 702 of file ut0ut.cc.
 
 
Returns system time. We do not specify the format of the time returned: the only way to manipulate it is to use the function ut_difftime. 
- Returns
- system time 
Definition at line 107 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN ulint ut_time_ms | ( | void |  | ) |  | 
      
 
Returns the number of milliseconds since some epoch. The value may wrap around. It should only be used for heuristic purposes. 
- Returns
- ms since epoch 
Definition at line 188 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN ullint ut_time_us | ( | ullint * | tloc | ) |  | 
      
 
Returns the number of microseconds since epoch. Similar to time(3), the return value is also stored in *tloc, provided that tloc is non-NULL. 
- Returns
- us since epoch out: us since epoch, if non-NULL
Returns the number of microseconds since epoch. Similar to time(3), the return value is also stored in *tloc, provided that tloc is non-NULL. 
- Returns
- us since epoch 
- Parameters
- 
  
    | tloc | out: us since epoch, if non-NULL |  
 
Definition at line 163 of file ut0ut.cc.
 
 
      
        
          | UNIV_INLINE int ut_ulint_cmp | ( | ulint | a, | 
        
          |  |  | ulint | b | 
        
          |  | ) |  |  | 
      
 
Compares two ulints. 
- Returns
- 1 if a > b, 0 if a == b, -1 if a < b in: ulint 
- Parameters
- 
  
  
 
 
      
        
          | UNIV_INTERN void ut_ulint_sort | ( | ulint * | arr, | 
        
          |  |  | ulint * | aux_arr, | 
        
          |  |  | ulint | low, | 
        
          |  |  | ulint | high | 
        
          |  | ) |  |  | 
      
 
Sort function for ulint arrays. 
- Parameters
- 
  
    | arr | in/out: array to sort |  | aux_arr | in/out: aux array to use in sort |  | low | in: lower bound |  | high | in: upper bound |  
 
Definition at line 458 of file ut0ut.cc.
 
 
      
        
          | UNIV_INTERN int ut_usectime | ( | ulint * | sec, | 
        
          |  |  | ulint * | ms | 
        
          |  | ) |  |  | 
      
 
Returns system time. Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error. 
- Returns
- 0 on success, -1 otherwise out: microseconds since the Epoch+*sec
Returns system time. Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error. 
- Returns
- 0 on success, -1 otherwise 
- Parameters
- 
  
    | sec | out: seconds since the Epoch |  | ms | out: microseconds since the Epoch+*sec |  
 
Definition at line 122 of file ut0ut.cc.