*BSD News Article 73163


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!spool.mu.edu!howland.reston.ans.net!gatech!news.mathworks.com!news.kei.com!nntp.coast.net!dispatch.news.demon.net!demon!awfulhak.demon.co.uk!awfulhak.demon.co.uk!awfulhak.demon.co.uk!not-for-mail
From: brian@awfulhak.demon.co.uk (Brian Somers)
Newsgroups: comp.unix.bsd.misc
Subject: Re: programming
Date: 8 Jul 1996 11:59:38 +0100
Organization: Coverform Ltd.
Lines: 35
Message-ID: <4rqpmq$cv@anorak.coverform.lan>
References: <31DC7155.41C67EA6@vnet.net> <4rjpoo$hp@anorak.coverform.lan> <31E0053F.41C67EA6@vnet.net>
NNTP-Posting-Host: localhost.coverform.lan
X-NNTP-Posting-Host: awfulhak.demon.co.uk
X-Newsreader: TIN [version 1.2 PL2]

Edwin Burley (khan@vnet.net) wrote:
: So both of you are saying that chdir does not needed tobe
:  
: #include() into a lib....or just place it in the program
: as chdir...
: also Brian ,,,,are you saying that it will go to the dir and
: do something ...then come back to the dir you started at....
: (((is this right))))

You need a #include <unistd.h> for the chdir prototype.

For example:

#include <string.h>
#include <unistd.h>

int main( int argc, char **argv )
{
	if( argc != 2 )
		fprintf( stderr, "Usage: %s dir\n", argv[0] );
	else if( chdir( argv[1] ) )
		perror( "chdir" );
	else
		return 0;
	return 1;
}

This program changes to the given directory.  However, because the
current directory information is held per-process, when the above
program exits, you'll be right back where you started (the executing
shells directory hasn't changed).

--
Brian <brian@awfulhak.demon.co.uk>
Don't _EVER_ lose your sense of humour....