~jelmer/pkg-libinnodb/lintian-fixes

« back to all changes in this revision

Viewing changes to ut/ut0ut.c

  • Committer: Monty Taylor
  • Date: 2010-02-25 22:11:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: mordred@inaugust.com-20100225221129-7hp269rppif7b79c
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
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.
4
11
 
5
12
This program is free software; you can redistribute it and/or modify it under
6
13
the terms of the GNU General Public License as published by the Free Software
16
23
 
17
24
*****************************************************************************/
18
25
 
19
 
/*******************************************************************
 
26
/***************************************************************//**
 
27
@file ut/ut0ut.c
20
28
Various utilities for Innobase.
21
29
 
22
30
Created 5/11/1994 Heikki Tuuri
39
47
#include "api0ucode.h"
40
48
#endif /* UNIV_HOTBACKUP */
41
49
 
42
 
static  ibool   ut_always_false = FALSE;
 
50
UNIV_STATIC     ibool   ut_always_false = FALSE;
43
51
 
44
52
#ifdef __WIN__
45
 
/*********************************************************************
 
53
/*****************************************************************//**
46
54
NOTE: The Windows epoch starts from 1601/01/01 whereas the Unix
47
55
epoch starts from 1970/1/1. For selection of constant see:
48
56
http://support.microsoft.com/kb/167296/ */
49
57
#define WIN_TO_UNIX_DELTA_USEC  ((ib_int64_t) 11644473600000000ULL)
50
58
 
51
59
 
52
 
/*********************************************************************
53
 
This is the Windows version of gettimeofday(2).*/
54
 
static
 
60
/*****************************************************************//**
 
61
This is the Windows version of gettimeofday(2).
 
62
@return 0 if all OK else -1 */
 
63
UNIV_STATIC
55
64
int
56
65
ut_gettimeofday(
57
66
/*============*/
58
 
                        /* out: 0 if all OK else -1 */
59
 
        struct timeval* tv,     /* out: Values are relative to Unix epoch */
60
 
        void*           tz)     /* in: not used */
 
67
        struct timeval* tv,     /*!< out: Values are relative to Unix epoch */
 
68
        void*           tz)     /*!< in: not used */
61
69
{
62
70
        FILETIME        ft;
63
71
        ib_int64_t      tm;
88
96
}
89
97
#else
90
98
#include <sys/time.h>
 
99
/** An alias for gettimeofday(2).  On Microsoft Windows, we have to
 
100
reimplement this function. */
91
101
#define ut_gettimeofday         gettimeofday
92
102
#endif
93
103
 
94
 
/************************************************************
 
104
/********************************************************//**
95
105
Gets the high 32 bits in a ulint. That is makes a shift >> 32,
96
106
but since there seem to be compiler bugs in both gcc and Visual C++,
97
 
we do this by a special conversion. */
 
107
we do this by a special conversion.
 
108
@return a >> 32 */
98
109
UNIV_INTERN
99
110
ulint
100
111
ut_get_high32(
101
112
/*==========*/
102
 
                        /* out: a >> 32 */
103
 
        ulint   a)      /* in: ulint */
 
113
        ulint   a)      /*!< in: ulint */
104
114
{
105
115
        ib_int64_t      i;
106
116
 
111
121
        return((ulint)i);
112
122
}
113
123
 
114
 
/**************************************************************
 
124
/**********************************************************//**
115
125
Returns system time. We do not specify the format of the time returned:
116
 
the only way to manipulate it is to use the function ut_difftime. */
 
126
the only way to manipulate it is to use the function ut_difftime.
 
127
@return system time */
117
128
UNIV_INTERN
118
129
ib_time_t
119
130
ut_time(void)
120
131
/*=========*/
121
 
                                /* out: system time */
122
132
{
123
133
        return(time(NULL));
124
134
}
125
135
 
126
 
/**************************************************************
 
136
#ifndef UNIV_HOTBACKUP
 
137
/**********************************************************//**
127
138
Returns system time.
128
139
Upon successful completion, the value 0 is returned; otherwise the
129
140
value -1 is returned and the global variable errno is set to indicate the
130
 
error. */
 
