dbus-marshal-byteswap: Byte-swap Unix fd indexes if needed
[platform/upstream/dbus.git] / test / manual-paths.c
1 /*
2  * Simple manual paths check
3  *
4  * syntax:  manual-paths
5  *
6 */
7
8 #include "config.h"
9 #include "dbus/dbus-list.h"
10 #include "dbus/dbus-internals.h"
11 #include "dbus/dbus-sysdeps.h"
12
13 #include <stdio.h>
14
15 static dbus_bool_t
16 print_install_root (void)
17 {
18   DBusString runtime_prefix;
19
20   if (!_dbus_string_init (&runtime_prefix))
21     {
22       _dbus_assert_not_reached ("out of memory");
23       return FALSE;
24     }
25
26   if (!_dbus_get_install_root (&runtime_prefix))
27     {
28       _dbus_assert_not_reached ("out of memory");
29       _dbus_string_free (&runtime_prefix);
30       return FALSE;
31     }
32
33   if (_dbus_string_get_length (&runtime_prefix) == 0)
34     {
35       fprintf (stderr, "_dbus_get_install_root() failed\n");
36       _dbus_string_free (&runtime_prefix);
37       return FALSE;
38     }
39
40   fprintf (stdout, "_dbus_get_install_root() returned '%s'\n",
41       _dbus_string_get_const_data (&runtime_prefix));
42   _dbus_string_free (&runtime_prefix);
43   return TRUE;
44 }
45
46 static dbus_bool_t
47 print_service_dirs (void)
48 {
49   DBusList *dirs;
50   DBusList *link;
51   dirs = NULL;
52
53   if (!_dbus_get_standard_session_servicedirs (&dirs))
54     _dbus_assert_not_reached ("couldn't get standard dirs");
55
56   while ((link = _dbus_list_pop_first_link (&dirs)))
57     {
58       printf ("default service dir: %s\n", (char *)link->data);
59       dbus_free (link->data);
60       _dbus_list_free_link (link);
61     }
62   dbus_free (dirs);
63   return TRUE;
64 }
65
66 static dbus_bool_t print_replace_install_prefix(const char *s)
67 {
68   DBusString str;
69
70   if (!_dbus_string_init (&str))
71     {
72       _dbus_assert_not_reached ("out of memory");
73       return FALSE;
74     }
75
76   if (!_dbus_string_append (&str, s) ||
77       !_dbus_replace_install_prefix (&str))
78     {
79       _dbus_assert_not_reached ("out of memory");
80       _dbus_string_free (&str);
81       return FALSE;
82     }
83
84   fprintf(stdout, "replaced '%s' by '%s'\n", s,
85       _dbus_string_get_const_data (&str));
86   _dbus_string_free (&str);
87   return TRUE;
88 }
89
90 int
91 main (int argc, char **argv)
92 {
93   if (!print_install_root())
94     return -1;
95
96   if (!print_service_dirs())
97     return -2;
98
99   if (!print_replace_install_prefix(DBUS_BINDIR "/dbus-daemon"))
100     return -3;
101
102   if (!print_replace_install_prefix("c:\\Windows\\System32\\testfile"))
103     return -4;
104
105   return 0;
106 }