LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-17-2007, 11:49 AM   #1
_john_i_
Member
 
Registered: Aug 2003
Location: Austin, TX
Distribution: Linux from Scratch
Posts: 52

Rep: Reputation: 15
setenv vs. putenv and malloc requirements


I know that using putenv() to set an environment variable requires that the string passed into putenv must be static, or malloced because it just sets a pointer to it in the environment.

What I am not clear on is if the same is true for setenv(). The linux man and info pages don't say specifically that I must malloc the memory myself, but it doesn't say that it does it for me either.

Would it be safe to set an environment variable with setenv using a string that is just on the stack and will go away at the end or a function? I know this is a no-no with putenv.

Does anyone know?

Thanks,

John
 
Old 07-17-2007, 12:53 PM   #2
_john_i_
Member
 
Registered: Aug 2003
Location: Austin, TX
Distribution: Linux from Scratch
Posts: 52

Original Poster
Rep: Reputation: 15
Nevermind. I answered it myself with a small test program. setenv does handle allocating the memory for the environment variable for you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with putenv and getenv schanuzie Linux - Newbie 0 05-08-2006 06:22 PM
problem with setenv sanjibgupta Linux - General 2 01-20-2006 02:51 AM
Setenv IBP Linux - Software 3 12-20-2002 09:05 AM
setenv DISPLAY toxic53 Linux - Newbie 2 09-27-2001 01:47 AM
setenv ???? toxic53 Linux - Networking 1 09-26-2001 11:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration