PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

NOOOOOOOOOOOOO!!!!!!!!   Ce replacement for getenv

Ok, I've been working on my port all morning (since about 9:30), and I have come to screeching hault.  Ok, here is the problem.  There is a function called

Code:
char *getenv(const char *name);


which searches the environment for a string of the form name=value; and, if such a string is present, it returns a pointer to value. If it cannot find the specified name, it returns a null pointer.

I've been looking all through msdn, and cannot find a substitute anywhere.  PLEASE HELP!!!!!!!!!!!!!!
Please help, I'm begging you.  This is one of the few functions I have left to port, and I can't find a good substitute.
Settle down Beavis! :-)

Check out http://www.rainer-keuchel.de/wince/celib.html this guy is a complete machine and ports stuff left right and centre. I use his perl port when I want to test stuff out on the road.

His libc port is pretty complete - I've ripped one a few of his routines instead of creating empty wrappers as they easy to copy/paste
into the GNUboy port for gapi. Laguna forgot to include the merged codebase for the 1.0.3 release but that's another story..

You can proably do the same for getenv I've not looked at the code I assume it goes and hits the registery. The other question though is do you need getenv(), can you just make a wrapper instead?

Good luck,


Chris
Talk about a machine, aside from bathroom brakes, and putting things in the microwave, I am goin on 10 hours of nostop porting.  I'm donwloading the file right now, and I hope it works.  It is a vital routine for the port, so I either need a port of it, or a workaround that accomplishes the same thing.
This just keeps getting funnier.  There's a good reason why you can't find a substitute, Rob.

Ok, now I'm confused (not that I haven't been many times so far today).  What's funny, the fact that I couldn't find a substitute or that I've been working for 10 hours on this?
Here's a hint.  Who, or what, is going to be setting the environment variables that your implementation of getenv() is going to retrieve?  And more importantly, how are they going to set them?

regedit? DeXplorer?

Can't you set registry settings in the CAB installer? (I've never set a CAB up so I'm not sure what is possible with a CAB.)

Chris
Yeah, OK.  I'm laughing even harder now.  Thanks.

This thread reminds me of a joke:

A man goes into a restaurant and orders a bowl of soup. The waiter brings the soup and walks away. He comes back in a few minutes. "Sir, how is the soup."
"Waiter, taste the soup."
"Sir, is there something wrong with the soup?"
"Waiter, taste the soup!"
"Sir, I'll be glad to bring you something else."
"Waiter! Taste the soup!!!"
"Okay, sir. (looking around) "Where's the spoon?"
"Aha!!"


Rob, you're trying to come up with a replacement for an API that has no purpose on CE.  CE doesn't have environment variables.  You'll need to look at the strings the app is trying to retrieve with getenv() and then find another way to get that information into your ported program.  Some environment variables are set by the user, some by the OS, and some by applications.  You'll have to determine who/what normally sets the environment variables the app is attempting to read, and then find another way to set it, as well as read it.

You've got me confused now too :-(

Are you suggesting that the Windows (CE or XP, etc.) registry is not suitable for storing program config information? I'm inclined to agree with you on this as the registry is a nice idea but a fraught with all sorts of pratical problems. But the registry is all we have under CE so we are stuck with it. There is a getenv() routine available that hits the registry so the port of this part of the code is pretty simple, no re-write required. For a first cut port I would go with that, and it it turns out the config variables are not actually much use, replace the getenv() routing with a custome routine that just fullfils the role for this particualr application.

I've no idea what variables Rob is trying to get hold of but I suspect some of it may be directory settings, e.g. "where are the data files". This (admittedly contrived example) strikes me as a really good place to store in an OS based config stucture such as OS variables (or registry) particulary as CE doesn't have the notion of a current directory in the same way that Unix or win2k/win98 does.

I don't think it is such a big deal to use a wrapper routine that hits the registry to get config (getenv()) information. The celib that Rainer produced works really well, I don't make changes to OS variables/registry very often so I just set up a batch file that runs on the desktop to set the registry on the PocketPC. Then use PHM regedit if I need to make changes on the fly, e.g. I some times change the proxy server settings for the perl module LWP. putenv() is also available in celib if that is something you where alluding to, I'm happy using a registry editing tool though.

Hope I've not confused things any further :-)

Chris
Thanks Digby.  Boy do I feel stupid now.  I'll take your advice and figure out who create the var.
Ugh.  Forget I ever said anything.

True environment vars are not preserved from one instance of the OS to another, unless they are stored in set in a batch file (MS-DOS specific of course), etc. I can't imagine an app that sets environment vars in order to read that info in another part of the app. If it does then it uses very poor programming practices. Environment vars would be used to pass additional parameter information into the app, and are usually read at startup. I can almost guarantee that Rob can comment those out with no ill effects.

Dan East