D-Bus 1.4.1
|
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ 00002 /* dbus-sysdeps.c Wrappers around system/libc features shared between UNIX and Windows (internal to D-Bus implementation) 00003 * 00004 * Copyright (C) 2002, 2003, 2006 Red Hat, Inc. 00005 * Copyright (C) 2003 CodeFactory AB 00006 * 00007 * Licensed under the Academic Free License version 2.1 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 */ 00024 00025 #include <config.h> 00026 #include "dbus-internals.h" 00027 #include "dbus-sysdeps.h" 00028 #include "dbus-threads.h" 00029 #include "dbus-protocol.h" 00030 #include "dbus-string.h" 00031 #include "dbus-list.h" 00032 00033 /* NOTE: If you include any unix/windows-specific headers here, you are probably doing something 00034 * wrong and should be putting some code in dbus-sysdeps-unix.c or dbus-sysdeps-win.c. 00035 * 00036 * These are the standard ANSI C headers... 00037 */ 00038 #if HAVE_LOCALE_H 00039 #include <locale.h> 00040 #endif 00041 #include <stdlib.h> 00042 #include <string.h> 00043 #include <stdio.h> 00044 00045 #ifdef HAVE_ERRNO_H 00046 #include <errno.h> 00047 #endif 00048 00049 _DBUS_DEFINE_GLOBAL_LOCK (win_fds); 00050 _DBUS_DEFINE_GLOBAL_LOCK (sid_atom_cache); 00051 _DBUS_DEFINE_GLOBAL_LOCK (system_users); 00052 00053 #ifdef DBUS_WIN 00054 #include <stdlib.h> 00055 #elif (defined __APPLE__) 00056 # include <crt_externs.h> 00057 # define environ (*_NSGetEnviron()) 00058 #else 00059 extern char **environ; 00060 #endif 00061 00079 void 00080 _dbus_abort (void) 00081 { 00082 const char *s; 00083 00084 _dbus_print_backtrace (); 00085 00086 s = _dbus_getenv ("DBUS_BLOCK_ON_ABORT"); 00087 if (s && *s) 00088 { 00089 /* don't use _dbus_warn here since it can _dbus_abort() */ 00090 fprintf (stderr, " Process %lu sleeping for gdb attach\n", _dbus_pid_for_log ()); 00091 _dbus_sleep_milliseconds (1000 * 180); 00092 } 00093 00094 abort (); 00095 _dbus_exit (1); /* in case someone manages to ignore SIGABRT ? */ 00096 } 00097 00111 dbus_bool_t 00112 _dbus_setenv (const char *varname, 00113 const char *value) 00114 { 00115 _dbus_assert (varname != NULL); 00116 00117 if (value == NULL) 00118 { 00119 #ifdef HAVE_UNSETENV 00120 unsetenv (varname); 00121 return TRUE; 00122 #else 00123 char *putenv_value; 00124 size_t len; 00125 00126 len = strlen (varname); 00127 00128 /* Use system malloc to avoid memleaks that dbus_malloc 00129 * will get upset about. 00130 */ 00131 00132 putenv_value = malloc (len + 2); 00133 if (putenv_value == NULL) 00134 return FALSE; 00135 00136 strcpy (putenv_value, varname); 00137 #if defined(DBUS_WIN) 00138 strcat (putenv_value, "="); 00139 #endif 00140 00141 return (putenv (putenv_value) == 0); 00142 #endif 00143 } 00144 else 00145 { 00146 #ifdef HAVE_SETENV 00147 return (setenv (varname, value, TRUE) == 0); 00148 #else 00149 char *putenv_value; 00150 size_t len; 00151 size_t varname_len; 00152 size_t value_len; 00153 00154 varname_len = strlen (varname); 00155 value_len = strlen (value); 00156 00157 len = varname_len + value_len + 1 /* '=' */ ; 00158 00159 /* Use system malloc to avoid memleaks that dbus_malloc 00160 * will get upset about. 00161 */ 00162 00163 putenv_value = malloc (len + 1); 00164 if (putenv_value == NULL) 00165 return FALSE; 00166 00167 strcpy (putenv_value, varname); 00168 strcpy (putenv_value + varname_len, "="); 00169 strcpy (putenv_value + varname_len + 1, value); 00170 00171 return (putenv (putenv_value) == 0); 00172 #endif 00173 } 00174 } 00175 00182 const char* 00183 _dbus_getenv (const char *varname) 00184 { 00185 #ifdef HAVE___SECURE_GETENV 00186 return __secure_getenv(varname); 00187 #else 00188 return getenv(varname); 00189 #endif 00190 } 00191 00197 dbus_bool_t 00198 _dbus_clearenv (void) 00199 { 00200 dbus_bool_t rc = TRUE; 00201 00202 #ifdef HAVE_CLEARENV 00203 if (clearenv () != 0) 00204 rc = FALSE; 00205 #else 00206 00207 if (environ != NULL) 00208 environ[0] = NULL; 00209 #endif 00210 00211 return rc; 00212 } 00213 00220 char ** 00221 _dbus_get_environment (void) 00222 { 00223 int i, length; 00224 char **environment; 00225 00226 _dbus_assert (environ != NULL); 00227 00228 for (length = 0; environ[length] != NULL; length++); 00229 00230 /* Add one for NULL */ 00231 length++; 00232 00233 environment = dbus_new0 (char *, length); 00234 00235 if (environment == NULL) 00236 return NULL; 00237 00238 for (i = 0; environ[i] != NULL; i++) 00239 { 00240 environment[i] = _dbus_strdup (environ[i]); 00241 00242 if (environment[i] == NULL) 00243 break; 00244 } 00245 00246 if (environ[i] != NULL) 00247 { 00248 dbus_free_string_array (environment); 00249 environment = NULL; 00250 } 00251 00252 return environment; 00253 } 00254 00263 dbus_bool_t 00264 _dbus_split_paths_and_append (DBusString *dirs, 00265 const char *suffix, 00266 DBusList **dir_list) 00267 { 00268 int start; 00269 int i; 00270 int len; 00271 char *cpath; 00272 DBusString file_suffix; 00273 00274 start = 0; 00275 i = 0; 00276 00277 _dbus_string_init_const (&file_suffix, suffix); 00278 00279 len = _dbus_string_get_length (dirs); 00280 00281 while (_dbus_string_find (dirs, start, _DBUS_PATH_SEPARATOR, &i)) 00282 { 00283 DBusString path; 00284 00285 if (!_dbus_string_init (&path)) 00286 goto oom; 00287 00288 if (!_dbus_string_copy_len (dirs, 00289 start, 00290 i - start, 00291 &path, 00292 0)) 00293 { 00294 _dbus_string_free (&path); 00295 goto oom; 00296 } 00297 00298 _dbus_string_chop_white (&path); 00299 00300 /* check for an empty path */ 00301 if (_dbus_string_get_length (&path) == 0) 00302 goto next; 00303 00304 if (!_dbus_concat_dir_and_file (&path, 00305 &file_suffix)) 00306 { 00307 _dbus_string_free (&path); 00308 goto oom; 00309 } 00310 00311 if (!_dbus_string_copy_data(&path, &cpath)) 00312 { 00313 _dbus_string_free (&path); 00314 goto oom; 00315 } 00316 00317 if (!_dbus_list_append (dir_list, cpath)) 00318 { 00319 _dbus_string_free (&path); 00320 dbus_free (cpath); 00321 goto oom; 00322 } 00323 00324 next: 00325 _dbus_string_free (&path); 00326 start = i + 1; 00327 } 00328 00329 if (start != len) 00330 { 00331 DBusString path; 00332 00333 if (!_dbus_string_init (&path)) 00334 goto oom; 00335 00336 if (!_dbus_string_copy_len (dirs, 00337 start, 00338 len - start, 00339 &path, 00340 0)) 00341 { 00342 _dbus_string_free (&path); 00343 goto oom; 00344 } 00345 00346 if (!_dbus_concat_dir_and_file (&path, 00347 &file_suffix)) 00348 { 00349 _dbus_string_free (&path); 00350 goto oom; 00351 } 00352 00353 if (!_dbus_string_copy_data(&path, &cpath)) 00354 { 00355 _dbus_string_free (&path); 00356 goto oom; 00357 } 00358 00359 if (!_dbus_list_append (dir_list, cpath)) 00360 { 00361 _dbus_string_free (&path); 00362 dbus_free (cpath); 00363 goto oom; 00364 } 00365 00366 _dbus_string_free (&path); 00367 } 00368 00369 return TRUE; 00370 00371 oom: 00372 _dbus_list_foreach (dir_list, (DBusForeachFunction)dbus_free, NULL); 00373 _dbus_list_clear (dir_list); 00374 return FALSE; 00375 } 00376 00391 dbus_bool_t 00392 _dbus_string_append_int (DBusString *str, 00393 long value) 00394 { 00395 /* this calculation is from comp.lang.c faq */ 00396 #define MAX_LONG_LEN ((sizeof (long) * 8 + 2) / 3 + 1) /* +1 for '-' */ 00397 int orig_len; 00398 int i; 00399 char *buf; 00400 00401 orig_len = _dbus_string_get_length (str); 00402 00403 if (!_dbus_string_lengthen (str, MAX_LONG_LEN)) 00404 return FALSE; 00405 00406 buf = _dbus_string_get_data_len (str, orig_len, MAX_LONG_LEN); 00407 00408 snprintf (buf, MAX_LONG_LEN, "%ld", value); 00409 00410 i = 0; 00411 while (*buf) 00412 { 00413 ++buf; 00414 ++i; 00415 } 00416 00417 _dbus_string_shorten (str, MAX_LONG_LEN - i); 00418 00419 return TRUE; 00420 } 00421 00429 dbus_bool_t 00430 _dbus_string_append_uint (DBusString *str, 00431 unsigned long value) 00432 { 00433 /* this is wrong, but definitely on the high side. */ 00434 #define MAX_ULONG_LEN (MAX_LONG_LEN * 2) 00435 int orig_len; 00436 int i; 00437 char *buf; 00438 00439 orig_len = _dbus_string_get_length (str); 00440 00441 if (!_dbus_string_lengthen (str, MAX_ULONG_LEN)) 00442 return FALSE; 00443 00444 buf = _dbus_string_get_data_len (str, orig_len, MAX_ULONG_LEN); 00445 00446 snprintf (buf, MAX_ULONG_LEN, "%lu", value); 00447 00448 i = 0; 00449 while (*buf) 00450 { 00451 ++buf; 00452 ++i; 00453 } 00454 00455 _dbus_string_shorten (str, MAX_ULONG_LEN - i); 00456 00457 return TRUE; 00458 } 00459 00460 #ifdef DBUS_BUILD_TESTS 00461 00468 dbus_bool_t 00469 _dbus_string_append_double (DBusString *str, 00470 double value) 00471 { 00472 #define MAX_DOUBLE_LEN 64 /* this is completely made up :-/ */ 00473 int orig_len; 00474 char *buf; 00475 int i; 00476 00477 orig_len = _dbus_string_get_length (str); 00478 00479 if (!_dbus_string_lengthen (str, MAX_DOUBLE_LEN)) 00480 return FALSE; 00481 00482 buf = _dbus_string_get_data_len (str, orig_len, MAX_DOUBLE_LEN); 00483 00484 snprintf (buf, MAX_LONG_LEN, "%g", value); 00485 00486 i = 0; 00487 while (*buf) 00488 { 00489 ++buf; 00490 ++i; 00491 } 00492 00493 _dbus_string_shorten (str, MAX_DOUBLE_LEN - i); 00494 00495 return TRUE; 00496 } 00497 #endif /* DBUS_BUILD_TESTS */ 00498 00511 dbus_bool_t 00512 _dbus_string_parse_int (const DBusString *str, 00513 int start, 00514 long *value_return, 00515 int *end_return) 00516 { 00517 long v; 00518 const char *p; 00519 char *end; 00520 00521 p = _dbus_string_get_const_data_len (str, start, 00522 _dbus_string_get_length (str) - start); 00523 00524 end = NULL; 00525 _dbus_set_errno_to_zero (); 00526 v = strtol (p, &end, 0); 00527 if (end == NULL || end == p || errno != 0) 00528 return FALSE; 00529 00530 if (value_return) 00531 *value_return = v; 00532 if (end_return) 00533 *end_return = start + (end - p); 00534 00535 return TRUE; 00536 } 00537 00550 dbus_bool_t 00551 _dbus_string_parse_uint (const DBusString *str, 00552 int start, 00553 unsigned long *value_return, 00554 int *end_return) 00555 { 00556 unsigned long v; 00557 const char *p; 00558 char *end; 00559 00560 p = _dbus_string_get_const_data_len (str, start, 00561 _dbus_string_get_length (str) - start); 00562 00563 end = NULL; 00564 _dbus_set_errno_to_zero (); 00565 v = strtoul (p, &end, 0); 00566 if (end == NULL || end == p || errno != 0) 00567 return FALSE; 00568 00569 if (value_return) 00570 *value_return = v; 00571 if (end_return) 00572 *end_return = start + (end - p); 00573 00574 return TRUE; 00575 } 00576 00577 #ifdef DBUS_BUILD_TESTS 00578 static dbus_bool_t 00579 ascii_isspace (char c) 00580 { 00581 return (c == ' ' || 00582 c == '\f' || 00583 c == '\n' || 00584 c == '\r' || 00585 c == '\t' || 00586 c == '\v'); 00587 } 00588 #endif /* DBUS_BUILD_TESTS */ 00589 00590 #ifdef DBUS_BUILD_TESTS 00591 static dbus_bool_t 00592 ascii_isdigit (char c) 00593 { 00594 return c >= '0' && c <= '9'; 00595 } 00596 #endif /* DBUS_BUILD_TESTS */ 00597 00598 #ifdef DBUS_BUILD_TESTS 00599 static dbus_bool_t 00600 ascii_isxdigit (char c) 00601 { 00602 return (ascii_isdigit (c) || 00603 (c >= 'a' && c <= 'f') || 00604 (c >= 'A' && c <= 'F')); 00605 } 00606 #endif /* DBUS_BUILD_TESTS */ 00607 00608 #ifdef DBUS_BUILD_TESTS 00609 /* Calls strtod in a locale-independent fashion, by looking at 00610 * the locale data and patching the decimal comma to a point. 00611 * 00612 * Relicensed from glib. 00613 */ 00614 static double 00615 ascii_strtod (const char *nptr, 00616 char **endptr) 00617 { 00618 /* FIXME: The Win32 C library's strtod() doesn't handle hex. 00619 * Presumably many Unixes don't either. 00620 */ 00621 00622 char *fail_pos; 00623 double val; 00624 struct lconv *locale_data; 00625 const char *decimal_point; 00626 int decimal_point_len; 00627 const char *p, *decimal_point_pos; 00628 const char *end = NULL; /* Silence gcc */ 00629 00630 fail_pos = NULL; 00631 00632 #if HAVE_LOCALECONV 00633 locale_data = localeconv (); 00634 decimal_point = locale_data->decimal_point; 00635 #else 00636 decimal_point = "."; 00637 #endif 00638 00639 decimal_point_len = strlen (decimal_point); 00640 _dbus_assert (decimal_point_len != 0); 00641 00642 decimal_point_pos = NULL; 00643 if (decimal_point[0] != '.' || 00644 decimal_point[1] != 0) 00645 { 00646 p = nptr; 00647 /* Skip leading space */ 00648 while (ascii_isspace (*p)) 00649 p++; 00650 00651 /* Skip leading optional sign */ 00652 if (*p == '+' || *p == '-') 00653 p++; 00654 00655 if (p[0] == '0' && 00656 (p[1] == 'x' || p[1] == 'X')) 00657 { 00658 p += 2; 00659 /* HEX - find the (optional) decimal point */ 00660 00661 while (ascii_isxdigit (*p)) 00662 p++; 00663 00664 if (*p == '.') 00665 { 00666 decimal_point_pos = p++; 00667 00668 while (ascii_isxdigit (*p)) 00669 p++; 00670 00671 if (*p == 'p' || *p == 'P') 00672 p++; 00673 if (*p == '+' || *p == '-') 00674 p++; 00675 while (ascii_isdigit (*p)) 00676 p++; 00677 end = p; 00678 } 00679 } 00680 else 00681 { 00682 while (ascii_isdigit (*p)) 00683 p++; 00684 00685 if (*p == '.') 00686 { 00687 decimal_point_pos = p++; 00688 00689 while (ascii_isdigit (*p)) 00690 p++; 00691 00692 if (*p == 'e' || *p == 'E') 00693 p++; 00694 if (*p == '+' || *p == '-') 00695 p++; 00696 while (ascii_isdigit (*p)) 00697 p++; 00698 end = p; 00699 } 00700 } 00701 /* For the other cases, we need not convert the decimal point */ 00702 } 00703 00704 /* Set errno to zero, so that we can distinguish zero results 00705 and underflows */ 00706 _dbus_set_errno_to_zero (); 00707 00708 if (decimal_point_pos) 00709 { 00710 char *copy, *c; 00711 00712 /* We need to convert the '.' to the locale specific decimal point */ 00713 copy = dbus_malloc (end - nptr + 1 + decimal_point_len); 00714 00715 c = copy; 00716 memcpy (c, nptr, decimal_point_pos - nptr); 00717 c += decimal_point_pos - nptr; 00718 memcpy (c, decimal_point, decimal_point_len); 00719 c += decimal_point_len; 00720 memcpy (c, decimal_point_pos + 1, end - (decimal_point_pos + 1)); 00721 c += end - (decimal_point_pos + 1); 00722 *c = 0; 00723 00724 val = strtod (copy, &fail_pos); 00725 00726 if (fail_pos) 00727 { 00728 if (fail_pos > decimal_point_pos) 00729 fail_pos = (char *)nptr + (fail_pos - copy) - (decimal_point_len - 1); 00730 else 00731 fail_pos = (char *)nptr + (fail_pos - copy); 00732 } 00733 00734 dbus_free (copy); 00735 00736 } 00737 else 00738 val = strtod (nptr, &fail_pos); 00739 00740 if (endptr) 00741 *endptr = fail_pos; 00742 00743 return val; 00744 } 00745 #endif /* DBUS_BUILD_TESTS */ 00746 00747 #ifdef DBUS_BUILD_TESTS 00748 00760 dbus_bool_t 00761 _dbus_string_parse_double (const DBusString *str, 00762 int start, 00763 double *value_return, 00764 int *end_return) 00765 { 00766 double v; 00767 const char *p; 00768 char *end; 00769 00770 p = _dbus_string_get_const_data_len (str, start, 00771 _dbus_string_get_length (str) - start); 00772 00773 /* parsing hex works on linux but isn't portable, so intercept it 00774 * here to get uniform behavior. 00775 */ 00776 if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) 00777 return FALSE; 00778 00779 end = NULL; 00780 _dbus_set_errno_to_zero (); 00781 v = ascii_strtod (p, &end); 00782 if (end == NULL || end == p || errno != 0) 00783 return FALSE; 00784 00785 if (value_return) 00786 *value_return = v; 00787 if (end_return) 00788 *end_return = start + (end - p); 00789 00790 return TRUE; 00791 } 00792 #endif /* DBUS_BUILD_TESTS */ 00793 /* DBusString group */ 00795 00801 void 00802 _dbus_generate_pseudorandom_bytes_buffer (char *buffer, 00803 int n_bytes) 00804 { 00805 long tv_usec; 00806 int i; 00807 00808 /* fall back to pseudorandom */ 00809 _dbus_verbose ("Falling back to pseudorandom for %d bytes\n", 00810 n_bytes); 00811 00812 _dbus_get_current_time (NULL, &tv_usec); 00813 srand (tv_usec); 00814 00815 i = 0; 00816 while (i < n_bytes) 00817 { 00818 double r; 00819 unsigned int b; 00820 00821 r = rand (); 00822 b = (r / (double) RAND_MAX) * 255.0; 00823 00824 buffer[i] = b; 00825 00826 ++i; 00827 } 00828 } 00829 00836 void 00837 _dbus_generate_random_bytes_buffer (char *buffer, 00838 int n_bytes) 00839 { 00840 DBusString str; 00841 00842 if (!_dbus_string_init (&str)) 00843 { 00844 _dbus_generate_pseudorandom_bytes_buffer (buffer, n_bytes); 00845 return; 00846 } 00847 00848 if (!_dbus_generate_random_bytes (&str, n_bytes)) 00849 { 00850 _dbus_string_free (&str); 00851 _dbus_generate_pseudorandom_bytes_buffer (buffer, n_bytes); 00852 return; 00853 } 00854 00855 _dbus_string_copy_to_buffer (&str, buffer, n_bytes); 00856 00857 _dbus_string_free (&str); 00858 } 00859 00868 dbus_bool_t 00869 _dbus_generate_random_ascii (DBusString *str, 00870 int n_bytes) 00871 { 00872 static const char letters[] = 00873 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; 00874 int i; 00875 int len; 00876 00877 if (!_dbus_generate_random_bytes (str, n_bytes)) 00878 return FALSE; 00879 00880 len = _dbus_string_get_length (str); 00881 i = len - n_bytes; 00882 while (i < len) 00883 { 00884 _dbus_string_set_byte (str, i, 00885 letters[_dbus_string_get_byte (str, i) % 00886 (sizeof (letters) - 1)]); 00887 00888 ++i; 00889 } 00890 00891 _dbus_assert (_dbus_string_validate_ascii (str, len - n_bytes, 00892 n_bytes)); 00893 00894 return TRUE; 00895 } 00896 00907 const char* 00908 _dbus_error_from_errno (int error_number) 00909 { 00910 switch (error_number) 00911 { 00912 case 0: 00913 return DBUS_ERROR_FAILED; 00914 00915 #ifdef EPROTONOSUPPORT 00916 case EPROTONOSUPPORT: 00917 return DBUS_ERROR_NOT_SUPPORTED; 00918 #endif 00919 #ifdef WSAEPROTONOSUPPORT 00920 case WSAEPROTONOSUPPORT: 00921 return DBUS_ERROR_NOT_SUPPORTED; 00922 #endif 00923 #ifdef EAFNOSUPPORT 00924 case EAFNOSUPPORT: 00925 return DBUS_ERROR_NOT_SUPPORTED; 00926 #endif 00927 #ifdef WSAEAFNOSUPPORT 00928 case WSAEAFNOSUPPORT: 00929 return DBUS_ERROR_NOT_SUPPORTED; 00930 #endif 00931 #ifdef ENFILE 00932 case ENFILE: 00933 return DBUS_ERROR_LIMITS_EXCEEDED; /* kernel out of memory */ 00934 #endif 00935 #ifdef EMFILE 00936 case EMFILE: 00937 return DBUS_ERROR_LIMITS_EXCEEDED; 00938 #endif 00939 #ifdef EACCES 00940 case EACCES: 00941 return DBUS_ERROR_ACCESS_DENIED; 00942 #endif 00943 #ifdef EPERM 00944 case EPERM: 00945 return DBUS_ERROR_ACCESS_DENIED; 00946 #endif 00947 #ifdef ENOBUFS 00948 case ENOBUFS: 00949 return DBUS_ERROR_NO_MEMORY; 00950 #endif 00951 #ifdef ENOMEM 00952 case ENOMEM: 00953 return DBUS_ERROR_NO_MEMORY; 00954 #endif 00955 #ifdef ECONNREFUSED 00956 case ECONNREFUSED: 00957 return DBUS_ERROR_NO_SERVER; 00958 #endif 00959 #ifdef WSAECONNREFUSED 00960 case WSAECONNREFUSED: 00961 return DBUS_ERROR_NO_SERVER; 00962 #endif 00963 #ifdef ETIMEDOUT 00964 case ETIMEDOUT: 00965 return DBUS_ERROR_TIMEOUT; 00966 #endif 00967 #ifdef WSAETIMEDOUT 00968 case WSAETIMEDOUT: 00969 return DBUS_ERROR_TIMEOUT; 00970 #endif 00971 #ifdef ENETUNREACH 00972 case ENETUNREACH: 00973 return DBUS_ERROR_NO_NETWORK; 00974 #endif 00975 #ifdef WSAENETUNREACH 00976 case WSAENETUNREACH: 00977 return DBUS_ERROR_NO_NETWORK; 00978 #endif 00979 #ifdef EADDRINUSE 00980 case EADDRINUSE: 00981 return DBUS_ERROR_ADDRESS_IN_USE; 00982 #endif 00983 #ifdef WSAEADDRINUSE 00984 case WSAEADDRINUSE: 00985 return DBUS_ERROR_ADDRESS_IN_USE; 00986 #endif 00987 #ifdef EEXIST 00988 case EEXIST: 00989 return DBUS_ERROR_FILE_EXISTS; 00990 #endif 00991 #ifdef ENOENT 00992 case ENOENT: 00993 return DBUS_ERROR_FILE_NOT_FOUND; 00994 #endif 00995 } 00996 00997 return DBUS_ERROR_FAILED; 00998 } 00999 01005 const char* 01006 _dbus_error_from_system_errno (void) 01007 { 01008 return _dbus_error_from_errno (errno); 01009 } 01010 01014 void 01015 _dbus_set_errno_to_zero (void) 01016 { 01017 #ifdef DBUS_WINCE 01018 SetLastError (0); 01019 #else 01020 errno = 0; 01021 #endif 01022 } 01023 01028 dbus_bool_t 01029 _dbus_get_is_errno_nonzero (void) 01030 { 01031 return errno != 0; 01032 } 01033 01038 dbus_bool_t 01039 _dbus_get_is_errno_enomem (void) 01040 { 01041 return errno == ENOMEM; 01042 } 01043 01048 dbus_bool_t 01049 _dbus_get_is_errno_eintr (void) 01050 { 01051 return errno == EINTR; 01052 } 01053 01058 dbus_bool_t 01059 _dbus_get_is_errno_epipe (void) 01060 { 01061 return errno == EPIPE; 01062 } 01063 01068 const char* 01069 _dbus_strerror_from_errno (void) 01070 { 01071 return _dbus_strerror (errno); 01072 } 01073 01076 /* tests in dbus-sysdeps-util.c */