Solved

find home directory c++

Posted on 2003-11-30
4
438 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
Comment Utility
u can get it from env
$HOME will be /home/USERNAME.
0
 
LVL 24

Accepted Solution

by:
shivsa earned 135 total points
Comment Utility
#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
Comment Utility
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
Comment Utility
thanks shivsa
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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