X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/1ba28e2b955b005ce4825fec792df17f75a8de1e..93a680e4c9c899d86ff3fde0933fb5367b34af50:/src/src/os.c?ds=sidebyside diff --git a/src/src/os.c b/src/src/os.c index 4fa9324d4..1cde1b8ec 100644 --- a/src/src/os.c +++ b/src/src/os.c @@ -1,10 +1,8 @@ -/* $Cambridge: exim/src/src/os.c,v 1.8 2009/11/16 19:50:37 nm4 Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2009 */ +/* Copyright (c) University of Cambridge 1995 - 2016 */ /* See the file NOTICE for conditions of use and distribution. */ #ifdef STAND_ALONE @@ -797,6 +795,98 @@ return yield; +/* ----------------------------------------------------------------------- */ + +/*********************************************************** +* DNS Resolver Base Finder * +***********************************************************/ + +/* We need to be able to set options for the system resolver(5), historically +made available as _res. At least one OS (NetBSD) now no longer provides this +directly, instead making you call a function per thread to get a handle. +Other OSs handle thread-safe resolver differently, in ways which fail if the +programmer creates their own structs. */ + +#if !defined(OS_GET_DNS_RESOLVER_RES) && !defined(COMPILE_UTILITY) + +#include + +/* confirmed that res_state is typedef'd as a struct* on BSD and Linux, will +find out how unportable it is on other OSes, but most resolver implementations +should be descended from ISC's bind. + +Linux and BSD do: + define _res (*__res_state()) +identically. We just can't rely on __foo functions. It's surprising that use +of _res has been as portable as it has, for so long. + +So, since _res works everywhere, and everything can decode the struct, I'm +going to gamble that res_state is a typedef everywhere and use that as the +return type. +*/ + +res_state +os_get_dns_resolver_res(void) +{ + return &_res; +} + +#endif /* OS_GET_DNS_RESOLVER_RES */ + +/* ----------------------------------------------------------------------- */ + +/*********************************************************** +* unsetenv() * +***********************************************************/ + +/* Most modern systems define int unsetenv(const char*), +* some don't. */ + +#if !defined(OS_UNSETENV) +int +os_unsetenv(const uschar * name) +{ +return unsetenv(CS name); +} +#endif + +/* ----------------------------------------------------------------------- */ + +/*********************************************************** +* getcwd() * +***********************************************************/ + +/* Glibc allows getcwd(NULL, 0) to do auto-allocation. Some systems +do auto-allocation, but need the size of the buffer, and others +may not even do this. If the OS supports getcwd(NULL, 0) we'll use +this, for all other systems we provide our own getcwd() */ + +#if !defined(OS_GETCWD) +uschar * +os_getcwd(uschar * buffer, size_t size) +{ +return getcwd(CS buffer, size); +} +#else +#ifndef PATH_MAX +# define PATH_MAX 4096 +#endif +uschar * +os_getcwd(uschar * buffer, size_t size) +{ +void *rc; + +if (!size) size = PATH_MAX; +if (!buffer && !(buffer = US malloc(size))) return NULL; +if (!(buffer = getcwd(CS buffer, size))) return NULL; +return realloc(CS buffer, strlen(buffer) + 1); +} +#endif + +/* ----------------------------------------------------------------------- */ + + + /************************************************* **************************************************