Questions tagged [getenv]

Anything related to C or C++ standard library functions `getenv` (C) or `std::getenv` (C++). These functions are used to get the value of an environment variable.

Anything related to C or C++ standard library functions getenv (defined in <stdlib.h> C standard header) or std::getenv (defined in <cstdlib> C++ standard header). These functions are used to get the value of an environment variable.

See CPPreference.com:

128 questions
4
votes
1 answer

getenv() segmentation fault

I have to do my homework but I can not take path in C.For example ; int main(void) { char *path; path = getenv("PATH"); if(path) printf("The current path is: %s\n", path); return 0; } If I run this code , I got "Segmentation fault (core…
SemihY
  • 249
  • 1
  • 4
  • 14
4
votes
4 answers

Portable way to get user name

For C/C++ there seems to be no portable function to get the user name in Linux/Posix and Windows. What would be the least cumbersome and yet robust portable code to achieve this ? In Linux the USER environment variable seems always to be defined,…
tssch
  • 734
  • 8
  • 25
4
votes
2 answers

Ignore certain lines in Octave (but keep them for Matlab)

Possible Duplicate: How do I detect if I’m running MATLAB or Octave? My code was designed using MATLAB and I still use it. However, if I try to run some parts of it using Octave, I get errors. For example, MATLAB code uses pause on which Octave…
Maddy
  • 2,520
  • 14
  • 44
  • 64
4
votes
4 answers

Writing own Unix shell in C - Problems with PATH and execv

I'm writing my own shell in C. It needs to be able to display the users current directory, execute commands based on the full path (must use execv), and allow the user to change the directory with cd. This IS homework. The teacher only gave us a…
user1287523
  • 967
  • 3
  • 14
  • 31
3
votes
2 answers

getenv returns tainted string content

Coverity is claiming getenv is returning a tainted string and I've exhausted all of my ideas for return value checking. I looked at the other questions similar to mine, but none of their solutions worked for me. I've tried checking the return for…
AsiaRican
  • 75
  • 1
  • 13
3
votes
3 answers

Do envz_get and getenv reference the same pool of environment variables?

Do getenv() and envz_get() both look up environment variables from the same source if the latter is passed the optional envp argument to int main (int argc, char *argv[], char *envp[])? In other words, does the optional envp argument to int main…
StoneThrow
  • 5,314
  • 4
  • 44
  • 86
3
votes
1 answer

Access violation exception while using getenv to retrieve an environment variable that doesn't exist

I am using MS Visual Studio 2008 for developing a C++ application. I use the 'getenv()' function to fetch an environment variable, but when the searched environment variable doesn't exist, it throws an access violation exception. What is the issue…
Guruprasad
  • 1,447
  • 4
  • 16
  • 34
3
votes
2 answers

Why the contents of environ in the /proc file system differs from what extern environ pointed to?

getenv() in my C++ apache/cgi gives me weird things, then I checked the environ inside /proc/${PID_OF_THE_RUNNING_PROCESS}, they did not match, which I think they should, I am wondering what was wrong with /proc or it was getenv()? shell@kernel #…
http8086
  • 1,306
  • 16
  • 37
3
votes
1 answer

Environment.SetEnvironmentVariable does not set any value

i'm encountering this issue with only Windows Server 2016 (Win2016) and VisualStudio-redistributable 2015 (VS-redist-2015 = msvcp14) c# Environment.SetEnvironmentVariable(key,val, EnvironmentVariableTarget.Process) does not seem to set values that…
Lydon Ch
  • 8,637
  • 20
  • 79
  • 132
3
votes
1 answer

How to get Environment Variable from Shell in PHP/phpinfo()

I'm trying to use SendGrid's API for which I need to access an environment variable that I've added to my root directory using the following command. echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env echo "sendgrid.env" >>…
Govind Rai
  • 14,406
  • 9
  • 72
  • 83
2
votes
3 answers

How to setenv (set environment variable) using mainmenu nib (xib) file in Cocoa or Xcode programming?

I am new to both Cocoa programming and Xcode. I am wondering how I can setenv (or set environment variable) using MainMenu.nib (or .xib) file. I have someone else's code in the main function like this: [NSApplication sharedApplication]; [NSBundle…
Sangcheol Choi
  • 841
  • 1
  • 12
  • 19
2
votes
2 answers

Environment variables in simple linux shell

I am to program a simple shell in C for my project that can implement environment variables. I looked up on how to use the getenv, setenv, putenv. So far so good i've tried to use the getenv to show the shell variables...well... with some succes .…
mkab
  • 933
  • 4
  • 16
  • 31
2
votes
1 answer

Thread safe initialization of string from getenv (environment variable)

I have a project with tight level of clang-tidy static analysis. In order to check some consistencies in the environment I am probing the value of a few environment variables. int main() { char const* ompi_size_cstr =…
alfC
  • 14,261
  • 4
  • 67
  • 118
2
votes
1 answer

InfluxDB : cant connect with the client because of my token and os.getenv

I am just starting with InfluxDB. On the UI there is a section for Python to start with the database with an example: initialize the client, write data, make a request and close the client. In order to authenticate the request you have to generate a…
lapasq
  • 37
  • 4
2
votes
0 answers

Error in using getenv() to obtain number of threads

I am using the function getenv() to obtain the number of threads in the following manner: char* var; var = getenv("OMP_NUM_THREADS"); I get the following error: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To…
Babaji
  • 398
  • 1
  • 4
  • 18
1
2
3
8 9