Logo Search packages:      
Sourcecode: dbus version File versions

dbus_bool_t _dbus_directory_get_next_file ( DBusDirIter iter,
DBusString filename,
DBusError error 
)

Get next file in the directory. Will not return "." or ".." on UNIX. If an error occurs, the contents of "filename" are undefined. The error is never set if the function succeeds.

Todo:
for thread safety, I think we have to use readdir_r(). (GLib has the same issue, should file a bug.)
Parameters:
iter the iterator
filename string to be set to the next file in the dir
error return location for error
Returns:
TRUE if filename was filled in with a new filename

Definition at line 2614 of file dbus-sysdeps.c.

References _dbus_error_from_errno(), _dbus_strerror(), _dbus_string_append(), _dbus_string_set_length(), DBusDirIter::d, dbus_set_error(), FALSE, NULL, and TRUE.

{
  struct dirent *ent;

  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
  
 again:
  errno = 0;
  ent = readdir (iter->d);
  if (ent == NULL)
    {
      if (errno != 0)
        dbus_set_error (error,
                        _dbus_error_from_errno (errno),
                        "%s", _dbus_strerror (errno));
      return FALSE;
    }
  else if (ent->d_name[0] == '.' &&
           (ent->d_name[1] == '\0' ||
            (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
    goto again;
  else
    {
      _dbus_string_set_length (filename, 0);
      if (!_dbus_string_append (filename, ent->d_name))
        {
          dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
                          "No memory to read directory entry");
          return FALSE;
        }
      else
        return TRUE;
    }
}


Generated by  Doxygen 1.6.0   Back to index