~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Jay Pipes
  • Date: 2009-02-21 16:00:06 UTC
  • mto: (907.1.1 trunk-with-temporal)
  • mto: This revision was merged to the branch mainline in revision 908.
  • Revision ID: jpipes@serialcoder-20090221160006-vnk3wt4qbcz62eru
Removes the TIME column type and related time functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
4
 
Copyright (c) 2009, Sun Microsystems, Inc.
5
 
 
6
 
Portions of this file contain modifications contributed and copyrighted by
7
 
Sun Microsystems, Inc. Those modifications are gratefully acknowledged and
8
 
are described briefly in the InnoDB documentation. The contributions by
9
 
Sun Microsystems are incorporated with their permission, and subject to the
10
 
conditions contained in the file COPYING.Sun_Microsystems.
11
 
 
12
 
This program is free software; you can redistribute it and/or modify it under
13
 
the terms of the GNU General Public License as published by the Free Software
14
 
Foundation; version 2 of the License.
15
 
 
16
 
This program is distributed in the hope that it will be useful, but WITHOUT
17
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
 
 
20
 
You should have received a copy of the GNU General Public License along with
21
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22
 
Place, Suite 330, Boston, MA 02111-1307 USA
23
 
 
24
 
*****************************************************************************/
25
 
 
26
 
/***************************************************************//**
27
 
@file ut/ut0ut.c
 
1
/*******************************************************************
28
2
Various utilities for Innobase.
29
3
 
 
4
(c) 1994, 1995 Innobase Oy
 
5
 
30
6
Created 5/11/1994 Heikki Tuuri
31
7
********************************************************************/
32
8
 
40
16
#include <string.h>
41
17
#include <ctype.h>
42
18
 
 
19
#include "trx0trx.h"
 
20
#include "ha_prototypes.h"
43
21
#ifndef UNIV_HOTBACKUP
44
 
# include "trx0trx.h"
45
22
# if defined(BUILD_DRIZZLE)
46
 
#  include "drizzled/common.h"
 
23
#  include <drizzled/common.h>
47
24
#  if TIME_WITH_SYS_TIME
48
25
#   include <sys/time.h>
49
26
#   include <time.h>
55
32
#   endif
56
33
#  endif
57
34
# else
58
 
#  include "ha_prototypes.h"
59
35
#  include "mysql_com.h" /* NAME_LEN */
60
36
# endif /* DRIZZLE */
61
37
#endif /* UNIV_HOTBACKUP */
62
 
#include <errno.h>
63
 
#include <assert.h>
64
38
 
65
 
/** A constant to prevent the compiler from optimizing ut_delay() away. */
66
39
UNIV_INTERN ibool       ut_always_false = FALSE;
67
40
 
68
41
#ifdef __WIN__
69
 
/*****************************************************************//**
 
42
/*********************************************************************
70
43
NOTE: The Windows epoch starts from 1601/01/01 whereas the Unix
71
44
epoch starts from 1970/1/1. For selection of constant see:
72
45
http://support.microsoft.com/kb/167296/ */
73
46
#define WIN_TO_UNIX_DELTA_USEC  ((ib_int64_t) 11644473600000000ULL)
74
47
 
75
48
 
76
 
/*****************************************************************//**
77
 
This is the Windows version of gettimeofday(2).
78
 
@return 0 if all OK else -1 */
 
49
/*********************************************************************
 
50
This is the Windows version of gettimeofday(2).*/
79
51
static
80
52
int
81
53
ut_gettimeofday(
82
54
/*============*/
83
 
        struct timeval* tv,     /*!< out: Values are relative to Unix epoch */
84
 
        void*           tz)     /*!< in: not used */
 
55
                        /* out: 0 if all OK else -1 */
 
56
        struct timeval* tv,     /* out: Values are relative to Unix epoch */
 
57
        void*           tz)     /* in: not used */
85
58
{
86
59
        FILETIME        ft;
87
60
        ib_int64_t      tm;
111
84
        return(0);
112
85
}
113
86
#else
114
 
/** An alias for gettimeofday(2).  On Microsoft Windows, we have to
115
 
reimplement this function. */
116
87
#define ut_gettimeofday         gettimeofday
117
88
#endif
118
89
 
119
 
/********************************************************//**
 
90
/************************************************************
120
91
Gets the high 32 bits in a ulint. That is makes a shift >> 32,
121
92
but since there seem to be compiler bugs in both gcc and Visual C++,
122
 
we do this by a special conversion.
123
 
@return a >> 32 */
 
