ba17 [Solved] $HOME or ~ in C - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > Userland Programming & Scripting

Userland Programming & Scripting C, Shell, Perl, Sed & Awk

Reply
 
Thread Tools Display Modes
  #1  
Old April 12th, 2010, 13:51
killwin killwin is offline
Junior Member
 
Join Date: Oct 2009
Posts: 36
Thanks: 0
Thanked 1 Time in 1 Post
Default $HOME or ~ in C

Hello,

how to open file like "/home/toto/file.alx" with "$HOME/file.alx" or "~/file.alx" in C language ?

Attention i don't want to part arguments into main !

Thanks
Reply With Quote
  #2  
Old April 12th, 2010, 13:56
SirDice's Avatar
SirDice SirDice is offline
Moderator
 
Join Date: Nov 2008
Location: Rotterdam, Netherlands
Posts: 13,702
Thanks: 47
Thanked 2,022 Times in 1,861 Posts
Default

Not all shells understand ~ is $HOME.
__________________
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
Reply With Quote
  #3  
Old April 12th, 2010, 13:59
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,522
Thanks: 422
Thanked 607 Times in 475 Posts
Default

you need to read environment variables HOME

Code:
extern char **environ;
this will be pointer to (1D aka vertex) array of environment variables
It will be like HOME=/home/user\0 (C string)


INFO from Advanced Programming in the Unix Environment 2nd edition
Reply With Quote
  #4  
Old April 12th, 2010, 14:32
expl's Avatar
expl expl is offline
Member
 
Join Date: Oct 2009
Location: In your shell, stealing your cookies.
Posts: 639
Thanks: 0
Thanked 113 Times in 104 Posts
Default

Or call libc's getenv(3). Simpler than parsing yourself.
Reply With Quote
  #5  
Old April 12th, 2010, 15:20
killwin killwin is offline
Junior Member
 
Join Date: Oct 2009
Posts: 36
Thanks: 0
Thanked 1 Time in 1 Post
Default Solved

Solved, thanks.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Folding@home anemos Off-Topic 7 October 8th, 2011 13:57
How do you organize your home directory? Agi93 General 36 March 24th, 2010 00:16
New User Home Directory epanagio General 4 October 2nd, 2009 07:33
Samba & XP Home client squatter Web & Network Services 2 August 10th, 2009 08:30
home server jail SuperMiguel General 22 June 19th, 2009 00:32


All times are GMT +1. The time now is 04:38.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0