~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/ut/ut0ut.c

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include <string.h>
17
17
#include <ctype.h>
18
18
 
 
19
#include "ut0sort.h"
19
20
#include "trx0trx.h"
20
21
#include "ha_prototypes.h"
21
 
#ifndef UNIV_HOTBACKUP
22
 
# if defined(BUILD_DRIZZLE)
23
 
#  include <drizzled/common.h>
24
 
#  if TIME_WITH_SYS_TIME
25
 
#   include <sys/time.h>
26
 
#   include <time.h>
27
 
#  else
28
 
#   if HAVE_SYS_TIME_H
29
 
#    include <sys/time.h>
30
 
#   else
31
 
#    include <time.h>
32
 
#   endif
33
 
#  endif
34
 
# else
35
 
#  include "mysql_com.h" /* NAME_LEN */
36
 
# endif /* DRIZZLE */
37
 
#endif /* UNIV_HOTBACKUP */
38
22
 
39
 
UNIV_INTERN ibool       ut_always_false = FALSE;
 
23
ibool   ut_always_false = FALSE;
40
24
 
41
25
#ifdef __WIN__
42
26
/*********************************************************************
43
27
NOTE: The Windows epoch starts from 1601/01/01 whereas the Unix
44
28
epoch starts from 1970/1/1. For selection of constant see:
45
29
http://support.microsoft.com/kb/167296/ */
46
 
#define WIN_TO_UNIX_DELTA_USEC  ((ib_int64_t) 11644473600000000ULL)
 
30
#define WIN_TO_UNIX_DELTA_USEC  ((ib_longlong) 11644473600000000ULL)
47
31
 
48
32
 
49
33
/*********************************************************************
57
41
        void*           tz)     /* in: not used */
