MySQL 9.1.0
Source Code Documentation
my_basename.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MY_BASENAME_INCLUDED
25#define MY_BASENAME_INCLUDED
26
27/**
28 @file include/my_basename.h
29 A macro that gives __FILE__ without the directory name (e.g. foo.cc instead of
30 ../sql/foo.cc), calculated compile-time. Note that the entire __FILE__
31 string is still present in the binary; only the pointer is adjusted.
32*/
33
34static constexpr int basename_index(const char *const path, const int index) {
35 return (index == -1 || path[index] == '/' || path[index] == '\\')
36 ? index + 1
37 : basename_index(path, index - 1);
38}
39
40#define MY_BASENAME (&__FILE__[basename_index(__FILE__, sizeof(__FILE__) - 1)])
41
42#ifndef LOG_SUBSYSTEM_TAG
43constexpr const char *basename_prefix_eval(const char *const path) {
44 return (path[0] == 'r' && path[1] == 'p' && path[2] == 'l' && path[3] == '_')
45 ? "Repl"
46 : nullptr;
47}
48
49constexpr int basename_prefix_find(const char *const path, const int index) {
50 return (path[index] == '/' || path[index] == '\\')
51 ? index + 1
52 : basename_prefix_find(path, index - 1);
53}
54
55#define LOG_SUBSYSTEM_TAG \
56 basename_prefix_eval( \
57 &__FILE__[basename_prefix_find(__FILE__, sizeof(__FILE__) - 1)])
58
59#endif
60
61#endif // MY_BASENAME_INCLUDED
constexpr const char * basename_prefix_eval(const char *const path)
Definition: my_basename.h:43
static constexpr int basename_index(const char *const path, const int index)
Definition: my_basename.h:34
constexpr int basename_prefix_find(const char *const path, const int index)
Definition: my_basename.h:49
static char * path
Definition: mysqldump.cc:149