home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!warwick!coventry!ccx018
- From: ccx018@cch.coventry.ac.uk (Leslie Griffiths (Griff))
- Newsgroups: comp.unix.programmer
- Subject: Re: expanding ~'s in a directory name.
- Message-ID: <Bs8u5J.J6n@cck.coventry.ac.uk>
- Date: 31 Jul 92 07:58:30 GMT
- References: <1992Jul29.012629.14000@gucis.cit.gu.edu.au>
- Sender: news@cck.coventry.ac.uk (news user)
- Organization: Coventry University
- Lines: 37
- Nntp-Posting-Host: cc_sysh
-
- In article <1992Jul29.012629.14000@gucis.cit.gu.edu.au> aroll@gucis.cit.gu.edu.au (Ashley Roll) writes:
-
- >My problem is how do I expand ~'s. I want to expand then the way that csh does.
- >
- >Has anyone written or got code that will do this that I can use? Or is there
- >a library function that will do this.
-
- Well, all you need to do is to find out the users home directory, which can
- be obtained from the "struct passwd *" returned by a function such as
- getpwuid, or getpwnam i.e.
-
- #include <pwd.h>
-
- main()
- {
- struct passwd *pass;
-
-
- if ((pass = getpwuid(getuid())) == NULL)/* Not sure if getpwuid sets errno */
- {
- fprintf(stderr, "Could not get passwd struct\n");
- exit(1);
- }
-
- printf("Users home area is %s\n", pass->pw_dir);
- }
-
- To see what else is contained within the struct passwd, see /usr/include/pwd.h
-
- Cheers
-
-
-
- --
- Griff \\ ccx018@uk.ac.cov
- ^^^^^ :-= ^^^^^^^^^^^^^^^^
- //
-