141
error.
 
142
@return 0 on success, -1 otherwise */
131
143
UNIV_INTERN
132
144
int
133
145
ut_usectime(
134
146
/*========*/
135
 
                        /* out: 0 on success, -1 otherwise */
136
 
        ulint*  sec,    /* out: seconds since the Epoch */
137
 
        ulint*  ms)     /* out: microseconds since the Epoch+*sec */
 
147
        ulint*  sec,    /*!< out: seconds since the Epoch */
 
148
        ulint*  ms)     /*!< out: microseconds since the Epoch+*sec */
138
149
{
139
150
        struct timeval  tv;
140
151
        int             ret;
165
176
        return(ret);
166
177
}
167
178
 
168
 
/**************************************************************
 
179
/**********************************************************//**
169
180
Returns the number of microseconds since epoch. Similar to
170
181
time(3), the return value is also stored in *tloc, provided
171
 
that tloc is non-NULL. */
 
182
that tloc is non-NULL.
 
183
@return us since epoch */
172
184
UNIV_INTERN
173
185
ib_uint64_t
174
186
ut_time_us(
175
187
/*=======*/
176
 
                        /* out: us since epoch */
177
 
        ib_uint64_t*    tloc)   /* out: us since epoch, if non-NULL */
 
188
        ib_uint64_t*    tloc)   /*!< out: us since epoch, if non-NULL */
178
189
{
179
190
        struct timeval  tv;
180
191
        ib_uint64_t     us;
190
201
        return(us);
191
202
}
192
203
 
193
 
/**************************************************************
194
 
Returns the difference of two times in seconds. */
 
204
/**********************************************************//**
 
205
Returns the number of milliseconds since some epoch.  The
 
206
value may wrap around.  It should only be used for heuristic
 
207
purposes.
 
208
@return ms since epoch */
 
209
UNIV_INTERN
 
210
ulint
 
211
ut_time_ms(void)
 
212
/*============*/
 
213
{
 
214
        struct timeval  tv;
 
215
 
 
216
        ut_gettimeofday(&tv, NULL);
 
217
 
 
218
        return((ulint) tv.tv_sec * 1000 + tv.tv_usec / 1000);
 
219
}
 
220
#endif /* !UNIV_HOTBACKUP */
 
221
 
 
222
/**********************************************************//**
 
223
Returns the difference of two times in seconds.
 
224
@return time2 - time1 expressed in seconds */
195
225
UNIV_INTERN
196
226
double
197
227
ut_difftime(
198
228
/*========*/
199
 
                                /* out: time2 - time1 expressed in seconds */
200
 
        ib_time_t       time2,  /* in: time */
201
 
        ib_time_t       time1)  /* in: time */
 
229
        ib_time_t       time2,  /*!< in: time */
 
230
        ib_time_t       time1)  /*!< in: time */
202
231
{
203
232
        return(difftime(time2, time1));
204
233
}
205
234
 
206
 
/**************************************************************
 
235
/**********************************************************//**
207
236
Prints a timestamp to a file. */
208
237
UNIV_INTERN
209
238
void
210
239
ut_print_timestamp(
211
240
/*===============*/
212
 
        ib_stream_t     ib_stream) /* in: file where to print */
 
241
        ib_stream_t     ib_stream) /*!< in: file where to print */
213
242
{
214
243
#ifdef __WIN__
215
244
        SYSTEMTIME cal_tm;
246
275
#endif
247
276
}
248
277
 
249
 
/**************************************************************
 
278
/**********************************************************//**
250
279
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
251
280
UNIV_INTERN
252
281
void
253
282
ut_sprintf_timestamp(
254
283
/*=================*/
255
 
        char*   buf) /* in: buffer where to sprintf */
 
284
        char*   buf) /*!< in: buffer where to sprintf */
256
285
{
257
286
#ifdef __WIN__
258
287
        SYSTEMTIME cal_tm;
290
319
}
291
320
 
