which C function is best to check for directory EXISTANCE?

2012-12-18 Thread Gary Kline

which C function is best to check for the existence of a 
*directory*?  say that I am want to make postitve that /tmp/foo/
exists.

ALso: which will make sure that the directory AND ffile 
tmp/foo/filename12345 exists and that I have read access to it?
in other words, can playing around with access() and stat() be
best?  is there any new dirstat(PATh) that would work?

just want to see which way is best?

dank mucho, y'all!

gary


-- 
 Gary Kline  kl...@thought.org  http://www.thought.org  Public Service Unix
  Twenty-six years of service to the Unix community.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: which C function is best to check for directory EXISTANCE?

2012-12-18 Thread Polytropon
On Tue, 18 Dec 2012 16:26:10 -0800, Gary Kline wrote:
 
   which C function is best to check for the existence of a 
   *directory*?  say that I am want to make postitve that /tmp/foo/
   exists.

That can be done with the opendir() function; its manpage
lists other interesting follow-up functions to work with.



   ALso: which will make sure that the directory AND ffile 
   tmp/foo/filename12345 exists and that I have read access to it?

You can use readdir() and parse its output. If you already know
the file name, use a fopen() call for the mode you're trying to
open it with (e. g. r or w) to see if the permissions are
set accordingly. Also ferror() can be used to test for specific
errors that may occur during file operations.



   in other words, can playing around with access() and stat() be
   best?

That also sounds possible. In case you're going to continue to
operate with the file in question, certain functions sound better.
But for the pure testing, access() and stat() provide sufficient
functionality.


 is there any new dirstat(PATh) that would work?

$ man dirstat
No manual entry for dirstat

:-)



   just want to see which way is best?

Depends. :-)




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: which C function is best to check for directory EXISTANCE?

2012-12-18 Thread Karl Vogel
 On Tue, 18 Dec 2012 16:26:10 -0800, 
 Gary Kline kl...@thought.org said:

G which C function is best to check for the existence of a *directory*?
G say that I am want to make postitve that /tmp/foo/ exists.  ALso:
G which will make sure that the directory AND file
G tmp/foo/filename12345 exists and that I have read access to it?

   I'd just call open() with O_RDONLY and if it fails, check errno for
   EACCESS (you don't have permission) or ENOENT (doesn't exist).

-- 
Karl Vogel  I don't speak for the USAF or my company

USELESS PHRASES WHEN SPEAKING TO A COP #9:
You're not gonna check the trunk, are you?
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org