diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-08-21 06:39:18 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-08-21 06:39:18 +0000 |
commit | 9d601c6799ca74f398d5df8dc0144f74084f546b (patch) | |
tree | a006906797b6fd55a738b1c3e653f46a2a15ce31 /epan/filesystem.c | |
parent | aacb4d90f0ef62557d0fa370c5bfcafe89c466a0 (diff) | |
download | wireshark-9d601c6799ca74f398d5df8dc0144f74084f546b.tar.gz wireshark-9d601c6799ca74f398d5df8dc0144f74084f546b.tar.bz2 wireshark-9d601c6799ca74f398d5df8dc0144f74084f546b.zip |
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
Diffstat (limited to 'epan/filesystem.c')
-rw-r--r-- | epan/filesystem.c | 140 |
1 files changed, 137 insertions, 3 deletions
diff --git a/epan/filesystem.c b/epan/filesystem.c index 0dfa42489e..c026c2d681 100644 --- a/epan/filesystem.c +++ b/epan/filesystem.c @@ -1,12 +1,11 @@ /* filesystem.c * Filesystem utility routines * - * $Id: filesystem.c,v 1.4 2001/04/02 09:53:44 guy Exp $ + * $Id: filesystem.c,v 1.5 2001/08/21 06:39:16 guy Exp $ * * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@zing.org> + * By Gerald Combs <gerald@ethereal.com> * Copyright 1998 Gerald Combs - * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,12 +28,22 @@ #include <stdlib.h> #include <string.h> +#include <errno.h> + #include <glib.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif + #ifndef WIN32 #include <pwd.h> #endif @@ -132,6 +141,131 @@ get_dirname(char *path) return path; } +/* + * Given a pathname, return: + * + * the errno, if an attempt to "stat()" the file fails; + * + * EISDIR, if the attempt succeeded and the file turned out + * to be a directory; + * + * 0, if the attempt succeeded and the file turned out not + * to be a directory. + */ + +/* + * Visual C++ on Win32 systems doesn't define these. (Old UNIX systems don't + * define them either.) + * + * Visual C++ on Win32 systems doesn't define S_IFIFO, it defines _S_IFIFO. + */ +#ifndef S_ISREG +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#endif +#ifndef S_IFIFO +#define S_IFIFO _S_IFIFO +#endif +#ifndef S_ISFIFO +#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) +#endif +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif + +int +test_for_directory(const char *path) +{ + struct stat statb; + + if (stat(path, &statb) < 0) + return errno; + + if (S_ISDIR(statb.st_mode)) + return EISDIR; + else + return 0; +} + +/* + * Get the directory in which global configuration and data files are + * stored. + */ +const char * +get_datafile_dir(void) +{ +#ifdef WIN32 + char prog_pathname[_MAX_PATH+2]; + char *dir_end; + size_t datafile_dir_len; + static char *datafile_dir; + + /* + * Have we already gotten the pathname? + * If so, just return it. + */ + if (datafile_dir != NULL) + return datafile_dir; + + /* + * No, we haven't. + * Start out by assuming it's the default installation directory. + */ + datafile_dir = "C:\\Program Files\\Ethereal\\"; + + /* + * Now we attempt to get the full pathname of the currently running + * program, under the assumption that we're running an installed + * version of the program. If we fail, we don't change "datafile_dir", + * and thus end up using DATAFILE_DIR. + * + * XXX - does NSIS put the installation directory into + * "\HKEY_LOCAL_MACHINE\SOFTWARE\Ethereal\InstallDir"? + * If so, perhaps we should read that from the registry, + * instead. + */ + if (GetModuleFileName(NULL, prog_pathname, sizeof prog_pathname) != 0) { + /* + * If the program is an installed version, the full pathname + * includes the pathname of the directory in which it was + * installed; get that directory's pathname, and construct + * from it the pathname of the directory in which the + * plugins were installed. + * + * First, find the last "\\" in the directory, as that + * marks the end of the directory pathname. + * + * XXX - Can the pathname be something such as + * "C:ethereal.exe"? Or is it always a full pathname + * beginning with "\\" after the drive letter? + */ + dir_end = strrchr(prog_pathname, '\\'); + if (dir_end != NULL) { + /* + * Found it - now figure out how long the datafile + * directory pathname will be. + */ + datafile_dir_len = (dir_end - prog_pathname); + + /* + * Allocate a buffer for the plugin directory + * pathname, and construct it. + */ + datafile_dir = g_malloc(datafile_dir_len + 1); + strncpy(datafile_dir, prog_pathname, datafile_dir_len); + datafile_dir[datafile_dir_len] = '\0'; + } + } +#else + /* + * Just use DATAFILE_DIR, as that's what the configure script + * set it to be. + */ + return DATAFILE_DIR; +#endif +} + +/* Returns the user's home directory, via the HOME environment + * variable, or a default directory if HOME is not set */ const char* get_home_dir(void) { |