<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Can I find a users home directory from within a c program? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643379#M558498</link>
    <description>Hi,&lt;BR /&gt; Seems like there should be an easy way to find the home directory of the user running the c program. The only way I can think of is to read an external file containing it.&lt;BR /&gt; Any ideas?&lt;BR /&gt;      tia Renda&lt;BR /&gt;</description>
    <pubDate>Thu, 06 Oct 2005 10:51:50 GMT</pubDate>
    <dc:creator>Renda Skandier</dc:creator>
    <dc:date>2005-10-06T10:51:50Z</dc:date>
    <item>
      <title>Can I find a users home directory from within a c program?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643379#M558498</link>
      <description>Hi,&lt;BR /&gt; Seems like there should be an easy way to find the home directory of the user running the c program. The only way I can think of is to read an external file containing it.&lt;BR /&gt; Any ideas?&lt;BR /&gt;      tia Renda&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Oct 2005 10:51:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643379#M558498</guid>
      <dc:creator>Renda Skandier</dc:creator>
      <dc:date>2005-10-06T10:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can I find a users home directory from within a c program?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643380#M558499</link>
      <description>I am not a c programmer but here is how you determine it in shell scripting:&lt;BR /&gt;&lt;BR /&gt;USER=some_user_name&lt;BR /&gt;HOMEDIR=`grep $USER /etc/passwd | cut -d: -f6`&lt;BR /&gt;&lt;BR /&gt;Hope this helps</description>
      <pubDate>Thu, 06 Oct 2005 10:54:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643380#M558499</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-10-06T10:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can I find a users home directory from within a c program?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643381#M558500</link>
      <description>&lt;BR /&gt;Use getpwnam() to get the password entry. Use the field pw_dir in the password entry for the home directory.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;struct passwd *passwordEntry;&lt;BR /&gt;&lt;BR /&gt;passwordEntry = getpwnam ("user account name goes here");&lt;BR /&gt;&lt;BR /&gt;passwordEntry-&amp;gt;pw_dir /* Home directory */&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Oct 2005 11:42:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643381#M558500</guid>
      <dc:creator>Alan Sengillo_1</dc:creator>
      <dc:date>2005-10-06T11:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can I find a users home directory from within a c program?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643382#M558501</link>
      <description>I am not a tight programmer,&lt;BR /&gt;but I would have thought of accessing the environment variable "~", but I think the getpasswd solution is more elegant.&lt;BR /&gt;It just might not work in case you need to use a s-uid bit on your program ?&lt;BR /&gt;Would you receive the HOME of the s-bit owner in this case, or the password-entry of the real user ?&lt;BR /&gt;This is more a question to Alan than a solution for you, so no points please.&lt;BR /&gt;Thanks&lt;BR /&gt;Volker</description>
      <pubDate>Thu, 06 Oct 2005 13:05:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643382#M558501</guid>
      <dc:creator>Volker Borowski</dc:creator>
      <dc:date>2005-10-06T13:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Can I find a users home directory from within a c program?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643383#M558502</link>
      <description>The getpwnam(0 function is a good approach. Another is simply&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;char *home = NULL;&lt;BR /&gt;home = getenv("HOME");&lt;BR /&gt;if (home != NULL)&lt;BR /&gt;  {&lt;BR /&gt;    (void) printf("Homedir: %s\n",home);&lt;BR /&gt;  }&lt;BR /&gt;else&lt;BR /&gt;  {&lt;BR /&gt;    (void) fprintf(stderr,"getenv() failed\n");&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;You should note that getenv() uses a static buffer so subsequent calls will overwrite the buffer even if used to getenv("MYVAR"), for example. This means that *home will suddenly change to whatever "MYVAR" was set to. As with all functions of this type, you should copy the thingy to another vaiable if subsequent getenv() calls are expected.&lt;BR /&gt;This same fixed-buffer design is used by getpwnam() as well so ...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STDLIB.H&gt;</description>
      <pubDate>Thu, 06 Oct 2005 13:07:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643383#M558502</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-10-06T13:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Can I find a users home directory from within a c program?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643384#M558503</link>
      <description>You pass the login name of the account to getpwnam() so the s-bit would not have any effect on the call.&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Oct 2005 13:17:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643384#M558503</guid>
      <dc:creator>Alan Sengillo_1</dc:creator>
      <dc:date>2005-10-06T13:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can I find a users home directory from within a c program?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643385#M558504</link>
      <description>thanks... getenv is actually what I was thinking of but couldn't remember.&lt;BR /&gt;&lt;BR /&gt;getpwnam looks like ti would work but not all user have access</description>
      <pubDate>Thu, 06 Oct 2005 13:28:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643385#M558504</guid>
      <dc:creator>Renda Skandier</dc:creator>
      <dc:date>2005-10-06T13:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Can I find a users home directory from within a c program?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643386#M558505</link>
      <description>You could also make use of the system() function and the ~user substitution &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;system("echo ~root");&lt;BR /&gt;&lt;BR /&gt;returns the home directory of root.</description>
      <pubDate>Thu, 06 Oct 2005 13:40:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-i-find-a-users-home-directory-from-within-a-c-program/m-p/3643386#M558505</guid>
      <dc:creator>Tom Danzig</dc:creator>
      <dc:date>2005-10-06T13:40:55Z</dc:date>
    </item>
  </channel>
</rss>

