Changeset 14336
- Timestamp:
- Sep 21, 2014, 6:05:14 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/remote.c
r14331 r14336 1909 1909 1910 1910 case 810: /* authenv */ 1911 auth = tr_env_get_string ("TR_AUTH", NULL); 1912 if (auth == NULL) 1911 1913 { 1912 char *authenv = getenv ("TR_AUTH"); 1913 if (!authenv) { 1914 fprintf (stderr, "The TR_AUTH environment variable is not set\n"); 1915 exit (0); 1916 } 1917 auth = tr_strdup (authenv); 1914 fprintf (stderr, "The TR_AUTH environment variable is not set\n"); 1915 exit (0); 1918 1916 } 1919 1917 break; -
trunk/libtransmission/announcer-http.c
r14241 r14336 10 10 #include <limits.h> /* USHRT_MAX */ 11 11 #include <stdio.h> /* fprintf () */ 12 #include <stdlib.h> /* getenv () */13 12 #include <string.h> /* strchr (), memcmp (), memcpy () */ 14 13 … … 212 211 const bool variant_loaded = !tr_variantFromBenc (&benc, msg, msglen); 213 212 214 if ( getenv ("TR_CURL_VERBOSE") != NULL)213 if (tr_env_key_exists ("TR_CURL_VERBOSE")) 215 214 { 216 215 if (!variant_loaded) … … 367 366 const bool variant_loaded = !tr_variantFromBenc (&top, msg, msglen); 368 367 369 if ( getenv ("TR_CURL_VERBOSE") != NULL)368 if (tr_env_key_exists ("TR_CURL_VERBOSE")) 370 369 { 371 370 if (!variant_loaded) -
trunk/libtransmission/log.c
r14334 r14336 11 11 #include <errno.h> 12 12 #include <stdio.h> 13 #include <stdlib.h> /* getenv() */14 13 15 14 #include <event2/buffer.h> … … 67 66 if (!initialized) 68 67 { 69 int fd = 0; 70 const char * str = getenv ("TR_DEBUG_FD"); 71 72 if (str && *str) 73 fd = atoi (str); 68 const int fd = tr_env_get_int ("TR_DEBUG_FD", 0); 74 69 75 70 switch (fd) -
trunk/libtransmission/platform.c
r14335 r14336 248 248 if (!home) 249 249 { 250 home = tr_ strdup (getenv ("HOME"));250 home = tr_env_get_string ("HOME", NULL); 251 251 252 252 if (!home) … … 321 321 if (!s) 322 322 { 323 if ((s = getenv ("TRANSMISSION_HOME"))) 324 { 325 s = tr_strdup (s); 326 } 327 else 323 s = tr_env_get_string ("TRANSMISSION_HOME", NULL); 324 325 if (s == NULL) 328 326 { 329 327 #ifdef __APPLE__ … … 338 336 s = tr_buildPath (buf, appname, NULL); 339 337 #else 340 if ((s = getenv ("XDG_CONFIG_HOME"))) 341 s = tr_buildPath (s, appname, NULL); 338 if ((s = tr_env_get_string ("XDG_CONFIG_HOME", NULL))) 339 { 340 s = tr_buildPath (s, appname, NULL); 341 tr_free (s); 342 } 342 343 else 343 s = tr_buildPath (getHomeDir (), ".config", appname, NULL); 344 { 345 s = tr_buildPath (getHomeDir (), ".config", appname, NULL); 346 } 344 347 #endif 345 348 } … … 356 359 if (user_dir == NULL) 357 360 { 358 c onst char * config_home;361 char * config_home; 359 362 char * config_file; 360 363 char * content; … … 362 365 363 366 /* figure out where to look for user-dirs.dirs */ 364 config_home = getenv ("XDG_CONFIG_HOME");367 config_home = tr_env_get_string ("XDG_CONFIG_HOME", NULL); 365 368 if (config_home && *config_home) 366 369 config_file = tr_buildPath (config_home, "user-dirs.dirs", NULL); 367 370 else 368 371 config_file = tr_buildPath (getHomeDir (), ".config", "user-dirs.dirs", NULL); 372 tr_free (config_home); 369 373 370 374 /* read in user-dirs.dirs and look for the download dir entry */ … … 429 433 if (!s) 430 434 { 431 if ((s = getenv ("CLUTCH_HOME"))) 432 { 433 s = tr_strdup (s); 434 } 435 else if ((s = getenv ("TRANSMISSION_WEB_HOME"))) 436 { 437 s = tr_strdup (s); 438 } 439 else 435 s = tr_env_get_string ("CLUTCH_HOME", NULL); 436 if (s == NULL) 437 s = tr_env_get_string ("TRANSMISSION_WEB_HOME", NULL); 438 if (s == NULL) 440 439 { 441 440 … … 523 522 524 523 tr_list *candidates = NULL, *l; 525 c onst char * tmp;524 char * tmp; 526 525 527 526 /* XDG_DATA_HOME should be the first in the list of candidates */ 528 tmp = getenv ("XDG_DATA_HOME");527 tmp = tr_env_get_string ("XDG_DATA_HOME", NULL); 529 528 if (tmp && *tmp) 530 529 { 531 tr_list_append (&candidates, t r_strdup (tmp));530 tr_list_append (&candidates, tmp); 532 531 } 533 532 else … … 535 534 char * dhome = tr_buildPath (getHomeDir (), ".local", "share", NULL); 536 535 tr_list_append (&candidates, dhome); 536 tr_free (tmp); 537 537 } 538 538 … … 540 540 { 541 541 const char * pkg = PACKAGE_DATA_DIR; 542 c onst char * xdg = getenv ("XDG_DATA_DIRS");542 char * xdg = tr_env_get_string ("XDG_DATA_DIRS", NULL); 543 543 const char * fallback = "/usr/local/share:/usr/share"; 544 544 char * buf = tr_strdup_printf ("%s:%s:%s", (pkg?pkg:""), (xdg?xdg:""), fallback); 545 tr_free (xdg); 545 546 tmp = buf; 546 547 while (tmp && *tmp) … … 551 552 if ((end - tmp) > 1) 552 553 tr_list_append (&candidates, tr_strndup (tmp, end - tmp)); 553 tmp = end + 1;554 tmp = (char *) end + 1; 554 555 } 555 556 else if (tmp && *tmp) -
trunk/libtransmission/tr-dht.c
r14334 r14336 276 276 tr_logAddNamedDbg ("DHT", "Initializing DHT"); 277 277 278 if ( getenv ("TR_DHT_VERBOSE") != NULL)278 if (tr_env_key_exists ("TR_DHT_VERBOSE")) 279 279 dht_debug = stderr; 280 280 -
trunk/libtransmission/utils-test.c
r14299 r14336 11 11 #include <math.h> /* sqrt () */ 12 12 #include <string.h> /* strlen () */ 13 #include <stdlib.h> /* setenv (), unsetenv () */ 14 15 #ifdef _WIN32 16 #include <windows.h> 17 #define setenv(key, value, unused) SetEnvironmentVariableA (key, value) 18 #define unsetenv(key) SetEnvironmentVariableA (key, NULL) 19 #endif 13 20 14 21 #include "transmission.h" … … 474 481 s = test_strdup_printf_valist ("\n-%s-%s-%s-\n", "\r", "\t", "\b"); 475 482 check_streq ("\n-\r-\t-\b-\n", s); 483 tr_free (s); 484 485 return 0; 486 } 487 488 static int 489 test_env (void) 490 { 491 const char * test_key = "TR_TEST_ENV"; 492 int x; 493 char * s; 494 495 unsetenv (test_key); 496 497 check (!tr_env_key_exists (test_key)); 498 x = tr_env_get_int (test_key, 123); 499 check_int_eq (123, x); 500 s = tr_env_get_string (test_key, NULL); 501 check (s == NULL); 502 s = tr_env_get_string (test_key, "a"); 503 check_streq ("a", s); 504 tr_free (s); 505 506 setenv (test_key, "", 1); 507 508 check (tr_env_key_exists (test_key)); 509 x = tr_env_get_int (test_key, 456); 510 check_int_eq (456, x); 511 s = tr_env_get_string (test_key, NULL); 512 check_streq ("", s); 513 tr_free (s); 514 s = tr_env_get_string (test_key, "b"); 515 check_streq ("", s); 516 tr_free (s); 517 518 setenv (test_key, "135", 1); 519 520 check (tr_env_key_exists (test_key)); 521 x = tr_env_get_int (test_key, 789); 522 check_int_eq (135, x); 523 s = tr_env_get_string (test_key, NULL); 524 check_streq ("135", s); 525 tr_free (s); 526 s = tr_env_get_string (test_key, "c"); 527 check_streq ("135", s); 476 528 tr_free (s); 477 529 … … 496 548 test_truncd, 497 549 test_url, 498 test_utf8 }; 550 test_utf8, 551 test_env }; 499 552 500 553 return runTests (tests, NUM_TESTS (tests)); -
trunk/libtransmission/utils.c
r14331 r14336 25 25 #include <math.h> /* pow (), fabs (), floor () */ 26 26 #include <stdio.h> 27 #include <stdlib.h> 27 #include <stdlib.h> /* getenv () */ 28 28 #include <string.h> /* strerror (), memset (), memmem () */ 29 29 #include <time.h> /* nanosleep () */ … … 41 41 #include <w32api.h> 42 42 #define WINVER WindowsXP /* freeaddrinfo (), getaddrinfo (), getnameinfo () */ 43 #include <windows.h> /* Sleep (), GetSystemTimeAsFileTime () */43 #include <windows.h> /* Sleep (), GetSystemTimeAsFileTime (), GetEnvironmentVariable () */ 44 44 #endif 45 45 … … 1750 1750 } 1751 1751 1752 /*** 1753 **** ENVIRONMENT 1754 ***/ 1755 1756 bool 1757 tr_env_key_exists (const char * key) 1758 { 1759 assert (key != NULL); 1760 1761 #ifdef _WIN32 1762 1763 return GetEnvironmentVariableA (key, NULL, 0) != 0; 1764 1765 #else 1766 1767 return getenv (key) != NULL; 1768 1769 #endif 1770 } 1771 1772 int 1773 tr_env_get_int (const char * key, 1774 int default_value) 1775 { 1776 #ifdef _WIN32 1777 1778 char value[16]; 1779 1780 assert (key != NULL); 1781 1782 if (GetEnvironmentVariableA (key, value, ARRAYSIZE (value)) > 1) 1783 return atoi (value); 1784 1785 #else 1786 1787 const char * value; 1788 1789 assert (key != NULL); 1790 1791 value = getenv (key); 1792 1793 if (value != NULL && *value != '\0') 1794 return atoi (value); 1795 1796 #endif 1797 1798 return default_value; 1799 } 1800 1801 char * tr_env_get_string (const char * key, 1802 const char * default_value) 1803 { 1804 #ifdef _WIN32 1805 1806 wchar_t * wide_key; 1807 char * value = NULL; 1808 1809 wide_key = tr_win32_utf8_to_native (key, -1); 1810 if (wide_key != NULL) 1811 { 1812 const DWORD size = GetEnvironmentVariableW (wide_key, NULL, 0); 1813 if (size != 0) 1814 { 1815 wchar_t * const wide_value = tr_new (wchar_t, size); 1816 if (GetEnvironmentVariableW (wide_key, wide_value, size) == size - 1) 1817 value = tr_win32_native_to_utf8 (wide_value, size); 1818 1819 tr_free (wide_value); 1820 } 1821 1822 tr_free (wide_key); 1823 } 1824 1825 if (value == NULL && default_value != NULL) 1826 value = tr_strdup (default_value); 1827 1828 return value; 1829 1830 #else 1831 1832 char * value; 1833 1834 assert (key != NULL); 1835 1836 value = getenv (key); 1837 if (value == NULL) 1838 value = (char *) default_value; 1839 1840 if (value != NULL) 1841 value = tr_strdup (value); 1842 1843 return value; 1844 1845 #endif 1846 } -
trunk/libtransmission/utils.h
r14331 r14336 487 487 ***/ 488 488 489 /** @brief Check if environment variable exists. */ 490 bool tr_env_key_exists (const char * key); 491 492 /** @brief Get environment variable value as int. */ 493 int tr_env_get_int (const char * key, 494 int default_value); 495 496 /** @brief Get environment variable value as string (should be freed afterwards). */ 497 char * tr_env_get_string (const char * key, 498 const char * default_value); 499 500 /*** 501 **** 502 ***/ 503 489 504 #ifdef __cplusplus 490 505 } -
trunk/libtransmission/web.c
r14320 r14336 10 10 #include <assert.h> 11 11 #include <string.h> /* strlen (), strstr () */ 12 #include <stdlib.h> /* getenv () */13 12 14 13 #ifdef _WIN32 … … 102 101 bool curl_verbose; 103 102 bool curl_ssl_verify; 104 c onst char * curl_ca_bundle;103 char * curl_ca_bundle; 105 104 int close_mode; 106 105 struct tr_web_task * tasks; … … 388 387 web->taskLock = tr_lockNew (); 389 388 web->tasks = NULL; 390 web->curl_verbose = getenv ("TR_CURL_VERBOSE") != NULL;391 web->curl_ssl_verify = getenv ("TR_CURL_SSL_VERIFY") != NULL;392 web->curl_ca_bundle = getenv ("CURL_CA_BUNDLE");389 web->curl_verbose = tr_env_key_exists ("TR_CURL_VERBOSE"); 390 web->curl_ssl_verify = tr_env_key_exists ("TR_CURL_SSL_VERIFY"); 391 web->curl_ca_bundle = tr_env_get_string ("CURL_CA_BUNDLE", NULL); 393 392 if (web->curl_ssl_verify) 394 393 { … … 523 522 curl_multi_cleanup (multi); 524 523 tr_lockFree (web->taskLock); 524 tr_free (web->curl_ca_bundle); 525 525 tr_free (web->cookie_filename); 526 526 tr_free (web); -
trunk/utils/show.c
r14294 r14336 10 10 #include <stdio.h> /* fprintf () */ 11 11 #include <string.h> /* strcmp (), strchr (), memcmp () */ 12 #include <stdlib.h> /* getenv (),qsort () */12 #include <stdlib.h> /* qsort () */ 13 13 #include <time.h> 14 14 … … 189 189 curl_easy_setopt (curl, CURLOPT_WRITEDATA, writebuf); 190 190 curl_easy_setopt (curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 191 curl_easy_setopt (curl, CURLOPT_VERBOSE, getenv ("TR_CURL_VERBOSE") != NULL);191 curl_easy_setopt (curl, CURLOPT_VERBOSE, tr_env_key_exists ("TR_CURL_VERBOSE")); 192 192 curl_easy_setopt (curl, CURLOPT_ENCODING, ""); 193 193 return curl;
Note: See TracChangeset
for help on using the changeset viewer.