Re: glib outstanding stuff
- From: Sebastian Wilhelmi <wilhelmi ira uka de>
- To: Havoc Pennington <hp redhat com>, Gtk Development List <gtk-devel-list gnome org>
- Subject: Re: glib outstanding stuff
- Date: Thu, 05 Oct 2000 15:34:28 +0200
Hi Havoc,
> - g_file_test ()
>
> Only has simple tests that we definitely need; we can add more
> later.
...
> +/**
> + * g_file_test:
> + * @filename: a filename to test
> + * @test: bitfield of #GFileTest flags
> + *
> + * Returns TRUE if any of the tests in the bitfield @test are
> + * TRUE. For example, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)
> + * will return TRUE if the file exists; the check whether it's
> + * a directory doesn't matter since the existence test is TRUE.
> + * With the current set of available tests, there's no point
> + * passing in more than one test at a time.
> + *
> + * Return value: whether a test was TRUE
> + **/
Would't it make more sense to check for all flags to be true, something like:
gboolean
g_file_test (const gchar *filename,
GFileTest test)
{
struct stat s;
gboolean retval = TRUE;
if (test & G_FILE_TEST_EXISTS)
retval &&= (access (filename, F_OK) == 0);
if (test & G_FILE_TEST_IS_EXECUTABLE)
retval &&= (access (filename, X_OK) == 0);
if (test & G_FILE_TEST_IS_DIR || test & G_FILE_TEST_IS_SYMLINK)
{
if (stat (filename, &s) < 0)
return FALSE;
if ((test & G_FILE_TEST_IS_DIR))
retval &&= S_ISDIR (s.st_mode);
if ((test & G_FILE_TEST_IS_SYMLINK))
retval &&= S_ISLNK (s.st_mode))
}
return retval;
}
--
Sebastian Wilhelmi | här ovanför alla molnen
mailto:wilhelmi ira uka de | är himmlen så förunderligt blå
http://goethe.ira.uka.de/~wilhelmi |
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]