dir-util.cpp revision e188d779210569558801f9313494f956bc08fdcb
/** @file
* @brief Utility functions for filenames
*/
#define DIR_UTIL_C
#include <errno.h>
#include <string>
#include <cstring>
#include <glib/gconvert.h>
#include <glib/gstrfuncs.h>
/** Returns a form of \a path relative to \a base if that is easy to construct (e.g. if \a path
appears to be in the directory specified by \a base), otherwise returns \a path.
N.B. The return value is a pointer into the \a path string.
\a base is expected to be either NULL or the absolute path of a directory.
\a path is expected to be an absolute path.
\see inkscape_abs2rel for a more sophisticated version.
\see prepend_current_dir_if_relative.
*/
char const *
{
return path;
}
while (base_len != 0
{
--base_len;
}
{
while (*ret == G_DIR_SEPARATOR) {
++ret;
}
if (*ret != '\0') {
return ret;
}
}
return path;
}
char const *
sp_extension_from_path(char const *const path)
{
return NULL;
}
char const *p = path;
while (*p != '\0') p++;
if (* p != '.') return NULL;
p++;
return p;
}
/* current == "./", parent == "../" */
/**
* \brief Convert a relative path name into absolute. If path is already absolute, does nothing except copying path to result.
*
* \param path relative path
* \param base base directory (must be absolute path)
* \param result result buffer
* \param size size of result buffer
* \return != NULL: absolute path
* == NULL: error
\comment
based on functions by Shigio Yamaguchi.
FIXME:TODO: force it to also do path normalization of the entire resulting path,
i.e. get rid of any .. and . in any place, even if 'path' is already absolute
(now it returns it unchanged in this case)
*/
char *
{
/* endp points the last position which is safe in the result buffer. */
char *rp;
int length;
if (*path == G_DIR_SEPARATOR)
{
goto erange;
goto finish;
}
{
return (NULL);
}
else if (size == 1)
goto erange;
{
goto erange;
/* rp points the last char. */
if (*rp == G_DIR_SEPARATOR)
*rp = 0;
else
rp++;
/* rp point NULL char */
if (*++path == G_DIR_SEPARATOR)
{
/* Append G_DIR_SEPARATOR to the tail of path name. */
*rp++ = G_DIR_SEPARATOR;
goto erange;
*rp = 0;
}
goto finish;
}
--bp;
/* up to root. */
{
{
pp += 3;
;
}
{
pp += 2;
}
{
pp += 2;
;
}
else
break;
}
/* down to leaf. */
goto erange;
*rp++ = G_DIR_SEPARATOR;
goto erange;
return result;
return (NULL);
}
char *
{
/* endp points the last position which is safe in the result buffer. */
char *rp;
if (*path != G_DIR_SEPARATOR)
{
goto erange;
goto finish;
}
{
return (NULL);
}
else if (size == 1)
goto erange;
/* seek to branched point. */
if (*pp == G_DIR_SEPARATOR)
{
*rp++ = '.';
*rp++ = G_DIR_SEPARATOR;
goto erange;
*rp = 0;
goto finish;
}
/* up to root. */
{
goto erange;
*rp++ = '.';
*rp++ = '.';
*rp++ = G_DIR_SEPARATOR;
}
goto erange;
*rp = 0;
/* down to leaf. */
if (*branch)
{
goto erange;
}
else
*--rp = 0;
return result;
return (NULL);
}
void
{
if (!uri) {
return;
}
char *cwd = g_get_current_dir();
gsize bytesWritten = 0;
-1,
&error);
}