X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Fos.c;h=47af038f78216beaf73e6dcc1935dd28695dec21;hb=493e0e6648552c0dce6c5225c8438d2829f1ac11;hp=f9ddbe1a2722940ad39dabc7353e4008b212cbc7;hpb=92f9ced0f1ac270b78c3733ed259f4604d01af16;p=exim.git diff --git a/src/src/os.c b/src/src/os.c index f9ddbe1a2..47af038f7 100644 --- a/src/src/os.c +++ b/src/src/os.c @@ -1,10 +1,8 @@ -/* $Cambridge: exim/src/src/os.c,v 1.7 2009/10/20 12:39:47 nm4 Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2007 */ +/* Copyright (c) University of Cambridge 1995 - 2016 */ /* See the file NOTICE for conditions of use and distribution. */ #ifdef STAND_ALONE @@ -167,8 +165,8 @@ that have nothing. It provides a basic translation for the common standard signal numbers. I've been extra cautious with the ifdef's here. Probably more than is necessary... */ -char * -os_strsignal(int n) +const char * +os_strsignal(const int n) { switch (n) { @@ -284,8 +282,8 @@ switch (n) exit codes into text, but this function is implemented this way so that if any OS does have such a thing, it could be used instead of this build-in one. */ -char * -os_strexit(int n) +const char * +os_strexit(const int n) { switch (n) { @@ -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 unsigned char * name) +{ +return unsetenv((char *)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) +unsigned char * +os_getcwd(unsigned char * buffer, size_t size) +{ +return (unsigned char *) getcwd((char *)buffer, size); +} +#else +#ifndef PATH_MAX +# define PATH_MAX 4096 +#endif +unsigned char * +os_getcwd(unsigned char * buffer, size_t size) +{ +char * b = (char *)buffer; + +if (!size) size = PATH_MAX; +if (!b && !(b = malloc(size))) return NULL; +if (!(b = getcwd(b, size))) return NULL; +return realloc(b, strlen(b) + 1); +} +#endif + +/* ----------------------------------------------------------------------- */ + + + /************************************************* **************************************************