mirror of
https://github.com/RubyMetric/chsrc
synced 2025-09-10 20:57:05 +08:00
fix parent
This commit is contained in:
parent
0a91a9bdd5
commit
07685390b0
37
lib/xy.h
37
lib/xy.h
@ -927,32 +927,31 @@ xy_normalize_path (const char *path)
|
|||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @note 总是返回不含末尾斜杠的父目录路径
|
||||||
|
*/
|
||||||
static char *
|
static char *
|
||||||
xy_parent_dir (const char *path)
|
xy_parent_dir (const char *path)
|
||||||
{
|
{
|
||||||
char *dir = xy_normalize_path (path);
|
char *dir = xy_normalize_path (path);
|
||||||
|
dir = xy_str_gsub (dir, "\\", "/");
|
||||||
|
if (xy_str_end_with (dir, "/"))
|
||||||
|
dir = xy_str_delete_suffix (dir, "/");
|
||||||
|
|
||||||
char *last = NULL;
|
char *last = NULL;
|
||||||
|
|
||||||
|
last = strrchr (dir, '/');
|
||||||
|
if (!last)
|
||||||
|
{
|
||||||
|
/* current dir */
|
||||||
|
return ".";
|
||||||
|
}
|
||||||
|
*last = '\0';
|
||||||
|
|
||||||
if (xy_on_windows)
|
if (xy_on_windows)
|
||||||
{
|
return xy_str_gsub (dir, "/", "\\");
|
||||||
last = strrchr (dir, '\\');
|
|
||||||
if (!last)
|
|
||||||
{
|
|
||||||
/* current dir */
|
|
||||||
return ".";
|
|
||||||
}
|
|
||||||
*last = '\0';
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return dir;
|
||||||
last = strrchr (dir, '/');
|
|
||||||
if (!last)
|
|
||||||
{
|
|
||||||
/* current dir */
|
|
||||||
return ".";
|
|
||||||
}
|
|
||||||
*last = '\0';
|
|
||||||
}
|
|
||||||
return dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user