MySQL 8.0.33
Source Code Documentation
my_basename.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MY_BASENAME_INCLUDED
24#define MY_BASENAME_INCLUDED
25
26/**
27 @file include/my_basename.h
28 A macro that gives __FILE__ without the directory name (e.g. foo.cc instead of
29 ../sql/foo.cc), calculated compile-time. Note that the entire __FILE__
30 string is still present in the binary; only the pointer is adjusted.
31*/
32
33static constexpr int basename_index(const char *const path, const int index) {
34 return (index == -1 || path[index] == '/' || path[index] == '\\')
35 ? index + 1
36 : basename_index(path, index - 1);
37}
38
39#define MY_BASENAME (&__FILE__[basename_index(__FILE__, sizeof(__FILE__) - 1)])
40
41#ifndef LOG_SUBSYSTEM_TAG
42constexpr const char *basename_prefix_eval(const char *const path) {
43 return (path[0] == 'r' && path[1] == 'p' && path[2] == 'l' && path[3] == '_')
44 ? "Repl"
45 : nullptr;
46}
47
48constexpr int basename_prefix_find(const char *const path, const int index) {
49 return (path[index] == '/' || path[index] == '\\')
50 ? index + 1
51 : basename_prefix_find(path, index - 1);
52}
53
54#define LOG_SUBSYSTEM_TAG \
55 basename_prefix_eval( \
56 &__FILE__[basename_prefix_find(__FILE__, sizeof(__FILE__) - 1)])
57
58#endif
59
60#endif // MY_BASENAME_INCLUDED
constexpr const char * basename_prefix_eval(const char *const path)
Definition: my_basename.h:42
static constexpr int basename_index(const char *const path, const int index)
Definition: my_basename.h:33
constexpr int basename_prefix_find(const char *const path, const int index)
Definition: my_basename.h:48
static char * path
Definition: mysqldump.cc:133