Solved

find home directory c++

Posted on 2003-11-30
4
439 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux 10 106
Understanding curl command 1 50
CRON expression that fires every other Tuesday 3 94
Puppet: How to keep an update from installing in a few client machines 2 97
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 fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now