Mercurial > mplayer.hg
diff path.c @ 32554:8fffd26d06ae
Add a mp_dirname function (unused at the moment)
| author | cboesch |
|---|---|
| date | Sun, 21 Nov 2010 17:07:34 +0000 |
| parents | 25de211794e8 |
| children | 8a556b3aff79 |
line wrap: on
line diff
--- a/path.c Sun Nov 21 16:52:22 2010 +0000 +++ b/path.c Sun Nov 21 17:07:34 2010 +0000 @@ -206,3 +206,27 @@ s = strrchr(path, '/'); return s ? s + 1 : path; } + +/** + * \brief Allocates a new buffer containing the directory name + * \param path Original path. Must be a valid string. + * + * The path returned always contains a trailing slash '/'. + * On systems supporting DOS paths, '\' is also considered as a directory + * separator in addition to the '/'. + */ +char *mp_dirname(const char *path) +{ + const char *base = mp_basename(path); + size_t len = base - path; + char *dirname; + + if (len == 0) + return strdup("./"); + dirname = malloc(len + 1); + if (!dirname) + return NULL; + strncpy(dirname, path, len); + dirname[len] = '\0'; + return dirname; +}