93
we do this by a special conversion. */
124
94
UNIV_INTERN
125
95
ulint
126
96
ut_get_high32(
127
97
/*==========*/
128
 
        ulint   a)      /*!< in: ulint */
 
98
                        /* out: a >> 32 */
 
99
        ulint   a)      /* in: ulint */
129
100
{
130
101
        ib_int64_t      i;
131
102
 
136
107
        return((ulint)i);
137
108
}
138
109
 
139
 
/**********************************************************//**
 
110
/**************************************************************
140
111
Returns system time. We do not specify the format of the time returned:
141
 
the only way to manipulate it is to use the function ut_difftime.
142
 
@return system time */
 
112
the only way to manipulate it is to use the function ut_difftime. */
143
113
UNIV_INTERN
144
114
ib_time_t
145
115
ut_time(void)
148
118
        return(time(NULL));
149
119
}
150
120
 
151
 
/**********************************************************//**
 
121
/**************************************************************
152
122
Returns system time.
153
123
Upon successful completion, the value 0 is returned; otherwise the
154
124
value -1 is returned and the global variable errno is set to indicate the
155
 
error.
156
 
@return 0 on success, -1 otherwise */
 
125
error. */
157
126
UNIV_INTERN
158
127
int
159
128
ut_usectime(
160
129
/*========*/
161
 
        ulint*  sec,    /*!< out: seconds since the Epoch */
162
 
        ulint*  ms)     /*!< out: microseconds since the Epoch+*sec */
 
130
                        /* out: 0 on success, -1 otherwise */
 
131
        ulint*  sec,    /* out: seconds since the Epoch */
 
132
        ulint*  ms)     /* out: microseconds since the Epoch+*sec */
163
133
{
164
134
        struct timeval  tv;
165
135
        int             ret;
190
160
        return(ret);
191
161
}
192
162
 
193
 
/**********************************************************//**
 
163
/**************************************************************
194
164
Returns the number of microseconds since epoch. Similar to
195
165
time(3), the return value is also stored in *tloc, provided
196
 
that tloc is non-NULL.
197
 
@return us since epoch */
 
166
that tloc is non-NULL. */
198
167
UNIV_INTERN
199
168
ullint
200
169
ut_time_us(
201
170
/*=======*/
202
 
        ullint* tloc)   /*!< out: us since epoch, if non-NULL */
 
171
                        /* out: us since epoch */
 
172
        ullint* tloc)   /* out: us since epoch, if non-NULL */
203
173
{
204
174
        struct timeval  tv;
205
175
        ullint          us;
215
185
        return(us);
216
186
}
217
187
 
218
 
/**********************************************************//**
219
 
Returns the difference of two times in seconds.
220
 
@return time2 - time1 expressed in seconds */
 
188
/**************************************************************
 
189
Returns the difference of two times in seconds. */
221
190
UNIV_INTERN
222
191
double
223
192
ut_difftime(
224
193
/*========*/
225
 
        ib_time_t       time2,  /*!< in: time */
226
 
        ib_time_t       time1)  /*!< in: time */
 
194
                                /* out: time2 - time1 expressed in seconds */
 
195
        ib_time_t       time2,  /* in: time */
 
196
        ib_time_t       time1)  /* in: time */
227
197
{
228
198
        return(difftime(time2, time1));
229
199
}
230
200
 
231
 
/**********************************************************//**
 
201
/**************************************************************
232
202
Prints a timestamp to a file. */
233
203
UNIV_INTERN
234
204
void
235
205
ut_print_timestamp(
236
206
/*===============*/
237
 
        FILE*  file) /*!< in: file where to print */
 
207
        FILE*  file) /* in: file where to print */
238
208
{
239
209
#ifdef __WIN__
240
210
        SYSTEMTIME cal_tm;
271
241
#endif
272
242
}
273
243
 
274
 
/**********************************************************//**
 
244
/**************************************************************
275
245
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
276
246
UNIV_INTERN
277
247
void
278
248
ut_sprintf_timestamp(
279
249
/*=================*/
280
 
        char*   buf) /*!< in: buffer where to sprintf */
 
250
        char*   buf) /* in: buffer where to sprintf */
281
251
{
282
252
#ifdef __WIN__
283
253
        SYSTEMTIME cal_tm;
314
284
#endif
315
285
}
316
286
 
317
 
#ifdef UNIV_HOTBACKUP
318
 
