"get_home_dir()", in "epan/filesystem.c", uses

"find_last_pathname_separator()" on Win32; move the other pathname
manipulation routines from "util.c" into "epan/filesystem.c".

Remove from "util.h" the declarations of routines not defined in
"util.c", and put them into "epan/filesystem.h" if they're not already
there.

Adjust #includes to make the above work.

svn path=/trunk/; revision=3241
This commit is contained in:
Guy Harris 2001-04-02 09:53:46 +00:00
parent d203637ade
commit 65dc469326
8 changed files with 122 additions and 106 deletions

View File

@ -1,7 +1,7 @@
/* filesystem.c
* Filesystem utility routines
*
* $Id: filesystem.c,v 1.3 2001/03/31 22:53:09 hagbard Exp $
* $Id: filesystem.c,v 1.4 2001/04/02 09:53:44 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -41,6 +41,97 @@
#include "filesystem.h"
/*
* 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 *path)
{
char *separator;
#ifdef WIN32
char c;
/*
* We have to scan for '\' or '/'.
* Get to the end of the string.
*/
separator = path + strlen(path); /* points to ending '\0' */
while (separator > path) {
c = *--separator;
if (c == '\\' || c == '/')
return separator; /* found it */
}
/*
* OK, we didn't find any, so no directories - but there might
* be a drive letter....
*/
return strchr(path, ':');
#else
separator = strrchr(path, '/');
#endif
return separator;
}
/*
* Given a pathname, return the last component.
*/
char *
get_basename(char *path)
{
char *filename;
filename = find_last_pathname_separator(path);
if (filename == NULL) {
/*
* There're no directories, drive letters, etc. in the
* name; the pathname *is* the file name.
*/
filename = path;
} else {
/*
* Skip past the pathname or drive letter separator.
*/
filename++;
}
return filename;
}
/*
* Given a pathname, return a string containing everything but the
* last component. NOTE: this overwrites the pathname handed into
* it....
*/
char *
get_dirname(char *path)
{
char *separator;
separator = find_last_pathname_separator(path);
if (separator == NULL) {
/*
* There're no directories, drive letters, etc. in the
* name; there is no directory path to return.
*/
return NULL;
}
/*
* Get rid of the last pathname separator and the final file
* name following it.
*/
*separator = '\0';
/*
* "path" now contains the pathname of the directory containing
* the file/directory to which it referred.
*/
return path;
}
const char*
get_home_dir(void)
{

View File

@ -1,7 +1,7 @@
/* filesystem.h
* Filesystem utility definitions
*
* $Id: filesystem.h,v 1.2 2000/12/22 22:26:19 nneul Exp $
* $Id: filesystem.h,v 1.3 2001/04/02 09:53:44 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -26,6 +26,25 @@
#ifndef FILESYSTEM_H
#define FILESYSTEM_H
/*
* 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 *);
/* 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 @@
/* filters.c
* Code for reading and writing the filters file.
*
* $Id: filters.c,v 1.8 2001/03/15 09:50:39 guy Exp $
* $Id: filters.c,v 1.9 2001/04/02 09:53:42 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -47,9 +47,9 @@
#include <glib.h>
#include <epan.h>
#include <filesystem.h>
#include "filters.h"
#include "util.h"
/*
* Old filter file name.

View File

@ -1,7 +1,7 @@
/* colors.c
* Definitions for color structures and routines
*
* $Id: colors.c,v 1.7 2001/02/01 20:21:21 gram Exp $
* $Id: colors.c,v 1.8 2001/04/02 09:53:46 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -40,13 +40,13 @@
#endif
#include <epan.h>
#include <epan/filesystem.h>
#include "gtk/main.h"
#include "packet.h"
#include "colors.h"
#include "file.h"
#include "dfilter/dfilter.h"
#include "simple_dialog.h"
#include "util.h"
extern capture_file cf;

View File

@ -1,6 +1,6 @@
/* main.c
*
* $Id: main.c,v 1.186 2001/04/02 00:38:36 hagbard Exp $
* $Id: main.c,v 1.187 2001/04/02 09:53:46 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -107,6 +107,7 @@
#endif
#include <epan.h>
#include <epan/filesystem.h>
#include "main.h"
#include "timestamp.h"

View File

@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
* $Id: prefs.c,v 1.47 2001/01/05 22:45:26 guy Exp $
* $Id: prefs.c,v 1.48 2001/04/02 09:53:42 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -49,6 +49,7 @@
#endif
#include <epan.h>
#include <filesystem.h>
#include "globals.h"
#include "packet.h"
#include "file.h"
@ -56,7 +57,6 @@
#include "proto.h"
#include "column.h"
#include "print.h"
#include "util.h"
#include "prefs-int.h"

93
util.c
View File

@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
* $Id: util.c,v 1.50 2001/03/22 06:14:27 guy Exp $
* $Id: util.c,v 1.51 2001/04/02 09:53:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -134,97 +134,6 @@ test_for_directory(const char *path)
return 0;
}
/*
* 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 *path)
{
char *separator;
#ifdef WIN32
char c;
/*
* We have to scan for '\' or '/'.
* Get to the end of the string.
*/
separator = path + strlen(path); /* points to ending '\0' */
while (separator > path) {
c = *--separator;
if (c == '\\' || c == '/')
return separator; /* found it */
}
/*
* OK, we didn't find any, so no directories - but there might
* be a drive letter....
*/
return strchr(path, ':');
#else
separator = strrchr(path, '/');
#endif
return separator;
}
/*
* Given a pathname, return the last component.
*/
char *
get_basename(char *path)
{
char *filename;
filename = find_last_pathname_separator(path);
if (filename == NULL) {
/*
* There're no directories, drive letters, etc. in the
* name; the pathname *is* the file name.
*/
filename = path;
} else {
/*
* Skip past the pathname or drive letter separator.
*/
filename++;
}
return filename;
}
/*
* Given a pathname, return a string containing everything but the
* last component. NOTE: this overwrites the pathname handed into
* it....
*/
char *
get_dirname(char *path)
{
char *separator;
separator = find_last_pathname_separator(path);
if (separator == NULL) {
/*
* There're no directories, drive letters, etc. in the
* name; there is no directory path to return.
*/
return NULL;
}
/*
* Get rid of the last pathname separator and the final file
* name following it.
*/
*separator = '\0';
/*
* "path" now contains the pathname of the directory containing
* the file/directory to which it referred.
*/
return path;
}
/*
* Collect command-line arguments as a string consisting of the arguments,
* separated by spaces.

6
util.h
View File

@ -1,7 +1,7 @@
/* util.h
* Utility definitions
*
* $Id: util.h,v 1.22 2000/10/11 07:35:00 guy Exp $
* $Id: util.h,v 1.23 2001/04/02 09:53:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -64,10 +64,6 @@ char *get_dirname(char *);
int create_tempfile(char *, int, const char *);
/* 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);
/*
* Collect command-line arguments as a string consisting of the arguments,
* separated by spaces.