make use of platform::putenv()

This commit is contained in:
Axel Kohlmeyer
2021-10-04 22:39:24 -04:00
parent 40f683c1a7
commit ee594a879b
3 changed files with 7 additions and 19 deletions

View File

@ -41,7 +41,7 @@
#if defined(__PLUMED_DEFAULT_KERNEL) #if defined(__PLUMED_DEFAULT_KERNEL)
#define PLUMED_QUOTE_DIRECT(name) #name #define PLUMED_QUOTE_DIRECT(name) #name
#define PLUMED_QUOTE(macro) PLUMED_QUOTE_DIRECT(macro) #define PLUMED_QUOTE(macro) PLUMED_QUOTE_DIRECT(macro)
static char plumed_default_kernel[] = "PLUMED_KERNEL=" PLUMED_QUOTE(__PLUMED_DEFAULT_KERNEL); static const char plumed_default_kernel[] = "PLUMED_KERNEL=" PLUMED_QUOTE(__PLUMED_DEFAULT_KERNEL);
#endif #endif
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
@ -68,7 +68,7 @@ FixPlumed::FixPlumed(LAMMPS *lmp, int narg, char **arg) :
#if defined(__PLUMED_DEFAULT_KERNEL) #if defined(__PLUMED_DEFAULT_KERNEL)
if (getenv("PLUMED_KERNEL") == nullptr) if (getenv("PLUMED_KERNEL") == nullptr)
putenv(plumed_default_kernel); platform::putenv(plumed_default_kernel);
#endif #endif
p=new PLMD::Plumed; p=new PLMD::Plumed;

View File

@ -1241,20 +1241,7 @@ void Input::shell()
if (narg < 2) error->all(FLERR,"Illegal shell putenv command"); if (narg < 2) error->all(FLERR,"Illegal shell putenv command");
for (int i = 1; i < narg; i++) { for (int i = 1; i < narg; i++) {
rv = 0; rv = 0;
#ifdef _WIN32 if (arg[i]) rv = platform::putenv(arg[i]);
if (arg[i]) rv = _putenv(utils::strdup(arg[i]));
#else
if (arg[i]) {
std::string vardef(arg[i]);
auto found = vardef.find_first_of('=');
if (found == std::string::npos) {
rv = setenv(vardef.c_str(),"",1);
} else {
rv = setenv(vardef.substr(0,found).c_str(),
vardef.substr(found+1).c_str(),1);
}
}
#endif
rv = (rv < 0) ? errno : 0; rv = (rv < 0) ? errno : 0;
MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world); MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world);
if (me == 0 && err != 0) { if (me == 0 && err != 0) {

View File

@ -134,15 +134,16 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
init_pkg_lists(); init_pkg_lists();
#if defined(LMP_PYTHON) && defined(_WIN32) #if defined(LMP_PYTHON) && defined(_WIN32)
// if the LAMMPSHOME environment variable is set, it should point // If the LAMMPSHOME environment variable is set, it should point
// to the location of the LAMMPS installation tree where we bundle // to the location of the LAMMPS installation tree where we bundle
// the matching Python installation for use with the PYTHON package. // the matching Python installation for use with the PYTHON package.
// this is currently only used on Windows with the windows installer packages // This is currently only used on Windows with the Windows installer packages
const char *lmpenv = getenv("LAMMPSHOME"); const char *lmpenv = getenv("LAMMPSHOME");
if (lmpenv) { if (lmpenv) {
_putenv(utils::strdup(fmt::format("PYTHONHOME={}",lmpenv))); platform::putenv(fmt::format("PYTHONHOME={}",lmpenv));
} }
#endif #endif
// check if -mpicolor is first arg // check if -mpicolor is first arg
// if so, then 2 apps were launched with one mpirun command // if so, then 2 apps were launched with one mpirun command
// this means passed communicator (e.g. MPI_COMM_WORLD) is bigger than LAMMPS // this means passed communicator (e.g. MPI_COMM_WORLD) is bigger than LAMMPS