292
321
#ifdef UNIV_HOTBACKUP
293
 
/**************************************************************
 
322
/**********************************************************//**
294
323
Sprintfs a timestamp to a buffer with no spaces and with ':' characters
295
324
replaced by '_'. */
296
325
UNIV_INTERN
297
326
void
298
327
ut_sprintf_timestamp_without_extra_chars(
299
328
/*=====================================*/
300
 
        char*   buf) /* in: buffer where to sprintf */
 
329
        char*   buf) /*!< in: buffer where to sprintf */
301
330
{
302
331
#ifdef __WIN__
303
332
        SYSTEMTIME cal_tm;
334
363
#endif
335
364
}
336
365
 
337
 
/**************************************************************
 
366
/**********************************************************//**
338
367
Returns current year, month, day. */
339
368
UNIV_INTERN
340
369
void
341
370
ut_get_year_month_day(
342
371
/*==================*/
343
 
        ulint*  year,   /* out: current year */
344
 
        ulint*  month,  /* out: month */
345
 
        ulint*  day)    /* out: day */
 
372
        ulint*  year,   /*!< out: current year */
 
373
        ulint*  month,  /*!< out: month */
 
374
        ulint*  day)    /*!< out: day */
346
375
{
347
376
#ifdef __WIN__
348
377
        SYSTEMTIME cal_tm;
373
402
#endif /* UNIV_HOTBACKUP */
374
403
 
375
404
#ifndef UNIV_HOTBACKUP
376
 
/*****************************************************************
 
405
/*************************************************************//**
377
406
Runs an idle loop on CPU. The argument gives the desired delay
378
 
in microseconds on 100 MHz Pentium + Visual C++. */
 
407
in microseconds on 100 MHz Pentium + Visual C++.
 
408
@return dummy value */
379
409
UNIV_INTERN
380
410
ulint
381
411
ut_delay(
382
412
/*=====*/
383
 
                        /* out: dummy value */
384
 
        ulint   delay)  /* in: delay in microseconds on 100 MHz Pentium */
 
413
        ulint   delay)  /*!< in: delay in microseconds on 100 MHz Pentium */
385
414
{
386
415
        ulint   i, j;
387
416
 
389
418
 
390
419
        for (i = 0; i < delay * 50; i++) {
391
420
                j += i;
 
421
                UT_RELAX_CPU();
392
422
        }
393
423
 
394
424
        if (ut_always_false) {
399
429
}
400
430
#endif /* !UNIV_HOTBACKUP */
401
431
 
402
 
/*****************************************************************
 
432
/*************************************************************//**
403
433
Prints the contents of a memory buffer in hex and ascii. */
404
434
UNIV_INTERN
405
435
void
406
436
ut_print_buf(
407
437
/*=========*/
408
 
        ib_stream_t     ib_stream,      /* in: stream where to print */
409
 
        const void*     buf,            /* in: memory buffer */
410
 
        ulint           len)            /* in: length of the buffer */
 
438
        ib_stream_t     ib_stream,      /*!< in: stream where to print */
 
439
        const void*     buf,            /*!< in: memory buffer */
 
440
        ulint           len)            /*!< in: length of the buffer */
411
441
{
412
442
        const byte*     data;
413
443
        ulint           i;
432
462
        ib_logger(ib_stream, ";");
433
463
}
434
464
 
435
 
/*****************************************************************
436
 
Calculates fast the number rounded up to the nearest power of 2. */
 
465
/*************************************************************//**
 
466
Calculates fast the number rounded up to the nearest power of 2.
 
467
@return first power of 2 which is >= n */
437
468
UNIV_INTERN
438
469
ulint
439
470
ut_2_power_up(
440
471
/*==========*/
441
 
                        /* out: first power of 2 which is >= n */
442
 
        ulint   n)      /* in: number != 0 */
 
472
        ulint   n)      /*!< in: number != 0 */
443
473
{
444
474
        ulint   res;
445
475
 
454
484
        return(res);
455
485
}
456
486
 
