mirror of
https://github.com/RubyMetric/chsrc
synced 2025-09-09 02:26:43 +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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @note 总是返回不含末尾斜杠的父目录路径
|
||||
*/
|
||||
static char *
|
||||
xy_parent_dir (const char *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;
|
||||
|
||||
last = strrchr (dir, '/');
|
||||
if (!last)
|
||||
{
|
||||
/* current dir */
|
||||
return ".";
|
||||
}
|
||||
*last = '\0';
|
||||
|
||||
if (xy_on_windows)
|
||||
{
|
||||
last = strrchr (dir, '\\');
|
||||
if (!last)
|
||||
{
|
||||
/* current dir */
|
||||
return ".";
|
||||
}
|
||||
*last = '\0';
|
||||
}
|
||||
return xy_str_gsub (dir, "/", "\\");
|
||||
else
|
||||
{
|
||||
last = strrchr (dir, '/');
|
||||
if (!last)
|
||||
{
|
||||
/* current dir */
|
||||
return ".";
|
||||
}
|
||||
*last = '\0';
|
||||
}
|
||||
return dir;
|
||||
return dir;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user