Solved

find home directory c++

Posted on 2003-11-30
4
442 Views
Last Modified: 2011-08-18
i am using curl in my program and i need to be able to find the current users home directory, here is a snippet of the curl procedure

char *headerfilename = "logfile";
FILE *headerfile;
headerfile = fopen(headerfilename,"w");
curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER ,headerfile);

i need that headerfilename to be /home/USERNAME/logfile

any help would be great

Thanks


 
0
Comment
Question by:nutterx
  • 3
4 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9846640
u can get it from env
$HOME will be /home/USERNAME.
0
 
LVL 24

Accepted Solution

by:
shivsa earned 135 total points
ID: 9846801
#include <stdlib.h>

char *getenv(const char *NAME);
----------------------------------------------------

char *home = getenv( "HOME" );

char path[ MAXPATH];
strcpy( path, home );
strcat( path, "/your_directory/logfile" );
fopen( path, "w" );
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9846808
or u can try this too.

char *name;
name = (char *)malloc(sizeof(char)*(PATH_MAX));
name = getcwd(name,PATH_MAX);

BTW: PATH_MAX is found in sys/types.h

also to leart more about getcwd use man getcwd.
0
 

Author Comment

by:nutterx
ID: 9846896
thanks shivsa
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
automating commands in linux on start up 2 47
busybox bash/ash - bash -x | grep 19 152
add some character at the end of line in vi 7 91
WiFi Router device supports GPON! 3 86
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question