+/** Split the path string to the directory and file name (including extension) components.
+ The directory component doesn't contain trailing directory separator.
+ Returns true if the path contains the directory separator. */
+int
+dbuf_splitPath(const char *path, struct dbuf_s *dir, struct dbuf_s *file)
+{
+ const char *p;
+ int ret;
+ const char *end = &path[strlen(path)];
+
+ for (p = end - 1; p >= path && !IS_DIR_SEPARATOR(*p); --p)
+ ;
+
+ ret = p >= path;
+
+ if (NULL != dir)
+ {
+ int len = p - path;
+
+ if (0 < len)
+ dbuf_append(dir, path, len);
+ }
+
+ if (NULL != file)
+ {
+ int len;
+
+ ++p;
+ len = end - p;
+
+ if (0 < len)
+ dbuf_append(file, p, len);
+ }
+
+ return ret;
+}
+
+/** Split the path string to the file name (including directory) and file extension components.
+ File extension component contains the extension separator.
+ Returns true if the path contains the extension separator. */
+int
+dbuf_splitFile(const char *path, struct dbuf_s *file, struct dbuf_s *ext)
+{
+ const char *p;
+ const char *end = &path[strlen(path)];
+
+ for (p = end - 1; p >= path && !IS_DIR_SEPARATOR(*p) && '.' != *p; --p)
+ ;
+
+ if (p < path || '.' != *p)
+ {
+ dbuf_append_str(file, path);
+
+ return 0;
+ }
+ else
+ {
+ if (NULL != file)
+ {
+ int len = p - path;
+
+ if (0 < len)
+ dbuf_append(file, path, len);
+ }
+
+ if (NULL != ext)
+ {
+ int len = end - p;
+
+ if (0 < len)
+ dbuf_append(ext, p, len);
+ }
+
+ return 1;
+ }
+}
+
+/** Combine directory and the file name to a path string using the DIR_SEPARATOR_CHAR.
+ */
+void
+dbuf_makePath(struct dbuf_s *path,const char *dir, const char *file)
+{
+ if (dir != NULL)
+ dbuf_append_str(path, dir);
+
+ dbuf_append_char(path, DIR_SEPARATOR_CHAR);
+
+ if (file != NULL)
+ dbuf_append_str(path, file);
+}
+