program_name.cc
Go to the documentation of this file.
00001 //
00002 //  Copyright 2019 The Abseil Authors.
00003 //
00004 // Licensed under the Apache License, Version 2.0 (the "License");
00005 // you may not use this file except in compliance with the License.
00006 // You may obtain a copy of the License at
00007 //
00008 //      https://www.apache.org/licenses/LICENSE-2.0
00009 //
00010 // Unless required by applicable law or agreed to in writing, software
00011 // distributed under the License is distributed on an "AS IS" BASIS,
00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 // See the License for the specific language governing permissions and
00014 // limitations under the License.
00015 
00016 #include "absl/flags/internal/program_name.h"
00017 
00018 #include <string>
00019 
00020 #include "absl/flags/internal/path_util.h"
00021 #include "absl/synchronization/mutex.h"
00022 
00023 namespace absl {
00024 namespace flags_internal {
00025 
00026 ABSL_CONST_INIT static absl::Mutex program_name_guard(absl::kConstInit);
00027 ABSL_CONST_INIT static std::string* program_name
00028     GUARDED_BY(program_name_guard) = nullptr;
00029 
00030 std::string ProgramInvocationName() {
00031   absl::MutexLock l(&program_name_guard);
00032 
00033   return program_name ? *program_name : "UNKNOWN";
00034 }
00035 
00036 std::string ShortProgramInvocationName() {
00037   absl::MutexLock l(&program_name_guard);
00038 
00039   return program_name ? std::string(flags_internal::Basename(*program_name))
00040                       : "UNKNOWN";
00041 }
00042 
00043 void SetProgramInvocationName(absl::string_view prog_name_str) {
00044   absl::MutexLock l(&program_name_guard);
00045 
00046   if (!program_name)
00047     program_name = new std::string(prog_name_str);
00048   else
00049     program_name->assign(prog_name_str.data(), prog_name_str.size());
00050 }
00051 
00052 }  // namespace flags_internal
00053 }  // namespace absl


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:15