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
This commit is contained in:
Guy Harris 2001-08-21 06:39:18 +00:00
parent aacb4d90f0
commit 9d601c6799
17 changed files with 248 additions and 203 deletions

View File

@ -1,4 +1,4 @@
/* $Id: config.h.win32,v 1.31 2001/08/18 23:21:30 guy Exp $ */
/* $Id: config.h.win32,v 1.32 2001/08/21 06:39:14 guy Exp $ */
/* config.h.win32 Generated manually. :-) */
/* config.h. Generated automatically by configure. */
/* config.h.in. Generated automatically from configure.in by autoheader. */
@ -35,8 +35,6 @@
/* #undef HAVE_SA_LEN */
#define DATAFILE_DIR "/usr/local/etc"
/* #undef NEED_SNPRINTF_H */
/* #undef NEED_STRERROR_H */

View File

@ -1,4 +1,4 @@
/* $Id: config.h.win32,v 1.7 2001/05/01 02:44:52 guy Exp $ */
/* $Id: config.h.win32,v 1.8 2001/08/21 06:39:16 guy Exp $ */
/* config.h.win32 Generated manually. :-) */
/* config.h. Generated automatically by configure. */
/* config.h.in. Generated automatically from configure.in by autoheader. */
@ -28,8 +28,6 @@
#define HAVE_PLUGINS 1
#define DATAFILE_DIR "/usr/local/etc"
#define NEED_INET_ATON_H 1
#define NEED_INET_V6DEFS_H 1

View File

