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
1
vote
2 answers

Why this piece of code can get environment variable address?

64-bit Linux stack smashing tutorial: Part 1 uses Get environment variable address gist to get environment variable address. The prerequisite is to first disable ASLR via echo 0 > /proc/sys/kernel/randomize_va_space. The content of the gist is: /* …
Jingguo Yao
  • 7,320
  • 6
  • 50
  • 63
1
vote
2 answers

which is better between getting hostname using InetAddress or System.getenv

I posted a question about a problem that concerns inetaddress in java 8 : InetAddress java 8 is not getting the hostname however I found a simple solution by using System.getenv("HOSTNAME") instead of InetAddress.getLocalHost().getHostName()... I…
Mohamed Taboubi
  • 6,663
  • 11
  • 55
  • 87
1
vote
2 answers

AppData / Similar for all OS : C++?

I'm looking to store some "preferences" for my C++ application. Under windows I know I have to use the "AppData" folder, but I need the equivalent for Linux and OsX. Is there some library or portable way to get such information in C++ ? Here is the…
ClubberLang
  • 1,624
  • 3
  • 21
  • 45
1
vote
1 answer

chdir(getenv("HOME") prompts error "No such file or directory"

Being quite new to writing shell. I am trying to get "cd" to go to home directory when I don't give any extra argument. But when I call "cd" and the code tries to chdir(getenv("HOME")), it shows an error message "No such file or directory". /* …
donkey
  • 4,285
  • 7
  • 42
  • 68
1
vote
2 answers

Which environment variables the app is using

I have binary executable file compiled from C-source and I know that it uses some of UNIX system environment variables. Unfortunately I have no documentation and decompiling/reverse-engineering is very difficult. Is there a way to find which env…
Aleksei Petrenko
  • 6,698
  • 10
  • 53
  • 87
1
vote
1 answer

Strange behaviour for setenv & getenv in OS X Yosemite

When I set an environment variable launchctl setenv FOO test I can fetch the value by launchctl getenv FOO which returns me 'test', but a simple echo $FOO doesn't substitute, the result is empty. In same terminal as well as in new…
ctp
  • 1,077
  • 1
  • 10
  • 28
1
vote
0 answers

getenv() returns null within a MySQL UDF

I'm experiencing a strange issue with the C/C++ function getenv(). The function is used within a MySQL UDF on a Linux system (Linux Mint 16 Cinnamon 64bit). I've set the JAVA_HOME environment variable system-wide by editing the file /etc/environment…
user46726
  • 47
  • 8
1
vote
1 answer

using getenv and env doesn't give the same results:

I have a C program that prints every environmental variable, whose name is given by stdin. It prints variables such as $PATH, $USER but it doesn't see the environmental variables that i defined myself in the Linux shell... For instance, in ~.bashrc…
1
vote
2 answers

getenv returns null when asked for the username?

I want to get the username using the stdlib functio getenv ()However I always get NULL here is the code that I have written: #include #include main() { char *hai; printf("The current User name is\n"); hai="USER"; …
user1680944
  • 537
  • 2
  • 13
  • 23
1
vote
1 answer

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

I was learning C with a book called "C in Linux" by David Haskins but there's a problem. When i try to compile this code: #include #include int main (int argc, char *argv[], char *env[]) { …
user2680683
  • 13
  • 1
  • 3
1
vote
1 answer

PHP getenv results in MAC address not IP

New so maybe a problem with correct use however; Developing a php /web based ordering system needing to identify device (browser) when placing order. Currently using getenv: $terminal = getenv('REMOTE_ADDR'); Majority of results as expected -…
1
vote
1 answer

getenv in Visual C++ 2012

I want to use a getenv function from C in my C++ project in Visual Studio 2012. The code: extern "C" System::SByte^ getenv(const System::SByte^ name); and then in some function: String^ h1 = "HOMEDRIVE"; const System::SByte^ c1 = dynamic_cast
1
vote
1 answer

Stack smashing detected and no source for getenv

I'm having the weirdest problem ever when programming in C. My function sometimes runs and other times it doesn't, and even though I tried searching for these errors (stack smashing detected and no source for getenv) I can't seem to find the answer…
PL-RL
  • 427
  • 2
  • 7
  • 13
0
votes
1 answer

Implementing environment variables in simple linux shell

I am to program a simple shell in linux that can implement various stuffs including environment variables. I tried printing these variables using getenv but I have some problems. getenv always return NULL even if the user types a correct variable…
mkab
  • 933
  • 4
  • 16
  • 31
0
votes
2 answers

(C) How do I include a directory path after a getenv()?

I have been trying to figure out how to (in C) put "getenv()" and "/filetest" into one char. I've thought that you could do it by putting: char *file = getenv("HOME") + "/filetest"; But, I can't seem to figure it out. I tried after that to do: char…
0NeXt
  • 1
  • 2
1 2 3
8 9