cmake: Add X11 include path for tools
[platform/upstream/dbus.git] / test / manual-dir-iter.c
1 #include <config.h>
2 #include "test-utils.h"
3
4 #include "dbus/dbus-macros.h"
5 #include "dbus/dbus-sysdeps.h"
6
7 static void oom (const char *doing) _DBUS_GNUC_NORETURN;
8 static void die (const char *message) _DBUS_GNUC_NORETURN;
9
10 void
11 oom (const char *doing)
12 {
13   fprintf (stderr, "*** manual-dir-iter: OOM while %s\n", doing);
14   exit (1);
15 }
16
17 void
18 die (const char *message)
19 {
20   fprintf (stderr, "*** manual-dir-iter: %s\n", message);
21   exit (1);
22 }
23
24 static void
25 debug (const char *message)
26 {
27   fprintf (stdout, "+++ manual-dir-iter: %s\n", message);
28 }
29
30 int
31 main (int    argc,
32       char **argv)
33 {
34   DBusString filename;
35   DBusString dirname;
36   DBusError tmp_error;
37   DBusDirIter *dir;
38
39   if (argc != 2)
40       die ("syntax: manual-dir-iter <path>");
41
42   dbus_error_init (&tmp_error);
43
44   if (!_dbus_string_init (&filename))
45       oom ("init filename");
46
47   if (!_dbus_string_init (&dirname))
48       oom ("init dirname");
49
50   if (!_dbus_string_append (&dirname, argv[1]))
51       oom ("append argv[1]");
52
53   dir = _dbus_directory_open (&dirname, &tmp_error);
54
55   if (dir == NULL)
56     {
57       fprintf (stderr, "could not open directory: %s: %s\n",
58                tmp_error.name, tmp_error.message);
59       exit(1);
60     }
61
62   while (_dbus_directory_get_next_file (dir, &filename, &tmp_error))
63     {
64       DBusString full_path;
65       if (!_dbus_string_init (&full_path))
66         {
67           oom ("init full_path");
68         }
69
70       if (!_dbus_string_copy (&dirname, 0, &full_path, 0))
71         {
72           oom ("copying full_path to dirname");
73         }
74
75       if (!_dbus_concat_dir_and_file (&full_path, &filename))
76         {
77           oom ("concat full_path");
78         }
79       debug (_dbus_string_get_const_data (&filename));
80       _dbus_string_free (&full_path);
81     }
82
83   if (dbus_error_is_set (&tmp_error))
84       die (tmp_error.message);
85
86   _dbus_string_free (&filename);
87
88   if (dir)
89     _dbus_directory_close (dir);
90
91   _dbus_verbose ("*** Test dir name exiting\n");
92
93   return 0;
94 }