X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/1aadfaac094abee8bfa7e3d37fe352562d1eba3d..dcae3b01d76f9a040f2a6e3d2c861c25c2d60a73:/missing/getservent.c?ds=sidebyside diff --git a/missing/getservent.c b/missing/getservent.c index c2dc620d..39cee068 100644 --- a/missing/getservent.c +++ b/missing/getservent.c @@ -35,7 +35,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif #include @@ -49,26 +49,26 @@ int _serv_stayopen; const char *etc_path(const char *file); /* -* Return either "%SYSTEMROOT%\System32\drivers\etc\", -* $PREFIX/etc/ or simply "" if those failed. +* Check if exists in the current directory and, if so, return it. +* Else return either "%SYSTEMROOT%\System32\drivers\etc\" +* or $PREFIX/etc/. * "" is aka __PATH_SERVICES (aka "services" on Windows and -* "/etc/services" on other platforms that would need this) +* "/etc/services" on other platforms that would need this). */ const char *etc_path(const char *file) { const char *env = getenv(__PATH_SYSROOT); static char path[_MAX_PATH]; - if (!env) -/* -* #ifdef _DEBUG -* printf("Warning: Environment Variable \"%s\" invalid\nResorting to [CurrentDirectory]/%s\n", -* __PATH_SYSROOT, file); -* #endif -*/ + /* see if "" exists locally or whether __PATH_SYSROOT is valid */ + if (fopen(file, "r") || !env) return (file); - + else +#ifdef _WIN32 snprintf(path, sizeof(path), "%s%s%s", env, __PATH_ETC_INET, file); +#else + snprintf(path, sizeof(path), "%s%s", env, file); +#endif return (path); } @@ -96,7 +96,7 @@ struct servent * getservent(void) { char *p; - register char *cp, **q; + char *cp, **q; if (servf == NULL && (servf = fopen(etc_path(__PATH_SERVICES), "r")) == NULL) return (NULL);