Convention Over Configuration: A Way Forward?

Michael Pyne mpyne at purinchu.net
Wed Jan 18 14:43:55 PST 2012


On Wednesday, January 18, 2012 11:04:44 Nicolas Mailhot wrote:
> Le Lun 9 janvier 2012 13:53, Kevin Krammer a écrit :
> > Right, I didn't consider that they already have to read an environment
> > variable.
> > But maybe they consider $HOME to be always set or only explicitly unset,
> > i.e. always just do
> > config_path = getenv( "HOME" ) + config_name
> 
> They don't have to read an env variable for $HOME they can just use ~.

That doesn't always work. Normally shells expand out the value of ~/ to be the 
correct home directory before a program ever sees it, but ~/ does not work for 
the underlying system calls. So, you should not use ~/ in a program's 
internals.

It gets worse though... ~/ doesn't necessarily expand out to $HOME, instead it 
should be based on the user's home directory as given by the getpwent(3) and 
similar library calls. $HOME being set correctly at all is yet another thing 
that the shell is typically "nice" about so you can usually rely on it but 
depending on how sensitive your code is you should not rely on that.

Regards,
 - Michael Pyne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/xdg/attachments/20120118/e49265df/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/xdg/attachments/20120118/e49265df/attachment.pgp>


More information about the xdg mailing list