wordexp_ros.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
17 #include <wordexp.h>
18 #include <cstdlib>
19 
20 int wordexp_ros(const char *words, wordexp_t *pwordexp, int flags) {
21  bool should_unset_home = false;
22  if (nullptr == getenv("HOME") && nullptr != getenv("ROS_HOME")) {
23  // We don't want to change the behavior of anything else so we should unset HOME once we're done.
24  should_unset_home = true;
25  setenv("HOME", getenv("ROS_HOME"), true);
26  }
27 
28  int wordexp_result = wordexp(words, pwordexp, flags);
29  if (should_unset_home) {
30  unsetenv("HOME");
31  }
32  return wordexp_result;
33 }
int wordexp_ros(const char *words, wordexp_t *pwordexp, int flags)
Provide wordexp-like behavior, with one difference: in the case that $HOME is not defined - use $ROS_...
Definition: wordexp_ros.cpp:20


aws_common
Author(s): AWS RoboMaker
autogenerated on Sat Mar 6 2021 03:11:38