]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Updates for getservent.c 649/head
authorAli Abdulkadir <[email protected]>
Wed, 15 Nov 2017 15:39:39 +0000 (18:39 +0300)
committerAli Abdulkadir <[email protected]>
Wed, 15 Nov 2017 15:39:39 +0000 (18:39 +0300)
- fixed none _WIN32 implementation

- on windows, see if a services file exists in the same directory as tcpdump and use that

missing/getservent.c

index c2dc620d6c80f90897fd055451ed6f7cca5db93a..48b7465ca2be243fd8e1845f9f719aa2177e9b2b 100644 (file)
@@ -49,26 +49,26 @@ int _serv_stayopen;
 const char *etc_path(const char *file);
 
 /*
-* Return either "%SYSTEMROOT%\System32\drivers\etc\<file>",
-* $PREFIX/etc/<file> or simply "<file>" if those failed.
+* Check if <file> exists in the current directory and, if so, return it.
+* Else return either "%SYSTEMROOT%\System32\drivers\etc\<file>"
+* or $PREFIX/etc/<file>.
 * "<file>" 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 "<file>" 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);
 }