@ -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)
{

View File

@ -1,12 +1,11 @@
/* filesystem.h
* Filesystem utility definitions
*
* $Id: filesystem.h,v 1.3 2001/04/02 09:53:44 guy Exp $
* $Id: filesystem.h,v 1.4 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
@ -45,6 +44,25 @@ char *get_basename(char *);
*/
char *get_dirname(char *);
/*
* 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.
*/
int test_for_directory(const char *);
/*
* Get the directory in which global configuration and data files are
* stored.
*/
const char *get_datafile_dir(void);
/* 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);

View File

@ -1,7 +1,7 @@
/* plugins.c
* plugin routines
*
* $Id: plugins.c,v 1.27 2001/08/19 00:42:36 guy Exp $
* $Id: plugins.c,v 1.28 2001/08/21 06:39:16 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -70,10 +70,7 @@ static plugin_address_table_t patable;
/* linked list of all plugins */
plugin *plugin_list;
#ifdef WIN32
#include <stdio.h>
static gchar std_plug_dir[] = "C:\\Program Files\\Ethereal\\plugins\\" VERSION;
#else
#ifndef WIN32
static gchar std_plug_dir[] = "/usr/lib/ethereal/plugins/" VERSION;
static gchar local_plug_dir[] = "/usr/local/lib/ethereal/plugins/" VERSION;
#endif
@ -277,13 +274,11 @@ void
init_plugins(const char *plugin_dir)
{
#ifdef WIN32
char prog_pathname[_MAX_PATH+2];
char *dir_end;
size_t install_plugin_dir_len;
char *install_plugin_dir;
const char *datafile_dir;
#else
struct stat std_dir_stat, local_dir_stat, plugin_dir_stat;
struct stat std_dir_stat, local_dir_stat;
#endif
struct stat plugin_dir_stat;
if (plugin_list == NULL) /* ensure init_plugins is only run once */
{
@ -423,77 +418,46 @@ init_plugins(const char *plugin_dir)
#ifdef WIN32
/*
* Scan the default installation directory.
* On Windows, the data file directory is the installation
* directory; the plugins are stored under it.
*
* This may not, in fact, be where Ethereal is installed;
* we check that directory later, but we check this directory
* as well, so that if you're running the program from a
* source directory in which you've built it, you still get
* to see the plugins installed on your system.
* Assume we're running the installed version of Ethereal;
* on Windows, the data file directory is the directory
* in which the Ethereal binary resides.
*/
plugins_scan_dir(std_plug_dir);
datafile_dir = get_datafile_dir();
plugin_dir = g_malloc(strlen(datafile_dir) + strlen("plugins") +
strlen(VERSION) + 3);
sprintf(plugin_dir, "%s\\plugins\\%s", datafile_dir, VERSION);
/*
* Now attempt to get the full pathname of the currently running
* program, and assume that might contain the pathname of the
* directory in which Ethereal was installed.
* Make sure that pathname refers to a directory.
*/
if (GetModuleFileName(NULL, prog_pathname, sizeof prog_pathname) != 0) {
if (test_for_directory(plugin_dir) != 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.
* Either it doesn't refer to a directory or it
* refers to something that doesn't exist.
*
* First, find the last "\\" in the directory, as that
* marks the end of the directory pathname.
* Assume that means we're running, for example,
* a version of Ethereal we've built in a source
* directory, and fall back on the default
* installation directory, so you can put the plugins
* somewhere so they can be used with this version
* of Ethereal.
*
* XXX - should we, instead, have the Windows build
* procedure create a subdirectory of the "plugins"
* source directory, and copy the plugin DLLs there,
* so that you use the plugins from the build tree?
*/
dir_end = strrchr(prog_pathname, '\\');
if (dir_end != NULL) {
/*
* Include the "\\" in the directory's pathname,
* as we'll be appending to that pathname.
*/
dir_end++;
/*
* Found it - now figure out how long the plugin
* directory pathname will be.
* It's the length of the directory pathname
* (dir_end - prog_pathname), plus the length of
* the plugin directory's relative pathname.
*/
install_plugin_dir_len = (dir_end - prog_pathname) +
strlen("plugins\\"VERSION);
/*
* Allocate a buffer for the plugin directory
* pathname, and construct it.
*/
install_plugin_dir =
g_malloc(install_plugin_dir_len + 1);
strncpy(install_plugin_dir, prog_pathname,
dir_end - prog_pathname);
strcpy(install_plugin_dir + (dir_end - prog_pathname),
"plugins\\"VERSION);
/*
* Is it the same as the standard plugin directory?
* (Do a case-insensitive string comparison; this
* *is* Windows, after all.)
*
* XXX - is there another way to determine whether
* two pathnames refer to the same file?
*/
if (g_strcasecmp(std_plug_dir, install_plugin_dir) != 0) {
/*
* It's a different directory - scan it.
*/
plugins_scan_dir(install_plugin_dir);
}
}
plugin_dir =
"C:\\Program Files\\Ethereal\\plugins\\" VERSION;
}
/*
* Scan that directory.
*/
plugins_scan_dir(plugin_dir);
#else
/*
* XXX - why not just scan "plugin_dir"? That's where we

View File

@ -1,7 +1,7 @@
/* resolv.c
* Routines for network object lookup
*
* $Id: resolv.c,v 1.11 2001/06/07 22:07:02 guy Exp $
* $Id: resolv.c,v 1.12 2001/08/21 06:39:16 guy Exp $
*
* Laurent Deniel <deniel@worldnet.fr>
*
@ -83,9 +83,14 @@
#include "prefs.h"
/*
* XXX - on Windows, do "/etc/ethers" and "/etc/ipxnets" exist, perhaps in
* some other directory, or should we instead look for them in the Ethereal
* installation directory, treating them as Ethereal-specific files?
*/
#define EPATH_ETHERS "/etc/ethers"
#define EPATH_IPXNETS "/etc/ipxnets"
#define EPATH_MANUF DATAFILE_DIR "/manuf"
#define ENAME_MANUF "manuf"
#define EPATH_PERSONAL_ETHERS ".ethereal/ethers" /* with "$HOME/" prefix */
#define EPATH_PERSONAL_IPXNETS ".ethereal/ipxnets" /* with "$HOME/" prefix */
@ -173,7 +178,6 @@ gchar *g_ethers_path = EPATH_ETHERS;
gchar *g_pethers_path = NULL; /* "$HOME"/EPATH_PERSONAL_ETHERS */
gchar *g_ipxnets_path = EPATH_IPXNETS;
gchar *g_pipxnets_path = NULL; /* "$HOME"/EPATH_PERSONAL_IPXNETS */
gchar *g_manuf_path = EPATH_MANUF; /* may only be changed before the */
/* first resolving call */
/*
@ -624,6 +628,7 @@ static hashmanuf_t *manuf_name_lookup(const guint8 *addr)
static void initialize_ethers(void)
{
ether_t *eth;
char *manuf_path;
/* Set g_pethers_path here, but don't actually do anything
* with it. It's used in get_ethbyname() and get_ethbyaddr()
@ -637,7 +642,14 @@ static void initialize_ethers(void)
/* manuf hash table initialization */
set_ethent(g_manuf_path);
/* Compute the pathname of the manuf file */
manuf_path = (gchar *) g_malloc(strlen(get_datafile_dir()) +
strlen(ENAME_MANUF) + 2);
sprintf(manuf_path, "%s%c%s", get_datafile_dir(), G_DIR_SEPARATOR,
ENAME_MANUF);
/* Read it and initialize the hash table */
set_ethent(manuf_path);
while ((eth = get_ethent(0))) {
add_manuf_name(eth->addr, eth->name);
@ -645,6 +657,8 @@ static void initialize_ethers(void)
end_ethent();
g_free(manuf_path);
} /* initialize_ethers */
static hashether_t *add_eth_name(const guint8 *addr, const guchar *name)

View File

@ -1,7 +1,7 @@
/* resolv.h
* Definitions for network object lookup
*
* $Id: resolv.h,v 1.6 2001/04/15 03:37:15 guy Exp $
* $Id: resolv.h,v 1.7 2001/08/21 06:39:17 guy Exp $
*
* Laurent Deniel <deniel@worldnet.fr>
*
@ -36,7 +36,6 @@
extern gchar *g_ethers_path;
extern gchar *g_ipxnets_path;
extern gchar *g_manuf_path;
extern gchar *g_pethers_path;
extern gchar *g_pipxnets_path;

3
file.c
View File

@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
* $Id: file.c,v 1.243 2001/07/17 05:32:42 hagbard Exp $
* $Id: file.c,v 1.244 2001/08/21 06:39:14 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -69,6 +69,7 @@
#endif
#include <epan.h>
#include <filesystem.h>
#include "gtk/main.h"
#include "color.h"

View File

@ -7,10 +7,10 @@
* Copyright 2000, Jeffrey C. Foster<jfoste@woodward.com> and
* Guy Harris <guy@alum.mit.edu>
*
* $Id: dfilter_expr_dlg.c,v 1.22 2001/04/20 21:57:55 guy Exp $
* $Id: dfilter_expr_dlg.c,v 1.23 2001/08/21 06:39:18 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* By Gerald Combs <gerald@ethereal.com>
* Copyright 2000 Gerald Combs
*
* This program is free software; you can redistribute it and/or
@ -26,7 +26,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
/* Todo -
@ -62,7 +61,6 @@
#include "globals.h"
#include "gtkglobals.h"
#include "main.h"
#include "util.h"
#include "ui_util.h"
#include "simple_dialog.h"
#include "dlg_utils.h"

View File

@ -1,7 +1,7 @@
/* file_dlg.c
* Dialog boxes for handling files
*
* $Id: file_dlg.c,v 1.40 2001/06/05 07:38:37 guy Exp $
* $Id: file_dlg.c,v 1.41 2001/08/21 06:39:18 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -36,6 +36,8 @@
#include <string.h>
#include <epan/filesystem.h>
#include "globals.h"
#include "gtkglobals.h"
#include "prefs.h"
@ -47,7 +49,6 @@
#include "menu.h"
#include "file_dlg.h"
#include "dlg_utils.h"
#include "util.h"
#include "main.h"
static void file_open_ok_cb(GtkWidget *w, GtkFileSelection *fs);

View File

@ -1,11 +1,11 @@
/* help_dlg.c
*
* $Id: help_dlg.c,v 1.17 2001/05/12 19:45:37 gerald Exp $
* $Id: help_dlg.c,v 1.18 2001/08/21 06:39:18 guy Exp $
*
* Laurent Deniel <deniel@worldnet.fr>
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* By Gerald Combs <gerald@ethereal.com>
* Copyright 2000 Gerald Combs
*
* This program is free software; you can redistribute it and/or
@ -21,7 +21,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
@ -46,7 +45,6 @@
#include "globals.h"
#include "gtkglobals.h"
#include "main.h"
#include "util.h"
#include "ui_util.h"
#include "proto.h"

View File

@ -3,10 +3,10 @@
*
* Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
*
* $Id: packet_win.c,v 1.21 2001/03/24 23:53:07 guy Exp $
* $Id: packet_win.c,v 1.22 2001/08/21 06:39:18 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
@ -28,7 +28,6 @@
* - improve the window Title and allow user to config it
* - Add print support ? ( could be a mess)
* - Add button to have main window jump to this packet ?
*
*/
@ -58,7 +57,6 @@
#include "column.h"
#include "print.h"
#include "resolv.h"
#include "util.h"
#include "packet_win.h"
#include "simple_dialog.h"
#include "proto_draw.h"

View File

@ -1,12 +1,11 @@
/* prefs_dlg.c
* Routines for handling preferences
*
* $Id: prefs_dlg.c,v 1.24 2001/01/11 04:40:26 gram Exp $
* $Id: prefs_dlg.c,v 1.25 2001/08/21 06:39:18 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
@ -56,7 +55,6 @@
#include "print_prefs.h"
#include "stream_prefs.h"
#include "gui_prefs.h"
#include "util.h"
#include "ui_util.h"
#include "dlg_utils.h"
#include "simple_dialog.h"

View File

@ -1,12 +1,11 @@
/* stream_prefs.c
* Dialog boxes for preferences for the stream window
*
* $Id: stream_prefs.c,v 1.8 2001/03/01 20:49:50 gram Exp $
* $Id: stream_prefs.c,v 1.9 2001/08/21 06:39:18 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
@ -37,7 +36,6 @@
#include "keys.h"
#include "print.h"
#include "prefs_dlg.h"
#include "util.h"
static void update_text_color(GtkWidget *, gpointer);
static void update_current_color(GtkWidget *, gpointer);

21
prefs.c
View File

@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
* $Id: prefs.c,v 1.60 2001/07/23 18:14:36 guy Exp $
* $Id: prefs.c,v 1.61 2001/08/21 06:39:14 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -66,11 +66,11 @@ static gchar *put_string_list(GList *);
static void clear_string_list(GList *);
static void free_col_info(e_prefs *);
#define PF_NAME "preferences"
#define GPF_PATH DATAFILE_DIR "/ethereal.conf"
#define GPF_NAME "ethereal.conf"
#define PF_NAME "preferences"
static gboolean init_prefs = TRUE;
static gchar *gpf_path = NULL;
static gchar *pf_path = NULL;
/*
@ -724,11 +724,18 @@ read_prefs(int *gpf_errno_return, char **gpf_path_return,
prefs.name_resolve = PREFS_RESOLV_ALL;
}
/* Construct the pathname of the global preferences file. */
if (! gpf_path) {
gpf_path = (gchar *) g_malloc(strlen(get_datafile_dir()) +
strlen(GPF_NAME) + 2);
sprintf(gpf_path, "%s%c%s", get_datafile_dir(), G_DIR_SEPARATOR, GPF_NAME);
}
/* Read the global preferences file, if it exists. */
*gpf_path_return = NULL;
if ((pf = fopen(GPF_PATH, "r")) != NULL) {
if ((pf = fopen(gpf_path, "r")) != NULL) {
/* We succeeded in opening it; read it. */
read_prefs_file(GPF_PATH, pf);
read_prefs_file(gpf_path, pf);
fclose(pf);
} else {
/* We failed to open it. If we failed for some reason other than
@ -736,7 +743,7 @@ read_prefs(int *gpf_errno_return, char **gpf_path_return,
caller can report the error. */
if (errno != ENOENT) {
*gpf_errno_return = errno;
*gpf_path_return = GPF_PATH;
*gpf_path_return = gpf_path;
}
}

50
util.c
View File

@ -1,12 +1,11 @@
/* util.c
* Utility routines
*
* $Id: util.c,v 1.51 2001/04/02 09:53:43 guy Exp $
* $Id: util.c,v 1.52 2001/08/21 06:39:15 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
@ -89,51 +88,6 @@ typedef int mode_t; /* for win32 */
#endif
/*
* 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;
}
/*
* Collect command-line arguments as a string consisting of the arguments,
* separated by spaces.

37
util.h
View File

@ -1,12 +1,11 @@
/* util.h
* Utility definitions
*
* $Id: util.h,v 1.23 2001/04/02 09:53:43 guy Exp $
* $Id: util.h,v 1.24 2001/08/21 06:39:15 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
@ -30,38 +29,6 @@
extern "C" {
#endif /* __cplusplus */
/*
* 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.
*/
int test_for_directory(const char *);
/*
* Given a pathname, return a pointer to the last pathname separator
* character in the pathname, or NULL if the pathname contains no
* separators.
*/
char *find_last_pathname_separator(char *);
/*
* Given a pathname, return the last component.
*/
char *get_basename(char *);
/*
* Given a pathname, return a string containing everything but the
* last component. NOTE: this overwrites the pathname handed into
* it....
*/
char *get_dirname(char *);
int create_tempfile(char *, int, const char *);
/*