2003-03-31 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / test / unbase64.c
1 #include <dbus/dbus.h>
2 #define DBUS_COMPILATION /* cheat and use string etc. */
3 #include <dbus/dbus-string.h>
4 #include <dbus/dbus-sysdeps.h>
5 #include <dbus/dbus-internals.h>
6 #undef DBUS_COMPILATION
7 #include <stdio.h>
8
9 int
10 main (int    argc,
11       char **argv)
12 {
13   DBusString contents;
14   DBusString decoded;
15   DBusString filename;
16   const char *s;
17   DBusError error;
18   
19   if (argc < 2)
20     {
21       fprintf (stderr, "Give the file to decode as an argument\n");
22       return 1;
23     }
24
25   _dbus_string_init_const (&filename, argv[1]);
26   
27   if (!_dbus_string_init (&contents))
28     return 1;
29
30   if (!_dbus_string_init (&decoded))
31     return 1;
32
33   dbus_error_init (&error);
34   if (!_dbus_file_get_contents (&contents, &filename, &error))
35     {
36       fprintf (stderr, "Failed to load file: %s\n", error.message);
37       dbus_error_free (&error);
38       return 1;
39     }
40
41   if (!_dbus_string_base64_decode (&contents, 0,
42                                    &decoded, 0))
43     return 1;
44
45   s = _dbus_string_get_const_data (&decoded);
46   
47   fputs (s, stdout);
48   
49   return 0;
50 }