compat: implement basename(3) for Windows
This helps porting in_tail to Windows.
@@ -51,6 +51,21 @@ static inline time_t timegm(struct tm *tm)
return _mkgmtime(tm);
}
+static inline char* basename(const char *path)
+{
+ char drive[_MAX_DRIVE];
+ char dir[_MAX_DIR];
+ char fname[_MAX_FNAME];
+ char ext[_MAX_EXT];
+ static char buf[_MAX_PATH];
+
+ _splitpath_s(path, drive, _MAX_DRIVE, dir, _MAX_DIR,
+ fname, _MAX_FNAME, ext, _MAX_EXT);
+
+ _makepath_s(buf, _MAX_PATH, "", "", fname, ext);
+ return buf;
+}
+
/* mk_utils.c exposes localtime_r */
extern struct tm *localtime_r(const time_t *timep, struct tm * result);
