Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!mp.cs.niu.edu!ux1.cso.uiuc.edu!osiris.cso.uiuc.edu!gordon From: gordon@osiris.cso.uiuc.edu (John Gordon) Newsgroups: comp.unix.questions Subject: Re: getting home directories Message-ID: <1991Apr19.235620.15230@ux1.cso.uiuc.edu> Date: 19 Apr 91 23:56:20 GMT References: <1991Apr16.155130.2708@jsp.umontreal.ca> Sender: usenet@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana Lines: 26 gaumondp@JSP.UMontreal.CA (Gaumond Pierre) writes: >Suppose a C program has to reead the name of a file on another file and then >open it (with "fopen"). >Now, suppose the name read has one of the forms: > - ~/dir/file > - ~user/dir/file >What tools do I have to interpret the ~ and ~user as home directories? >What tools can split path name in single components? Here's how I would do it: Examine the string that contains the filespec. If the first char is a ~, we have to do expansion. If the second char is a /, the ~ represents us, else scan up to a / and that is the user name. If we are getting our own home dir, go a getenv("HOME") or your local equivalent. If we are getting someone else's home dir, do an awk system command to parse that user's entry in the password file. There you will find the home dir for that user. --- John Gordon Internet: gordon@osiris.cso.uiuc.edu #include gordon@cerl.cecer.army.mil #include