| 935 | #define MALLOC_CONF_NSOURCES 4 |
| 936 | |
| 937 | static const char * |
| 938 | obtain_malloc_conf(unsigned which_source, char buf[PATH_MAX + 1]) { |
| 939 | if (config_debug) { |
| 940 | static unsigned read_source = 0; |
| 941 | /* |
| 942 | * Each source should only be read once, to minimize # of |
| 943 | * syscalls on init. |
| 944 | */ |
| 945 | assert(read_source++ == which_source); |
| 946 | } |
| 947 | assert(which_source < MALLOC_CONF_NSOURCES); |
| 948 | |
| 949 | const char *ret; |
| 950 | switch (which_source) { |
| 951 | case 0: |
| 952 | ret = config_malloc_conf; |
| 953 | break; |
| 954 | case 1: |
| 955 | if (je_malloc_conf != NULL) { |
| 956 | /* Use options that were compiled into the program. */ |
| 957 | ret = je_malloc_conf; |
| 958 | } else { |
| 959 | /* No configuration specified. */ |
| 960 | ret = NULL; |
| 961 | } |
| 962 | break; |
| 963 | case 2: { |
| 964 | ssize_t linklen = 0; |
| 965 | #ifndef _WIN32 |
| 966 | int saved_errno = errno; |
| 967 | const char *linkname = |
| 968 | # ifdef JEMALLOC_PREFIX |
| 969 | "/etc/"JEMALLOC_PREFIX"malloc.conf" |
| 970 | # else |
| 971 | "/etc/malloc.conf" |
| 972 | # endif |
| 973 | ; |
| 974 | |
| 975 | /* |
| 976 | * Try to use the contents of the "/etc/malloc.conf" symbolic |
| 977 | * link's name. |
| 978 | */ |
| 979 | #ifndef JEMALLOC_READLINKAT |
| 980 | linklen = readlink(linkname, buf, PATH_MAX); |
| 981 | #else |
| 982 | linklen = readlinkat(AT_FDCWD, linkname, buf, PATH_MAX); |
| 983 | #endif |
| 984 | if (linklen == -1) { |
| 985 | /* No configuration specified. */ |
| 986 | linklen = 0; |
| 987 | /* Restore errno. */ |
| 988 | set_errno(saved_errno); |
| 989 | } |
| 990 | #endif |
| 991 | buf[linklen] = '\0'; |
| 992 | ret = buf; |
| 993 | break; |
| 994 | } case 3: { |
no test coverage detected