When calling getenv() globally, the function returns NULL, yet when
called from main, returns an appropriate value.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
//using namespace std;
#define MW_DEBUG "TEST"
char* debugstr = getenv(MW_DEBUG);
int debug = debugstr?1:0;
int main()
{
if(debug)
write(2, "\nDEBUG Enabled\n", 15);
else
write(2, "\nDEBUG DISABLED\n", 16);
debugstr = getenv(MW_DEBUG);
if(debugstr)
write(2, "\nDebug Enabled\n", 15);
else
write(2, "\nDebug Disabled\n", 16);
} 2 4525 si*******@gmail.com wrote: When calling getenv() globally, the function returns NULL, yet when called from main, returns an appropriate value.
So? The behaviour of 'getenv' is implementation-defined. You need to
read the documentation for your application, perhaps they say that any
call to 'getenv' is not going to succeed before the 'main' function has
been called. The platform is probably setting the "environment" just
before calling your 'main' function.
#include <stdlib.h> #include <stdio.h> #include <unistd.h>
<unistd.h> is not a standard header (regardless of the fact that it has
'std' in its name). //using namespace std; #define MW_DEBUG "TEST"
char* debugstr = getenv(MW_DEBUG); int debug = debugstr?1:0;
int main() { if(debug) write(2, "\nDEBUG Enabled\n", 15); else write(2, "\nDEBUG DISABLED\n", 16); debugstr = getenv(MW_DEBUG); if(debugstr) write(2, "\nDebug Enabled\n", 15); else write(2, "\nDebug Disabled\n", 16); }
V
--
Please remove capital As from my address when replying by mail si*******@gmail.com wrote: When calling getenv() globally, the function returns NULL, yet when called from main, returns an appropriate value.
No it doesn't, what system are you using?
--
Ian Collins. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Xavier |
last post by:
Greetings,
While messing around with the "dl" module I ran into a segfault.
*DO NOTE THAT THE FOLLOWING OCCURED ON 2 OF MY LINUX WORKSTATIONS*
------
# python -c 'import dl;...
|
by: Anand Subramanian |
last post by:
Hi,
Can someone explain the differences(setup, pre-main()
setup/initialization) between global variables in a C++ and a C program?
The global variables I used are uninitialized.
I have a test.o...
|
by: Shuo Xiang |
last post by:
Greetings:
I know that variables declared on a stack definitely does not reside in heap
space so there is only a very limited amount of stuff that you can store in
the stack of a function. But...
|
by: Chad Paquette |
last post by:
Hi,
We have a legacy cgi app that's written in C. We are encountering
an error when we try to retrieve a cgi environment variable. The
variable we are getting contains a Base64 encoded...
|
by: Kleenex |
last post by:
Reason: I am working on an embedded project which has very limited
memory (under 512 bytes, 60 or so of which is stack space), which
translates into limited stack space. In order to save on stack...
|
by: Protoman |
last post by:
What does getenv() do and why would you use it?
|
by: Protoman |
last post by:
Why does getenv work backwards? When I'm testing an env variable, I
have to test if its NOT equal to, rather than equal to, to get the
desired result. As evidenced by this simple piece of code:
...
|
by: silrandir |
last post by:
when attempting to call getenv() in global memory (c/c++), it
constantly returns null, but when called in main, it properly reads the
environment. is this expected behavior?
sample code:...
|
by: Yogi Watcher |
last post by:
Hi,
Recently I have observed some odd behavior of getenv and putenv function. I
am developing some code that integrates with several other libraries. This
program is not using MFC. It is plain C...
|
by: Michael B Allen |
last post by:
Is the string returned by getenv guaranteed to be the same string supplied
to putenv plus the offset of the variable name and equals sign?
Because of API constraints I do not want to save a...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |