D-Bus 1.15.8
dbus-sysdeps.c
1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2/* dbus-sysdeps.c Wrappers around system/libc features shared between UNIX and Windows (internal to D-Bus implementation)
3 *
4 * Copyright (C) 2002, 2003, 2006 Red Hat, Inc.
5 * Copyright (C) 2003 CodeFactory AB
6 *
7 * SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
8 *
9 * Licensed under the Academic Free License version 2.1
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 */
26
27#include <config.h>
28#include "dbus-internals.h"
29#include "dbus-sysdeps.h"
30#include "dbus-threads.h"
31#include "dbus-protocol.h"
32#include "dbus-string.h"
33#include "dbus-list.h"
34#include "dbus-misc.h"
35
36/* NOTE: If you include any unix/windows-specific headers here, you are probably doing something
37 * wrong and should be putting some code in dbus-sysdeps-unix.c or dbus-sysdeps-win.c.
38 *
39 * These are the standard ANSI C headers...
40 */
41#if HAVE_LOCALE_H
42#include <locale.h>
43#endif
44#include <stdlib.h>
45#include <string.h>
46#include <stdio.h>
47
48#ifdef HAVE_ERRNO_H
49#include <errno.h>
50#endif
51
52#ifdef DBUS_WIN
53 #include <stdlib.h>
54#elif (defined __APPLE__)
55# include <crt_externs.h>
56# define environ (*_NSGetEnviron())
57#elif HAVE_DECL_ENVIRON && defined(HAVE_UNISTD_H)
58# include <unistd.h>
59#else
60extern char **environ;
61#endif
62
63#ifdef DBUS_WIN
64#include "dbus-sockets-win.h"
65#else
66#include <arpa/inet.h>
67#include <netinet/in.h>
68#include <sys/socket.h>
69#endif
70
88void
90{
91 const char *s;
92
93 _dbus_print_backtrace ();
94
95 s = _dbus_getenv ("DBUS_BLOCK_ON_ABORT");
96 if (s && *s)
97 {
98 /* don't use _dbus_warn here since it can _dbus_abort() */
99 fprintf (stderr, " Process %lu sleeping for gdb attach\n", _dbus_pid_for_log ());
100 _dbus_sleep_milliseconds (1000 * 180);
101 }
102
103 abort ();
104 _dbus_exit (1); /* in case someone manages to ignore SIGABRT ? */
105}
106
126dbus_setenv (const char *varname,
127 const char *value)
128{
129 _dbus_assert (varname != NULL);
130
131 if (value == NULL)
132 {
133#ifdef HAVE_UNSETENV
134 unsetenv (varname);
135 return TRUE;
136#else
137 char *putenv_value;
138 size_t len;
139
140 len = strlen (varname);
141
142 /* Use system malloc to avoid memleaks that dbus_malloc
143 * will get upset about.
144 */
145
146 putenv_value = malloc (len + 2);
147 if (putenv_value == NULL)
148 return FALSE;
149
150 strcpy (putenv_value, varname);
151#if defined(DBUS_WIN)
152 strcat (putenv_value, "=");
153#endif
154
155 return (putenv (putenv_value) == 0);
156#endif
157 }
158 else
159 {
160#ifdef HAVE_SETENV
161 return (setenv (varname, value, TRUE) == 0);
162#else
163 char *putenv_value;
164 size_t len;
165 size_t varname_len;
166 size_t value_len;
167
168 varname_len = strlen (varname);
169 value_len = strlen (value);
170
171 len = varname_len + value_len + 1 /* '=' */ ;
172
173 /* Use system malloc to avoid memleaks that dbus_malloc
174 * will get upset about.
175 */
176
177 putenv_value = malloc (len + 1);
178 if (putenv_value == NULL)
179 return FALSE;
180
181 strcpy (putenv_value, varname);
182 strcpy (putenv_value + varname_len, "=");
183 strcpy (putenv_value + varname_len + 1, value);
184
185 return (putenv (putenv_value) == 0);
186#endif
187 }
188}
189
196const char*
197_dbus_getenv (const char *varname)
198{
199 /* Don't respect any environment variables if the current process is
200 * setuid. This is the equivalent of glibc's __secure_getenv().
201 */
202 if (_dbus_check_setuid ())
203 return NULL;
204 return getenv (varname);
205}
206
214{
215 dbus_bool_t rc = TRUE;
216
217#ifdef HAVE_CLEARENV
218 if (clearenv () != 0)
219 rc = FALSE;
220#else
221
222 if (environ != NULL)
223 environ[0] = NULL;
224#endif
225
226 return rc;
227}
228
239 const char *suffix,
240 DBusList **dir_list)
241{
242 int start;
243 int i;
244 int len;
245 char *cpath;
246 DBusString file_suffix;
247
248 start = 0;
249 i = 0;
250
251 _dbus_string_init_const (&file_suffix, suffix);
252
253 len = _dbus_string_get_length (dirs);
254
255 while (_dbus_string_find (dirs, start, _DBUS_PATH_SEPARATOR, &i))
256 {
257 DBusString path;
258
259 if (!_dbus_string_init (&path))
260 goto oom;
261
262 if (!_dbus_string_copy_len (dirs,
263 start,
264 i - start,
265 &path,
266 0))
267 {
268 _dbus_string_free (&path);
269 goto oom;
270 }
271
273
274 /* check for an empty path */
275 if (_dbus_string_get_length (&path) == 0)
276 goto next;
277
278 if (!_dbus_concat_dir_and_file (&path,
279 &file_suffix))
280 {
281 _dbus_string_free (&path);
282 goto oom;
283 }
284
285 if (!_dbus_string_copy_data(&path, &cpath))
286 {
287 _dbus_string_free (&path);
288 goto oom;
289 }
290
291 if (!_dbus_list_append (dir_list, cpath))
292 {
293 _dbus_string_free (&path);
294 dbus_free (cpath);
295 goto oom;
296 }
297
298 next:
299 _dbus_string_free (&path);
300 start = i + 1;
301 }
302
303 if (start != len)
304 {
305 DBusString path;
306
307 if (!_dbus_string_init (&path))
308 goto oom;
309
310 if (!_dbus_string_copy_len (dirs,
311 start,
312 len - start,
313 &path,
314 0))
315 {
316 _dbus_string_free (&path);
317 goto oom;
318 }
319
320 if (!_dbus_concat_dir_and_file (&path,
321 &file_suffix))
322 {
323 _dbus_string_free (&path);
324 goto oom;
325 }
326
327 if (!_dbus_string_copy_data(&path, &cpath))
328 {
329 _dbus_string_free (&path);
330 goto oom;
331 }
332
333 if (!_dbus_list_append (dir_list, cpath))
334 {
335 _dbus_string_free (&path);
336 dbus_free (cpath);
337 goto oom;
338 }
339
340 _dbus_string_free (&path);
341 }
342
343 return TRUE;
344
345 oom:
347 return FALSE;
348}
349
366 long value)
367{
368 /* this calculation is from comp.lang.c faq */
369#define MAX_LONG_LEN ((sizeof (long) * 8 + 2) / 3 + 1) /* +1 for '-' */
370 int orig_len;
371 int i;
372 char *buf;
373
374 orig_len = _dbus_string_get_length (str);
375
376 if (!_dbus_string_lengthen (str, MAX_LONG_LEN))
377 return FALSE;
378
379 buf = _dbus_string_get_data_len (str, orig_len, MAX_LONG_LEN);
380
381 snprintf (buf, MAX_LONG_LEN, "%ld", value);
382
383 i = 0;
384 while (*buf)
385 {
386 ++buf;
387 ++i;
388 }
389
390 _dbus_string_shorten (str, MAX_LONG_LEN - i);
391
392 return TRUE;
393}
394
404 unsigned long value)
405{
406 /* this is wrong, but definitely on the high side. */
407#define MAX_ULONG_LEN (MAX_LONG_LEN * 2)
408 int orig_len;
409 int i;
410 char *buf;
411
412 orig_len = _dbus_string_get_length (str);
413
414 if (!_dbus_string_lengthen (str, MAX_ULONG_LEN))
415 return FALSE;
416
417 buf = _dbus_string_get_data_len (str, orig_len, MAX_ULONG_LEN);
418
419 snprintf (buf, MAX_ULONG_LEN, "%lu", value);
420
421 i = 0;
422 while (*buf)
423 {
424 ++buf;
425 ++i;
426 }
427
428 _dbus_string_shorten (str, MAX_ULONG_LEN - i);
429
430 return TRUE;
431}
432
447 int start,
448 long *value_return,
449 int *end_return)
450{
451 long v;
452 const char *p;
453 char *end;
454
455 p = _dbus_string_get_const_data_len (str, start,
456 _dbus_string_get_length (str) - start);
457
458 end = NULL;
460 v = strtol (p, &end, 0);
461 if (end == NULL || end == p || errno != 0)
462 return FALSE;
463
464 if (value_return)
465 *value_return = v;
466 if (end_return)
467 *end_return = start + (end - p);
468
469 return TRUE;
470}
471
486 int start,
487 unsigned long *value_return,
488 int *end_return)
489{
490 unsigned long v;
491 const char *p;
492 char *end;
493
494 p = _dbus_string_get_const_data_len (str, start,
495 _dbus_string_get_length (str) - start);
496
497 end = NULL;
499 v = strtoul (p, &end, 0);
500 if (end == NULL || end == p || errno != 0)
501 return FALSE;
502
503 if (value_return)
504 *value_return = v;
505 if (end_return)
506 *end_return = start + (end - p);
507
508 return TRUE;
509}
510 /* DBusString group */
512
528 int n_bytes,
529 DBusError *error)
530{
531 DBusString str;
532
533 if (!_dbus_string_init (&str))
534 {
535 _DBUS_SET_OOM (error);
536 return FALSE;
537 }
538
539 if (!_dbus_generate_random_bytes (&str, n_bytes, error))
540 {
541 _dbus_string_free (&str);
542 return FALSE;
543 }
544
545 _dbus_string_copy_to_buffer (&str, buffer, n_bytes);
546
547 _dbus_string_free (&str);
548 return TRUE;
549}
550
562 int n_bytes,
563 DBusError *error)
564{
565 static const char letters[] =
566 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
567 int i;
568 int len;
569
570 if (!_dbus_generate_random_bytes (str, n_bytes, error))
571 return FALSE;
572
573 len = _dbus_string_get_length (str);
574 i = len - n_bytes;
575 while (i < len)
576 {
577 _dbus_string_set_byte (str, i,
578 letters[_dbus_string_get_byte (str, i) %
579 (sizeof (letters) - 1)]);
580
581 ++i;
582 }
583
584 _dbus_assert (_dbus_string_validate_ascii (str, len - n_bytes,
585 n_bytes));
586
587 return TRUE;
588}
589
600const char*
601_dbus_error_from_errno (int error_number)
602{
603 switch (error_number)
604 {
605 case 0:
606 return DBUS_ERROR_FAILED;
607
608#ifdef EPROTONOSUPPORT
609 case EPROTONOSUPPORT:
611#elif defined(WSAEPROTONOSUPPORT)
612 case WSAEPROTONOSUPPORT:
614#endif
615#ifdef EAFNOSUPPORT
616 case EAFNOSUPPORT:
618#elif defined(WSAEAFNOSUPPORT)
619 case WSAEAFNOSUPPORT:
621#endif
622#ifdef ENFILE
623 case ENFILE:
624 return DBUS_ERROR_LIMITS_EXCEEDED; /* kernel out of memory */
625#endif
626#ifdef EMFILE
627 case EMFILE:
629#endif
630#ifdef EACCES
631 case EACCES:
633#endif
634#ifdef EPERM
635 case EPERM:
637#endif
638#ifdef ENOBUFS
639 case ENOBUFS:
641#endif
642#ifdef ENOMEM
643 case ENOMEM:
645#endif
646#ifdef ECONNREFUSED
647 case ECONNREFUSED:
649#elif defined(WSAECONNREFUSED)
650 case WSAECONNREFUSED:
652#endif
653#ifdef ETIMEDOUT
654 case ETIMEDOUT:
655 return DBUS_ERROR_TIMEOUT;
656#elif defined(WSAETIMEDOUT)
657 case WSAETIMEDOUT:
658 return DBUS_ERROR_TIMEOUT;
659#endif
660#ifdef ENETUNREACH
661 case ENETUNREACH:
663#elif defined(WSAENETUNREACH)
664 case WSAENETUNREACH:
666#endif
667#ifdef EADDRINUSE
668 case EADDRINUSE:
670#elif defined(WSAEADDRINUSE)
671 case WSAEADDRINUSE:
673#endif
674#ifdef EEXIST
675 case EEXIST:
677#endif
678#ifdef ENOENT
679 case ENOENT:
681#endif
682 default:
683 return DBUS_ERROR_FAILED;
684 }
685}
686
692const char*
694{
695 return _dbus_error_from_errno (errno);
696}
697
701void
703{
704#ifdef DBUS_WINCE
705 SetLastError (0);
706#else
707 errno = 0;
708#endif
709}
710
717{
718 return e == ENOMEM;
719}
720
727{
728 return e == EINTR;
729}
730
737{
738 return e == EPIPE;
739}
740
747{
748#ifdef ETOOMANYREFS
749 return e == ETOOMANYREFS;
750#else
751 return FALSE;
752#endif
753}
754
759const char*
761{
762 return _dbus_strerror (errno);
763}
764
771void
772_dbus_log (DBusSystemLogSeverity severity,
773 const char *msg,
774 ...)
775{
776 va_list args;
777
778 va_start (args, msg);
779
780 _dbus_logv (severity, msg, args);
781
782 va_end (args);
783}
784
785/*
786 * Try to convert the IPv4 or IPv6 address pointed to by
787 * sockaddr_pointer into a string.
788 *
789 * @param sockaddr_pointer A struct sockaddr_in or struct sockaddr_in6
790 * @param len The length of the struct pointed to by sockaddr_pointer
791 * @param string An array to write the address into
792 * @param string_len Length of string (should usually be at least INET6_ADDRSTRLEN)
793 * @param family_name Used to return "ipv4" or "ipv6", or NULL to ignore
794 * @param port Used to return the port number, or NULL to ignore
795 * @returns #FALSE with errno set if the address family was not understood
796 */
798_dbus_inet_sockaddr_to_string (const void *sockaddr_pointer,
799 size_t len,
800 char *string,
801 size_t string_len,
802 const char **family_name,
803 dbus_uint16_t *port,
804 DBusError *error)
805{
806 union
807 {
808 struct sockaddr sa;
809 struct sockaddr_storage storage;
810 struct sockaddr_in ipv4;
811 struct sockaddr_in6 ipv6;
812 } addr;
813 int saved_errno;
814
815 if (len > sizeof (addr))
816 return FALSE;
817
818 _DBUS_ZERO (addr);
819 memcpy (&addr, sockaddr_pointer, len);
820
821 switch (addr.sa.sa_family)
822 {
823 case AF_INET:
824 if (inet_ntop (AF_INET, &addr.ipv4.sin_addr, string, string_len) != NULL)
825 {
826 if (family_name != NULL)
827 *family_name = "ipv4";
828
829 if (port != NULL)
830 *port = ntohs (addr.ipv4.sin_port);
831
832 return TRUE;
833 }
834 else
835 {
836 saved_errno = _dbus_get_low_level_socket_errno ();
837 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
838 "Failed to get identity of IPv4 socket: %s",
839 _dbus_strerror (saved_errno));
840 }
841
842 return FALSE;
843
844#ifdef AF_INET6
845 case AF_INET6:
846 if (inet_ntop (AF_INET6, &addr.ipv6.sin6_addr, string, string_len) != NULL)
847 {
848 if (family_name != NULL)
849 *family_name = "ipv6";
850
851 if (port != NULL)
852 *port = ntohs (addr.ipv6.sin6_port);
853
854 return TRUE;
855 }
856 else
857 {
858 saved_errno = _dbus_get_low_level_socket_errno ();
859 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
860 "Failed to get identity of IPv6 socket: %s",
861 _dbus_strerror (saved_errno));
862 }
863
864 return FALSE;
865#endif
866
867 default:
869 "Failed to get identity of socket: unknown family");
870 return FALSE;
871 }
872}
873
874/*
875 * Format an error appropriate for saved_errno for the IPv4 or IPv6
876 * address pointed to by sockaddr_pointer of length sockaddr_len.
877 *
878 * @param error The error to set
879 * @param sockaddr_pointer A struct sockaddr_in or struct sockaddr_in6
880 * @param len The length of the struct pointed to by sockaddr_pointer
881 * @param description A prefix like "Failed to listen on socket"
882 * @param saved_errno The OS-level error number to use
883 */
884void
885_dbus_set_error_with_inet_sockaddr (DBusError *error,
886 const void *sockaddr_pointer,
887 size_t len,
888 const char *description,
889 int saved_errno)
890{
891 char string[INET6_ADDRSTRLEN];
892 dbus_uint16_t port;
893 const struct sockaddr *addr = sockaddr_pointer;
894
895 if (_dbus_inet_sockaddr_to_string (sockaddr_pointer, len,
896 string, sizeof (string), NULL, &port,
897 NULL))
898 {
899 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
900 "%s \"%s\" port %u: %s",
901 description, string, port, _dbus_strerror (saved_errno));
902 }
903 else
904 {
905 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
906 "%s <address of unknown family %d>: %s",
907 description, addr->sa_family,
908 _dbus_strerror (saved_errno));
909 }
910}
911
912void
913_dbus_combine_tcp_errors (DBusList **sources,
914 const char *summary,
915 const char *host,
916 const char *port,
917 DBusError *dest)
918{
919 DBusString message = _DBUS_STRING_INIT_INVALID;
920
921 if (_dbus_list_length_is_one (sources))
922 {
923 /* If there was exactly one error, just use it */
924 dbus_move_error (_dbus_list_get_first (sources), dest);
925 }
926 else
927 {
928 DBusList *iter;
929 const char *name = NULL;
930
931 /* If there was more than one error, concatenate all the
932 * errors' diagnostic messages, and use their common error
933 * name, or DBUS_ERROR_FAILED if more than one name is
934 * represented */
935 if (!_dbus_string_init (&message))
936 {
937 _DBUS_SET_OOM (dest);
938 goto out;
939 }
940
941 for (iter = _dbus_list_get_first_link (sources);
942 iter != NULL;
943 iter = _dbus_list_get_next_link (sources, iter))
944 {
945 DBusError *error = iter->data;
946
947 if (name == NULL)
948 {
949 /* no error names known yet, try to use this one */
950 name = error->name;
951 }
952 else if (strcmp (name, error->name) != 0)
953 {
954 /* errors of two different names exist, reconcile by
955 * using FAILED */
956 name = DBUS_ERROR_FAILED;
957 }
958
959 if ((_dbus_string_get_length (&message) > 0 &&
960 !_dbus_string_append (&message, "; ")) ||
961 !_dbus_string_append (&message, error->message))
962 {
963 _DBUS_SET_OOM (dest);
964 goto out;
965 }
966 }
967
968 if (name == NULL)
969 name = DBUS_ERROR_FAILED;
970
971 dbus_set_error (dest, name, "%s to \"%s\":%s (%s)",
972 summary, host ? host : "*", port,
973 _dbus_string_get_const_data (&message));
974 }
975
976out:
977 _dbus_string_free (&message);
978}
979
982/* tests in dbus-sysdeps-util.c */
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition: dbus-errors.c:281
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition: dbus-errors.c:356
dbus_bool_t _dbus_get_is_errno_epipe(int e)
See if errno is EPIPE.
Definition: dbus-sysdeps.c:736
dbus_bool_t _dbus_get_is_errno_etoomanyrefs(int e)
See if errno is ETOOMANYREFS.
Definition: dbus-sysdeps.c:746
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
void _dbus_log(DBusSystemLogSeverity severity, const char *msg,...)
Log a message to the system log file (e.g.
Definition: dbus-sysdeps.c:772
const char * _dbus_error_from_errno(int error_number)
Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.
Definition: dbus-sysdeps.c:601
dbus_bool_t _dbus_generate_random_ascii(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII su...
Definition: dbus-sysdeps.c:561
const char * _dbus_error_from_system_errno(void)
Converts the current system errno value into a DBusError name.
Definition: dbus-sysdeps.c:693
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
Definition: dbus-sysdeps.c:760
dbus_bool_t _dbus_get_is_errno_eintr(int e)
See if errno is EINTR.
Definition: dbus-sysdeps.c:726
#define _DBUS_ZERO(object)
Sets all bits in an object to zero.
void _dbus_set_errno_to_zero(void)
Assign 0 to the global errno variable.
Definition: dbus-sysdeps.c:702
dbus_bool_t _dbus_get_is_errno_enomem(int e)
See if errno is ENOMEM.
Definition: dbus-sysdeps.c:716
dbus_bool_t _dbus_generate_random_bytes_buffer(char *buffer, int n_bytes, DBusError *error)
Fills n_bytes of the given buffer with random bytes.
Definition: dbus-sysdeps.c:527
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
Definition: dbus-list.c:597
dbus_bool_t _dbus_list_length_is_one(DBusList **list)
Check whether length is exactly one.
Definition: dbus-list.c:813
void _dbus_list_clear_full(DBusList **list, DBusFreeFunction function)
Free every link and every element in the list.
Definition: dbus-list.c:570
void * _dbus_list_get_first(DBusList **list)
Gets the first data in the list.
Definition: dbus-list.c:642
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
Definition: dbus-list.c:273
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
Definition: dbus-list.h:121
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:694
dbus_bool_t dbus_setenv(const char *varname, const char *value)
Wrapper for setenv().
Definition: dbus-sysdeps.c:126
#define DBUS_ERROR_TIMEOUT
Certain timeout errors, possibly ETIMEDOUT on a socket.
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn't supported (like ENOSYS on UNIX).
#define DBUS_ERROR_ADDRESS_IN_USE
Can't bind a socket since its address is in use (i.e.
#define DBUS_ERROR_ACCESS_DENIED
Security restrictions don't allow doing what you're trying to do.
#define DBUS_ERROR_NO_SERVER
Unable to connect to server (probably caused by ECONNREFUSED on a socket).
#define DBUS_ERROR_FILE_EXISTS
Existing file and the operation you're using does not silently overwrite.
#define DBUS_ERROR_LIMITS_EXCEEDED
Some limited resource is exhausted.
#define DBUS_ERROR_NO_NETWORK
No network access (probably ENETUNREACH on a socket).
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define DBUS_ERROR_FILE_NOT_FOUND
Missing file.
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
Definition: dbus-string.c:980
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:182
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:197
dbus_bool_t _dbus_string_append_int(DBusString *str, long value)
Appends an integer to a DBusString.
Definition: dbus-sysdeps.c:365
dbus_bool_t _dbus_string_find(const DBusString *str, int start, const char *substr, int *found)
Finds the given substring in the string, returning TRUE and filling in the byte index where the subst...
Definition: dbus-string.c:1666
char * _dbus_string_get_data_len(DBusString *str, int start, int len)
Gets a sub-portion of the raw character buffer from the string.
Definition: dbus-string.c:535
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
Definition: dbus-string.c:278
void _dbus_string_shorten(DBusString *str, int length_to_remove)
Makes a string shorter by the given number of bytes.
Definition: dbus-string.c:825
dbus_bool_t _dbus_string_copy_data(const DBusString *str, char **data_return)
Copies the data from the string into a char*.
Definition: dbus-string.c:717
dbus_bool_t _dbus_string_parse_uint(const DBusString *str, int start, unsigned long *value_return, int *end_return)
Parses an unsigned integer contained in a DBusString.
Definition: dbus-sysdeps.c:485
dbus_bool_t _dbus_string_lengthen(DBusString *str, int additional_length)
Makes a string longer by the given number of bytes.
Definition: dbus-string.c:805
dbus_bool_t _dbus_string_parse_int(const DBusString *str, int start, long *value_return, int *end_return)
Parses an integer contained in a DBusString.
Definition: dbus-sysdeps.c:446
dbus_bool_t _dbus_string_validate_ascii(const DBusString *str, int start, int len)
Checks that the given range of the string is valid ASCII with no nul bytes.
Definition: dbus-string.c:2573
int _dbus_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
Definition: dbus-string.c:784
dbus_bool_t _dbus_string_append_uint(DBusString *str, unsigned long value)
Appends an unsigned integer to a DBusString.
Definition: dbus-sysdeps.c:403
void _dbus_string_chop_white(DBusString *str)
Deletes leading and trailing whitespace.
Definition: dbus-string.c:2051
const char * _dbus_string_get_const_data_len(const DBusString *str, int start, int len)
const version of _dbus_string_get_data_len().
Definition: dbus-string.c:559
void _dbus_string_set_byte(DBusString *str, int i, unsigned char byte)
Sets the value of the byte at the given position.
Definition: dbus-string.c:583
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
Definition: dbus-string.c:513
unsigned char _dbus_string_get_byte(const DBusString *str, int start)
Gets the byte at the given position.
Definition: dbus-string.c:607
dbus_bool_t _dbus_string_copy_len(const DBusString *source, int start, int len, DBusString *dest, int insert_at)
Like _dbus_string_copy(), but can copy a segment from the middle of the source string.
Definition: dbus-string.c:1437
void _dbus_string_copy_to_buffer(const DBusString *str, char *buffer, int avail_len)
Copies the contents of a DBusString into a different buffer.
Definition: dbus-string.c:742
void _dbus_logv(DBusSystemLogSeverity severity, const char *msg, va_list args)
Log a message to the system log file (e.g.
unsigned long _dbus_pid_for_log(void)
The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not fo...
dbus_bool_t _dbus_clearenv(void)
Wrapper for clearenv().
Definition: dbus-sysdeps.c:213
void _dbus_exit(int code)
Exit the process, returning the given value.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:197
dbus_bool_t _dbus_check_setuid(void)
NOTE: If you modify this function, please also consider making the corresponding change in GLib.
void _dbus_sleep_milliseconds(int milliseconds)
Sleeps the given number of milliseconds.
dbus_bool_t _dbus_generate_random_bytes(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of securely random bytes, using the best mechanism we can come up with.
void _dbus_abort(void)
Aborts the program with SIGABRT (dumping core).
Definition: dbus-sysdeps.c:89
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
dbus_bool_t _dbus_split_paths_and_append(DBusString *dirs, const char *suffix, DBusList **dir_list)
Split paths into a list of char strings.
Definition: dbus-sysdeps.c:238
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:37
unsigned short dbus_uint16_t
A 16-bit unsigned integer on all platforms.
Object representing an exception.
Definition: dbus-errors.h:51
const char * name
public error name field
Definition: dbus-errors.h:52
const char * message
public error message field
Definition: dbus-errors.h:53
A node in a linked list.
Definition: dbus-list.h:37
void * data
Data stored at this element.
Definition: dbus-list.h:40