/**********************************************************//**
 
287
/**************************************************************
319
288
Sprintfs a timestamp to a buffer with no spaces and with ':' characters
320
289
replaced by '_'. */
321
290
UNIV_INTERN
322
291
void
323
292
ut_sprintf_timestamp_without_extra_chars(
324
293
/*=====================================*/
325
 
        char*   buf) /*!< in: buffer where to sprintf */
 
294
        char*   buf) /* in: buffer where to sprintf */
326
295
{
327
296
#ifdef __WIN__
328
297
        SYSTEMTIME cal_tm;
359
328
#endif
360
329
}
361
330
 
362
 
/**********************************************************//**
 
331
/**************************************************************
363
332
Returns current year, month, day. */
364
333
UNIV_INTERN
365
334
void
366
335
ut_get_year_month_day(
367
336
/*==================*/
368
 
        ulint*  year,   /*!< out: current year */
369
 
        ulint*  month,  /*!< out: month */
370
 
        ulint*  day)    /*!< out: day */
 
337
        ulint*  year,   /* out: current year */
 
338
        ulint*  month,  /* out: month */
 
339
        ulint*  day)    /* out: day */
371
340
{
372
341
#ifdef __WIN__
373
342
        SYSTEMTIME cal_tm;
395
364
        *day = (ulint)cal_tm_ptr->tm_mday;
396
365
#endif
397
366
}
398
 
#endif /* UNIV_HOTBACKUP */
399
367
 
400
 
#ifndef UNIV_HOTBACKUP
401
 
/*************************************************************//**
 
368
/*****************************************************************
402
369
Runs an idle loop on CPU. The argument gives the desired delay
403
 
in microseconds on 100 MHz Pentium + Visual C++.
404
 
@return dummy value */
 
370
in microseconds on 100 MHz Pentium + Visual C++. */
405
371
UNIV_INTERN
406
372
ulint
407
373
ut_delay(
408
374
/*=====*/
409
 
        ulint   delay)  /*!< in: delay in microseconds on 100 MHz Pentium */
 
375
                        /* out: dummy value */
 
376
        ulint   delay)  /* in: delay in microseconds on 100 MHz Pentium */
410
377
{
411
378
        ulint   i, j;
412
379
 
414
381
 
415
382
        for (i = 0; i < delay * 50; i++) {
416
383
                j += i;
417
 
                UT_RELAX_CPU();
418
384
        }
419
385
 
420
386
        if (ut_always_false) {
423
389
 
424
390
        return(j);
425
391
}
426
 
#endif /* !UNIV_HOTBACKUP */
427
392
 
428
 
/*************************************************************//**
 
393
/*****************************************************************
429
394
Prints the contents of a memory buffer in hex and ascii. */
430
395
UNIV_INTERN
431
396
void
432
397
ut_print_buf(
433
398
/*=========*/
434
 
        FILE*           file,   /*!< in: file where to print */
435
 
        const void*     buf,    /*!< in: memory buffer */
436
 
        ulint           len)    /*!< in: length of the buffer */
 
399
        FILE*           file,   /* in: file where to print */
 
400
        const void*     buf,    /* in: memory buffer */
 
401
        ulint           len)    /* in: length of the buffer */
437
402
{
438
403
        const byte*     data;
439
404
        ulint           i;
458
423
        putc(';', file);
459
424
}
460
425
 
461
 
/*************************************************************//**
462
 
Calculates fast the number rounded up to the nearest power of 2.
463
 
@return first power of 2 which is >= n */
 
426
/*****************************************************************
 
427
Calculates fast the number rounded up to the nearest power of 2. */
464
428
UNIV_INTERN
465
429
ulint
466
430
ut_2_power_up(
467
431
/*==========*/
468
 
        ulint   n)      /*!< in: number != 0 */
 
432
                        /* out: first power of 2 which is >= n */
 
433
        ulint   n)      /* in: number != 0 */
469
434
{
470
435
        ulint   res;
471
436
 
480
445
        return(res);
481
446
}
482
447
 
483
 
/**********************************************************************//**
 
448
/**************************************************************************
484
449
Outputs a NUL-terminated file name, quoted with apostrophes. */
485
450
UNIV_INTERN
486
451
void
487
452
ut_print_filename(
488
453
/*==============*/
489
 
        FILE*           f,      /*!< in: output stream */
490
 
        const char*     name)   /*!< in: name to print */
 
454
        FILE*           f,      /* in: output stream */
 
455
        const char*     name)   /* in: name to print */