457
 
/**************************************************************************
 
487
/**********************************************************************//**
458
488
Outputs a NUL-terminated file name, quoted with apostrophes. */
459
489
UNIV_INTERN
460
490
void
461
491
ut_print_filename(
462
492
/*==============*/
463
 
        ib_stream_t     ib_stream,      /* in: output stream */
464
 
        const char*     name)           /* in: name to print */
 
493
        ib_stream_t     ib_stream,      /*!< in: output stream */
 
494
        const char*     name)           /*!< in: name to print */
465
495
{
466
496
        ib_logger(ib_stream, "'");
467
497
        for (;;) {
480
510
        ib_logger(ib_stream, "'");
481
511
}
482
512
#ifndef UNIV_HOTBACKUP
483
 
/**************************************************************************
 
513
/**********************************************************************//**
484
514
Outputs a fixed-length string, quoted as an SQL identifier.
485
515
If the string contains a slash '/', the string will be
486
516
output as two identifiers separated by a period (.),
489
519
void
490
520
ut_print_name(
491
521
/*==========*/
492
 
        ib_stream_t     ib_stream,      /* in: output stream */
493
 
        trx_t*          trx,            /* in: transaction */
494
 
        ibool           table_id,       /* in: TRUE=print a table name,
 
522
        ib_stream_t     ib_stream,      /*!< in: output stream */
 
523
        trx_t*          trx,            /*!< in: transaction */
 
524
        ibool           table_id,       /*!< in: TRUE=print a table name,
495
525
                                        FALSE=print other identifier */
496
 
        const char*     name)           /* in: name to print */
 
526
        const char*     name)           /*!< in: name to print */
497
527
{
498
528
        ut_print_namel(ib_stream, name, strlen(name));
499
529
}
500
530
 
501
 
/**************************************************************************
 
531
/**********************************************************************//**
502
532
Outputs a fixed-length string, quoted as an SQL identifier.
503
533
If the string contains a slash '/', the string will be
504
534
output as two identifiers separated by a period (.),
507
537
void
508
538
ut_print_namel(
509
539
/*===========*/
510
 
        ib_stream_t     ib_stream,      /* in: output stream */
511
 
        const char*     name,           /* in: name to print */
512
 
        ulint           namelen)        /* in: length of name */
 
540
        ib_stream_t     ib_stream,      /*!< in: output stream */
 
541
        const char*     name,           /*!< in: name to print */
 
542
        ulint           namelen)        /*!< in: length of name */
513
543
{
514
544
        int             len;
515
545
        /* 2 * NAME_LEN for database and table name,
521
551
 
522
552
        ib_logger(ib_stream, "%.*s", len, buf);
523
553
}
524
 
 
525
554
#endif /* !UNIV_HOTBACKUP */
526
555
 
527
 
/**************************************************************************
528
 
snprintf(). */
529
 
 
530
556
#ifdef __WIN__
531
 
#include <stdarg.h>
 
557
# include <stdarg.h>
 
558
/**********************************************************************//**
 
559
A substitute for snprintf(3), formatted output conversion into
 
560
a limited buffer.
 
561
@return number of characters that would have been printed if the size
 
562
were unlimited, not including the terminating '\0'. */
 
563
UNIV_INTERN
532
564
int
533
565
ut_snprintf(
534
 
                                /* out: number of characters that would
535
 
                                have been printed if the size were
536
 
                                unlimited, not including the terminating
537
 
                                '\0'. */
538
 
        char*           str,    /* out: string */
539
 
        size_t          size,   /* in: str size */
540
 
        const char*     fmt,    /* in: format */
541
 
        ...)                    /* in: format values */
 
566
/*========*/
 
567
        char*           str,    /*!< out: string */
 
568
        size_t          size,   /*!< in: str size */
 
569
        const char*     fmt,    /*!< in: format */
 
570
        ...)                    /*!< in: format values */
542
571
{
543
572
        int     res;
544
573
        va_list ap1;