From owner-freebsd-questions@FreeBSD.ORG Wed Dec 19 00:46:37 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 653CBFE3 for ; Wed, 19 Dec 2012 00:46:37 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id 206598FC14 for ; Wed, 19 Dec 2012 00:46:36 +0000 (UTC) Received: from r56.edvax.de (port-92-195-94-87.dynamic.qsc.de [92.195.94.87]) by mx02.qsc.de (Postfix) with ESMTP id 49E3C276E4; Wed, 19 Dec 2012 01:46:35 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id qBJ0kbl1004420; Wed, 19 Dec 2012 01:46:37 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Wed, 19 Dec 2012 01:46:37 +0100 From: Polytropon To: Gary Kline Subject: Re: which C function is best to check for directory EXISTANCE? Message-Id: <20121219014637.6e4728e3.freebsd@edvax.de> In-Reply-To: <20121219002610.GA12470@ethic.thought.org> References: <20121219002610.GA12470@ethic.thought.org> Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: FreeBSD Mailing List X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Dec 2012 00:46:37 -0000 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, ...