rename DIR_SEP to SYS_DIR_SEP (it being it sysdep.h, where most everything is thus prefixed)

another crack at #159; no longer use SYS_DIR_SEP. reason is that the
self-test uses windows AND unix paths, so both must always work on all
platforms.

This was SVN commit r4646.
This commit is contained in:
janwas 2006-11-18 17:48:49 +00:00
parent 3705caae7a
commit 9d34e32c34
4 changed files with 18 additions and 18 deletions

View File

@ -43,7 +43,7 @@ AT_STARTUP(\
static inline bool is_dir_sep(char c)
{
// note: ideally path strings would only contain '/' or even DIR_SEP.
// note: ideally path strings would only contain '/' or even SYS_DIR_SEP.
// however, windows-specific code (e.g. the sound driver detection)
// uses these routines with '\\' strings. converting them all to
// '/' and then back before passing to WinAPI would be annoying.
@ -241,14 +241,14 @@ LibError path_replace(char* dst, const char* src, const char* remove, const char
// characters up to the last dir separator, if any).
const char* path_name_only(const char* path)
{
const char* portable_slash = strrchr(path, '/');
const char* platform_slash = strrchr(path, DIR_SEP);
const char* slash1 = strrchr(path, '/');
const char* slash2 = strrchr(path, '\\');
// neither present, it's a filename only
if(!portable_slash && !platform_slash)
if(!slash1 && !slash2)
return path;
// return name, i.e. component after the last portable or platform slash
return MAX(portable_slash, platform_slash)+1;
return MAX(slash1, slash2)+1;
}
@ -258,7 +258,7 @@ const char* path_name_only(const char* path)
const char* path_last_component(const char* path)
{
// ('\0' is end of set string)
static const char separators[3] = { DIR_SEP, '/', '\0' };
static const char separators[3] = { '/', '\\', '\0' };
const char* pos = path;
const char* last_component = path;
@ -334,9 +334,9 @@ LibError path_foreach_component(const char* path_org, PathComponentCb cb, void*
// find end of cur_component
char* slash = (char*)strchr(cur_component, '/');
// .. try platform-specific separator
// .. try other separator
if(!slash)
slash = (char*)strchr(cur_component, DIR_SEP);
slash = (char*)strchr(cur_component, '\\');
// decide its type and 0-terminate
// .. filename (by definition)
@ -382,7 +382,7 @@ LibError path_foreach_component(const char* path_org, PathComponentCb cb, void*
// does not care if paths are relative/portable/absolute.
LibError path_package_set_dir(PathPackage* pp, const char* dir)
{
// -1 allows for trailing DIR_SEP that will be added if not
// -1 allows for trailing '/' that will be added if not
// already present.
if(strcpy_s(pp->path, ARRAY_SIZE(pp->path)-1, dir) != 0)
WARN_RETURN(ERR::PATH_LENGTH);

View File

@ -28,7 +28,7 @@
// must hold at least that much.
// - unless otherwise mentioned, all functions are intended to work with
// native and portable and VFS paths.
// when reading, both '/' and DIR_SEP are accepted; '/' is written.
// when reading, both '/' and SYS_DIR_SEP are accepted; '/' is written.
#ifndef PATH_UTIL_H__
#define PATH_UTIL_H__

View File

@ -58,14 +58,14 @@ enum Conversion
static LibError convert_path(char* dst, const char* src, Conversion conv = TO_NATIVE)
{
// DIR_SEP is assumed to be a single character!
// SYS_DIR_SEP is assumed to be a single character!
const char* s = src;
char* d = dst;
char from = DIR_SEP, to = '/';
char from = SYS_DIR_SEP, to = '/';
if(conv == TO_NATIVE)
from = '/', to = DIR_SEP;
from = '/', to = SYS_DIR_SEP;
size_t len = 0;
@ -190,10 +190,10 @@ LibError file_set_root_dir(const char* argv0, const char* rel_path)
if(!realpath(n_path, n_root_dir))
return LibError_from_errno();
// .. append DIR_SEP to simplify code that uses n_root_dir
n_root_dir_len = strlen(n_root_dir)+1; // +1 for trailing DIR_SEP
// .. append SYS_DIR_SEP to simplify code that uses n_root_dir
n_root_dir_len = strlen(n_root_dir)+1; // +1 for trailing SYS_DIR_SEP
debug_assert((n_root_dir_len+1) < sizeof(n_root_dir)); // Just checking
n_root_dir[n_root_dir_len-1] = DIR_SEP;
n_root_dir[n_root_dir_len-1] = SYS_DIR_SEP;
// You might think that n_root_dir is already 0-terminated, since it's
// static - but that might not be true after calling file_reset_root_dir!
n_root_dir[n_root_dir_len] = 0;

View File

@ -335,9 +335,9 @@ extern i64 i64_from_double(double);
extern size_t sys_max_sector_size();
#if OS_WIN
#define DIR_SEP '\\'
# define SYS_DIR_SEP '\\'
#else
#define DIR_SEP '/'
# define SYS_DIR_SEP '/'
#endif
// tell the compiler that the code at/following this macro invocation is