Merge branch 'g-clear-pointer-no-side-effects' into 'master'
[glib.git] / gio / tests / dbus-launch.c
blob90d8d069e73d893ef7982c46a6a9992769da70f2
1 /*
2 * Mock version of dbus-launch, for gdbus-unix-addresses test
4 * Copyright © 2015 Collabora Ltd.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include <glib.h>
22 #ifndef G_OS_UNIX
23 #error This is a Unix-specific test helper
24 #endif
26 #include <errno.h>
27 #include <string.h>
28 #include <sys/types.h>
29 #include <unistd.h>
31 #define ME "GDBus mock version of dbus-launch"
33 static void
34 write_all (const void *ptr,
35 size_t len)
37 const char *p = ptr;
39 while (len > 0)
41 gssize done = write (STDOUT_FILENO, p, len);
42 int errsv = errno;
44 if (done == 0)
46 g_error ("%s: write: EOF", ME);
48 else if (done < 0)
50 if (errsv == EINTR)
51 continue;
53 g_error ("%s: write: %s", ME, g_strerror (errsv));
55 else
57 if (len < (size_t) done)
58 g_error ("%s: wrote too many bytes?", ME);
60 len -= done;
61 p += done;
66 int
67 main (int argc,
68 char *argv[])
70 pid_t pid = 0x2323;
71 long window_id = 0x42424242;
72 const char *addr = "hello:this=address-is-from-the,mock=dbus-launch";
74 write_all (addr, strlen (addr) + 1);
75 write_all (&pid, sizeof (pid));
76 write_all (&window_id, sizeof (window_id));
77 return 0;