491
456
{
492
457
        putc('\'', f);
493
458
        for (;;) {
505
470
done:
506
471
        putc('\'', f);
507
472
}
508
 
#ifndef UNIV_HOTBACKUP
509
 
/**********************************************************************//**
 
473
 
 
474
/**************************************************************************
510
475
Outputs a fixed-length string, quoted as an SQL identifier.
511
476
If the string contains a slash '/', the string will be
512
477
output as two identifiers separated by a period (.),
515
480
void
516
481
ut_print_name(
517
482
/*==========*/
518
 
        FILE*           f,      /*!< in: output stream */
519
 
        trx_t*          trx,    /*!< in: transaction */
520
 
        ibool           table_id,/*!< in: TRUE=print a table name,
 
483
        FILE*           f,      /* in: output stream */
 
484
        trx_t*          trx,    /* in: transaction */
 
485
        ibool           table_id,/* in: TRUE=print a table name,
521
486
                                FALSE=print other identifier */
522
 
        const char*     name)   /*!< in: name to print */
 
487
        const char*     name)   /* in: name to print */
523
488
{
524
489
        ut_print_namel(f, trx, table_id, name, strlen(name));
525
490
}
526
491
 
527
 
/**********************************************************************//**
 
492
/**************************************************************************
528
493
Outputs a fixed-length string, quoted as an SQL identifier.
529
494
If the string contains a slash '/', the string will be
530
495
output as two identifiers separated by a period (.),
533
498
void
534
499
ut_print_namel(
535
500
/*===========*/
536
 
        FILE*           f,      /*!< in: output stream */
537
 
        trx_t*          trx,    /*!< in: transaction (NULL=no quotes) */
538
 
        ibool           table_id,/*!< in: TRUE=print a table name,
 
501
        FILE*           f,      /* in: output stream */
 
502
        trx_t*          trx,    /* in: transaction (NULL=no quotes) */
 
503
        ibool           table_id,/* in: TRUE=print a table name,
539
504
                                FALSE=print other identifier */
540
 
        const char*     name,   /*!< in: name to print */
541
 
        ulint           namelen)/*!< in: length of name */
 
505
        const char*     name,   /* in: name to print */
 
506
        ulint           namelen)/* in: length of name */
542
507
{
 
508
#ifdef UNIV_HOTBACKUP
 
509
        fwrite(name, 1, namelen, f);
 
510
#else
543
511
        /* 2 * NAME_LEN for database and table name,
544
512
        and some slack for the #mysql50# prefix and quotes */
545
513
        char            buf[3 * NAME_LEN];
552
520
 
553
521
        ssize_t ret= fwrite(buf, 1, bufend - buf, f);
554
522
        assert(ret==bufend-buf);  
 
523
#endif
555
524
}
556
525
 
557
 
/**********************************************************************//**
 
526
/**************************************************************************
558
527
Catenate files. */
559
528
UNIV_INTERN
560
529
void
561
530
ut_copy_file(
562
531
/*=========*/
563
 
        FILE*   dest,   /*!< in: output file */
564
 
        FILE*   src)    /*!< in: input file to be appended to output */
 
532
        FILE*   dest,   /* in: output file */
 
533
        FILE*   src)    /* in: input file to be appended to output */
565
534
{
566
535
        long    len = ftell(src);
567
536
        char    buf[4096];
580
549
                }
581
550
        } while (len > 0);
582
551
}
583
 
#endif /* !UNIV_HOTBACKUP */
 
552
 
 
553
/**************************************************************************
 
554
snprintf(). */
584
555
 
585
556
#ifdef __WIN__
586
 
# include <stdarg.h>
587
 
/**********************************************************************//**
588
 
A substitute for snprintf(3), formatted output conversion into
589
 
a limited buffer.
590
 
@return number of characters that would have been printed if the size
591
 
were unlimited, not including the terminating '\0'. */
592
 
UNIV_INTERN
 
557
#include <stdarg.h>
593
558
int
594
559
ut_snprintf(
595
 
/*========*/
596
 
        char*           str,    /*!< out: string */
597
 
        size_t          size,   /*!< in: str size */
598
 
        const char*     fmt,    /*!< in: format */
599
 
        ...)                    /*!< in: format values */
 
560
                                /* out: number of characters that would
 
561
                                have been printed if the size were
 
562
                                unlimited, not including the terminating
 
563
                                '\0'. */
 
564
        char*           str,    /* out: string */
 
565
        size_t          size,   /* in: str size */
 
566
        const char*     fmt,    /* in: format */
 
567
        ...)                    /* in: format values */
600
568
{
601
569
        int     res;
602
570
        va_list ap1;