58
42
{
59
43
        FILETIME        ft;
60
 
        ib_int64_t      tm;
 
44
        ib_longlong     tm;
61
45
 
62
46
        if (!tv) {
63
47
                errno = EINVAL;
66
50
 
67
51
        GetSystemTimeAsFileTime(&ft);
68
52
 
69
 
        tm = (ib_int64_t) ft.dwHighDateTime << 32;
 
53
        tm = (ib_longlong) ft.dwHighDateTime << 32;
70
54
        tm |= ft.dwLowDateTime;
71
55
 
72
56
        ut_a(tm >= 0);  /* If tm wraps over to negative, the quotient / 10
91
75
Gets the high 32 bits in a ulint. That is makes a shift >> 32,
92
76
but since there seem to be compiler bugs in both gcc and Visual C++,
93
77
we do this by a special conversion. */
94
 
UNIV_INTERN
 
78
 
95
79
ulint
96
80
ut_get_high32(
97
81
/*==========*/
98
82
                        /* out: a >> 32 */
99
83
        ulint   a)      /* in: ulint */
100
84
{
101
 
        ib_int64_t      i;
 
85
        ib_longlong     i;
102
86
 
103
 
        i = (ib_int64_t)a;
 
87
        i = (ib_longlong)a;
104
88
 
105
89
        i = i >> 32;
106
90
 
107
91
        return((ulint)i);
108
92
}
109
93
 
 
94
/************************************************************
 
95
The following function returns elapsed CPU time in milliseconds. */
 
96
 
 
97
ulint
 
98
ut_clock(void)
 
99
{
 
100
        return((clock() * 1000) / CLOCKS_PER_SEC);
 
101
}
 
102
 
110
103
/**************************************************************
111
104
Returns system time. We do not specify the format of the time returned:
112
105
the only way to manipulate it is to use the function ut_difftime. */
113
 
UNIV_INTERN
 
106
 
114
107
ib_time_t
115
108
ut_time(void)
116
109
/*=========*/
120
113
 
121
114
/**************************************************************
122
115
Returns system time. */
123
 
UNIV_INTERN
 
116
 
124
117
void
125
118
ut_usectime(
126
119
/*========*/
135
128
}
136
129
 
137
130
/**************************************************************
138
 
Returns the number of microseconds since epoch. Similar to
139
 
time(3), the return value is also stored in *tloc, provided
140
 
that tloc is non-NULL. */
141
 
UNIV_INTERN
142
 
ullint
143
 
ut_time_us(
144
 
/*=======*/
145
 
                        /* out: us since epoch */
146
 
        ullint* tloc)   /* out: us since epoch, if non-NULL */
147
 
{
148
 
        struct timeval  tv;
149
 
        ullint          us;
150
 
 
151
 
        ut_gettimeofday(&tv, NULL);
152
 
 
153
 
        us = (ullint) tv.tv_sec * 1000000 + tv.tv_usec;
154
 
 
155
 
        if (tloc != NULL) {
156
 
                *tloc = us;
157
 
        }
158
 
 
159
 
        return(us);
160
 
}
161
 
 
162
 
/**************************************************************
163
131
Returns the difference of two times in seconds. */
164
 
UNIV_INTERN
 
132
 
165
133
double
166
134
ut_difftime(
167
135
/*========*/
174
142
 
175
143
/**************************************************************
176
144
Prints a timestamp to a file. */
177
 
UNIV_INTERN
 
145
 
178
146
void
179
147
ut_print_timestamp(
180
148
/*===============*/
217
185
 
218
186
/**************************************************************
219
187
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
220
 
UNIV_INTERN
 
188
 
221
189
void
222
190
ut_sprintf_timestamp(
223
191
/*=================*/
261
229
/**************************************************************
262
230
Sprintfs a timestamp to a buffer with no spaces and with ':' characters
263
231
replaced by '_'. */
264
 
UNIV_INTERN
 
232
 
265
233
void
266
234
ut_sprintf_timestamp_without_extra_chars(
267
235
/*=====================================*/
304
272
 
305
273
/**************************************************************
306
274
Returns current year, month, day. */
307
 
UNIV_INTERN
 
275
 
308
276
void
309
277
ut_get_year_month_day(
310
278
/*==================*/
342
310
/*****************************************************************
343
311
Runs an idle loop on CPU. The argument gives the desired delay
344
312
in microseconds on 100 MHz Pentium + Visual C++. */
345
 
UNIV_INTERN
 
313
 
346
314
ulint
347
315
ut_delay(
348
316
/*=====*/
366
334
 
367
335
/*****************************************************************
368
336
Prints the contents of a memory buffer in hex and ascii. */
369
 
UNIV_INTERN
 
337
 
370
338
void
371
339
ut_print_buf(
372
340
/*=========*/
397
365
        putc(';', file);
398
366
}
399
367
 
 
368
/****************************************************************
 
369
Sort function for ulint arrays. */
 
370
 
 
371
void
 
372
ut_ulint_sort(ulint* arr, ulint* aux_arr, ulint low, ulint high)
 
373
/*============================================================*/
 
374
{
 
375
        UT_SORT_FUNCTION_BODY(ut_ulint_sort, arr, aux_arr, low, high,
 
376
                              ut_ulint_cmp);
 
377
}
 
378
 
400
379
/*****************************************************************
401
380
Calculates fast the number rounded up to the nearest power of 2. */
402
 
UNIV_INTERN
 
381
 
403
382
ulint
404
383
ut_2_power_up(
405
384
/*==========*/
421
400
 
422
401
/**************************************************************************
423
402
Outputs a NUL-terminated file name, quoted with apostrophes. */
424
 
UNIV_INTERN
 
403
 
425
404
void
426
405
ut_print_filename(
427
406
/*==============*/
450
429
If the string contains a slash '/', the string will be
451
430
output as two identifiers separated by a period (.),
452
431
as in SQL database_name.identifier. */
453
 
UNIV_INTERN
 
432
 
454
433
void
455
434
ut_print_name(
456
435
/*==========*/
468
447
If the string contains a slash '/', the string will be
469
448
output as two identifiers separated by a period (.),
470
449
as in SQL database_name.identifier. */
471
 
UNIV_INTERN
 
450
 
472
451
void
473
452
ut_print_namel(
474
453
/*===========*/
482
461
#ifdef UNIV_HOTBACKUP
483
462
        fwrite(name, 1, namelen, f);
484
463
#else
485
 
        /* 2 * NAME_LEN for database and table name,
486
 
        and some slack for the #mysql50# prefix and quotes */
487
 
        char            buf[3 * NAME_LEN];
488
 
        const char*     bufend;
489
 
 
490
 
        bufend = innobase_convert_name(buf, sizeof buf,
491
 
                                       name, namelen,
492
 
                                       trx ? trx->mysql_thd : NULL,
493
 
                                       table_id);
494
 
 
495
 
        ssize_t ret= fwrite(buf, 1, bufend - buf, f);
496
 
        assert(ret==bufend-buf);  
 
464
        if (table_id) {
 
465
                char*   slash = memchr(name, '/', namelen);
 
466
                if (!slash) {
 
467
 
 
468
                        goto no_db_name;
 
469
                }
 
470
 
 
471
                /* Print the database name and table name separately. */
 
472
                innobase_print_identifier(f, trx, TRUE, name, slash - name);
 
473
                putc('.', f);
 
474
                innobase_print_identifier(f, trx, TRUE, slash + 1,
 
475
                                          namelen - (slash - name) - 1);
 
476
        } else {
 
477
no_db_name:
 
478
                innobase_print_identifier(f, trx, table_id, name, namelen);
 
479
        }
497
480
#endif
498
481
}
499
482
 
500
483
/**************************************************************************
501
484
Catenate files. */
502
 
UNIV_INTERN
 
485
 
503
486
void
504
487
ut_copy_file(
505
488
/*=========*/
515
498
                        ? (size_t) len
516
499
                        : sizeof buf;
517
500
                size_t  size = fread(buf, 1, maxs, src);
518
 
                size_t ret= fwrite(buf, 1, size, dest);
519
 
                assert(ret==size);
 
501
                fwrite(buf, 1, size, dest);
520
502
                len -= (long) size;
521
503
                if (size < maxs) {
522
504
                        break;