26 #include "dbus-internals.h"
27 #include "dbus-sysdeps.h"
28 #include "dbus-threads.h"
29 #include "dbus-protocol.h"
30 #include "dbus-string.h"
31 #include "dbus-list.h"
55 #elif (defined __APPLE__)
56 # include <crt_externs.h>
57 # define environ (*_NSGetEnviron())
59 extern char **environ;
126 len = strlen (varname);
132 putenv_value = malloc (len + 2);
133 if (putenv_value ==
NULL)
136 strcpy (putenv_value, varname);
137 #if defined(DBUS_WIN)
138 strcat (putenv_value,
"=");
141 return (putenv (putenv_value) == 0);
147 return (setenv (varname, value,
TRUE) == 0);
154 varname_len = strlen (varname);
155 value_len = strlen (value);
157 len = varname_len + value_len + 1 ;
163 putenv_value = malloc (len + 1);
164 if (putenv_value ==
NULL)
167 strcpy (putenv_value, varname);
168 strcpy (putenv_value + varname_len,
"=");
169 strcpy (putenv_value + varname_len + 1, value);
171 return (putenv (putenv_value) == 0);
190 return getenv (varname);
204 if (clearenv () != 0)
229 for (length = 0; environ[length] !=
NULL; length++);
234 environment =
dbus_new0 (
char *, length);
236 if (environment ==
NULL)
239 for (i = 0; environ[i] !=
NULL; i++)
243 if (environment[i] ==
NULL)
247 if (environ[i] !=
NULL)
397 #define MAX_LONG_LEN ((sizeof (long) * 8 + 2) / 3 + 1)
409 snprintf (buf, MAX_LONG_LEN,
"%ld", value);
435 #define MAX_ULONG_LEN (MAX_LONG_LEN * 2)
447 snprintf (buf, MAX_ULONG_LEN,
"%lu", value);
461 #ifdef DBUS_BUILD_TESTS
473 #define MAX_DOUBLE_LEN 64
485 snprintf (buf, MAX_LONG_LEN,
"%g", value);
527 v = strtol (p, &end, 0);
528 if (end ==
NULL || end == p || errno != 0)
534 *end_return = start + (end - p);
554 unsigned long *value_return,
566 v = strtoul (p, &end, 0);
567 if (end ==
NULL || end == p || errno != 0)
573 *end_return = start + (end - p);
578 #ifdef DBUS_BUILD_TESTS
580 ascii_isspace (
char c)
591 #ifdef DBUS_BUILD_TESTS
593 ascii_isdigit (
char c)
595 return c >=
'0' && c <=
'9';
599 #ifdef DBUS_BUILD_TESTS
601 ascii_isxdigit (
char c)
603 return (ascii_isdigit (c) ||
604 (c >=
'a' && c <=
'f') ||
605 (c >=
'A' && c <=
'F'));
609 #ifdef DBUS_BUILD_TESTS
616 ascii_strtod (
const char *nptr,
625 struct lconv *locale_data;
626 const char *decimal_point;
627 int decimal_point_len;
628 const char *p, *decimal_point_pos;
629 const char *end =
NULL;
634 locale_data = localeconv ();
635 decimal_point = locale_data->decimal_point;
640 decimal_point_len = strlen (decimal_point);
643 decimal_point_pos =
NULL;
644 if (decimal_point[0] !=
'.' ||
645 decimal_point[1] != 0)
649 while (ascii_isspace (*p))
653 if (*p ==
'+' || *p ==
'-')
657 (p[1] ==
'x' || p[1] ==
'X'))
662 while (ascii_isxdigit (*p))
667 decimal_point_pos = p++;
669 while (ascii_isxdigit (*p))
672 if (*p ==
'p' || *p ==
'P')
674 if (*p ==
'+' || *p ==
'-')
676 while (ascii_isdigit (*p))
683 while (ascii_isdigit (*p))
688 decimal_point_pos = p++;
690 while (ascii_isdigit (*p))
693 if (*p ==
'e' || *p ==
'E')
695 if (*p ==
'+' || *p ==
'-')
697 while (ascii_isdigit (*p))
709 if (decimal_point_pos)
714 copy =
dbus_malloc (end - nptr + 1 + decimal_point_len);
717 memcpy (c, nptr, decimal_point_pos - nptr);
718 c += decimal_point_pos - nptr;
719 memcpy (c, decimal_point, decimal_point_len);
720 c += decimal_point_len;
721 memcpy (c, decimal_point_pos + 1, end - (decimal_point_pos + 1));
722 c += end - (decimal_point_pos + 1);
725 val = strtod (copy, &fail_pos);
729 if (fail_pos > decimal_point_pos)
730 fail_pos = (
char *)nptr + (fail_pos - copy) - (decimal_point_len - 1);
732 fail_pos = (
char *)nptr + (fail_pos - copy);
739 val = strtod (nptr, &fail_pos);
748 #ifdef DBUS_BUILD_TESTS
762 _dbus_string_parse_double (
const DBusString *str,
764 double *value_return,
777 if (p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X'))
782 v = ascii_strtod (p, &end);
783 if (end ==
NULL || end == p || errno != 0)
789 *end_return = start + (end - p);
810 _dbus_verbose (
"Falling back to pseudorandom for %d bytes\n",
823 b = (r / (double) RAND_MAX) * 255.0;
873 static const char letters[] =
874 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
887 (
sizeof (letters) - 1)]);
911 switch (error_number)
916 #ifdef EPROTONOSUPPORT
917 case EPROTONOSUPPORT:
920 #ifdef WSAEPROTONOSUPPORT
921 case WSAEPROTONOSUPPORT:
928 #ifdef WSAEAFNOSUPPORT
929 case WSAEAFNOSUPPORT:
960 #ifdef WSAECONNREFUSED
961 case WSAECONNREFUSED:
976 #ifdef WSAENETUNREACH
1042 return errno == ENOMEM;
1052 return errno == EINTR;
1062 return errno == EPIPE;
1072 return _dbus_strerror (errno);