Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 08-04-2001, 03:03 PM   #1
LQ Newbie
Registered: Apr 2001
Posts: 7

Rep: Reputation: 0
Question Filenames with tilde

I want to open a file with a filename that starts with ~ so that it is created/opened in the users home directory.

But when I try to do that it fails with "No such directory".

I would have thought that this was a common requirement. So is there a handy library function that exists to convert the tilde into the users home directory path.

If not, and I have to do the conversion myself, what routines exist to get hold of the HOMEDIR variable.

All in "C" by the way.
Old 08-05-2001, 05:27 PM   #2
LQ Newbie
Registered: Aug 2001
Location: montreal, canada
Distribution: redhat
Posts: 22

Rep: Reputation: 15
i dont know if theres a lib to automatically convert ~ to users home dir, but if you want to do it yourself and want to get hold of teh HOME, then you will have to use "environ"
use teh declaration as

extern char **environ;

and then get teh HOME var.
Old 08-08-2001, 05:53 PM   #3
LQ Newbie
Registered: Apr 2001
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks. I'm now decoding the environment variables and that seems to do what I want.

Thanks again



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Tilde name shortening steveel Slackware 6 11-21-2005 04:55 AM
Filenames eponymous Linux - Software 3 05-25-2005 07:36 AM
editor saves duplicate file with tilde after it smaudlin Red Hat 2 12-29-2004 05:37 PM
Backup "tilde" files jrdioko Linux - Newbie 2 09-03-2004 02:41 PM
tilde in X nva Linux - General 2 06-30-2003 12:12 PM

All times are GMT -5. The time now is 01:33 PM.

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