[comp.unix.questions] Unix C routines

andrew@ee.su.oz.au (Andrew Ho) (12/05/90)

Hi,

  I am writing an application for Unix X-window
which requires the following routines :

  (1) a routine that can return the full path
      string of the current directory

  (2) another routine to return all the file
      names in the current directory

  Are there any Unix built-in system calls to do so ?

  Many thanks!

andrew@ee.su.oz.au

hunt@dg-rtp.rtp.dg.com (Greg Hunt) (12/05/90)

In article <1990Dec5.051318.22071@metro.ucc.su.OZ.AU>, andrew@ee.su.oz.au (Andrew Ho) writes:
> 
>   I am writing an application for Unix X-window
> which requires the following routines :
> 
>   (1) a routine that can return the full path
>       string of the current directory
> 
>   (2) another routine to return all the file
>       names in the current directory
> 
>   Are there any Unix built-in system calls to do so ?

There are C library calls that can do want you need:

Try getwd or getcwd to get the pathname of the current directory.

Try opendir, readir, and closedir to iteratively get all the names
of the files in a directory.

Of course, you'll need to check that your C libraries actually
implement these calls.  Enjoy!

--
Greg Hunt                        Internet: hunt@dg-rtp.rtp.dg.com
DG/UX Kernel Development         UUCP:     {world}!mcnc!rti!dg-rtp!hunt
Data General Corporation
Research Triangle Park, NC, USA  These opinions are mine, not DG's.

james@dlss2.UUCP (James Cummings) (12/06/90)

In article <1990Dec5.051318.22071@metro.ucc.su.OZ.AU> andrew@ee.su.oz.au (Andrew Ho) writes:
>
>Hi,
>
>  I am writing an application for Unix X-window
>which requires the following routines :
>
>  (1) a routine that can return the full path
>      string of the current directory
>
	System V 3.2.x -- getcwd()
	Berkeley 4.3   -- getwd()

>  (2) another routine to return all the file
>      names in the current directory
>
	Berkeley 4.3 -- use "<sys/dir.h> and <sys/types>"
			 the "opendir()" is used much like "fopen()"
			 and the "readdir()" call can be used to read
			 inode and file names into a struct of type DIR
			 until the readdir returns NULL.  Check the 
			 Programmer's reference.

	System V  -- similar to BSD, but you may have to investigate the
		       "dirent.h" header as well.

	Hope this helps.

gwyn@smoke.brl.mil (Doug Gwyn) (12/07/90)

In article <127@dlss2.UUCP> james@dlss2.UUCP (James Cummings) writes:
>	Berkeley 4.3 -- use "<sys/dir.h> and <sys/types>"
>	System V  -- similar to BSD, but you may have to investigate the
>		       "dirent.h" header as well.

Poor advice.  You should use the <dirent.h> interface on all UNIX-like
systems.  If you need an implementation, send me email.