g_file_test()



typedef enum
{
  G_FILE_TEST_IS_REGULAR    = 1 << 0,
  G_FILE_TEST_IS_SYMLINK    = 1 << 1,
  G_FILE_TEST_IS_DIR        = 1 << 2,
  G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
  G_FILE_TEST_EXISTS        = 1 << 4
} GFileTest;

gboolean g_file_test         (const gchar  *filename,
                              GFileTest     test);

having used g_file_test() in a couple places now, i have to say that:
1) it definitely needs G_FILE_TEST_IS_READABLE and G_FILE_TEST_IS_WRITABLE
2) it should return TRUE only if all tests succeeded.

in most places that i've seen g_file_test() being used, it's just used
with one flag, however, places that do use it with more than one flag
seem to be expecting &= semantics for the flags, e.g.
G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR.

especially when adding G_FILE_TEST_IS_READABLE/G_FILE_TEST_IS_WRITABLE,
the current any-flag-succeeds semantics make increasingly less sense.
for one, i'd like to avoid multiple stat()s when checking:
  if (g_file_test ("foo", G_FILE_TEST_IS_REGULAR) &&
      g_file_test ("foo", G_FILE_TEST_IS_READABLE))
and for another, in executing
  if (g_file_test ("foo", G_FILE_TEST_IS_READABLE | G_FILE_TEST_IS_WRITABLE)
i probably want to know whether the file is readable _and_ writable,
not readable _or_ writable.

/me trying to behave and not write his own file_test to avoid multiple stat()s

---
ciaoTJ





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]