fprintf(stderr, "my_makepath(\"%s\", %d)\n", path, mode);
#endif
char *realpath = strdup(path);
- char *pathtrak = ((realpath[0] == '/') ? realpath + 1 : realpath);
+ char *pathtrak = ((realpath[0] == UTIL_PATHSEP_CHAR) ? realpath + 1 : realpath);
/* this will FUBAR on Windows, but since I'm not responsible for the
* Windows port, whoever *is* responsible for the Windows port can have
* the pleasure of figuring out how to do the equivalent job. */
{
struct stat s;
int i;
- pathtrak = strchr(pathtrak, '/');
+ pathtrak = strchr(pathtrak, UTIL_PATHSEP_CHAR);
if (pathtrak)
{
pathtrak[0] = '\0';
#ifdef UTIL_DEBUG
- fprintf(stderr, "Checking %s (pathtrak offset %d)\n", realpath, (int) (pathtrak - realpath));
+ fprintf(stderr, "%d Checking %s (pathtrak offset %d)\n", __LINE__, realpath, (int) (pathtrak - realpath));
#endif
i = stat(realpath, &s);
if (i == 0)
{
#ifdef UTIL_DEBUG
- fprintf(stderr, "stat(\"%s\") returned 0\n", realpath);
+ fprintf(stderr, "%d stat(\"%s\") returned 0\n", __LINE__, realpath);
#endif
if ((s.st_mode & S_IFMT) == S_IFDIR)
{
- pathtrak[0] = '/';
+ pathtrak[0] = UTIL_PATHSEP_CHAR;
++pathtrak;
}
else
{
#ifdef UTIL_DEBUG
- fprintf(stderr, "not a directory\n");
+ fprintf(stderr, "%d not a directory\n", __LINE__);
#endif
errno = ENOTDIR;
rv = -1;
else
{
#ifdef UTIL_DEBUG
- fprintf(stderr, "stat(\"%s\") returned %d, errno %d (%s)\n",
- realpath, i, errno, strerror(errno));
+ fprintf(stderr, "%d stat(\"%s\") returned %d, errno %d (%s)\n",
+ __LINE__, realpath, i, errno, strerror(errno));
#endif
if (errno == ENOENT)
{
#ifdef UTIL_DEBUG
- fprintf(stderr, "mkdir(\"%s\", %d)\n", realpath, mode);
+ fprintf(stderr, "%d mkdir(\"%s\", %d)\n", __LINE__, realpath, mode);
#endif
i = mkdir(realpath, mode);
if (i != 0)
{
#ifdef UTIL_DEBUG
- fprintf(stderr, "mkdir(\"%s\", %d) returned %d, errno %d (%s)\n", realpath, mode, i, errno, strerror(errno));
+ fprintf(stderr, "%d mkdir(\"%s\", %d) returned %d, errno %d (%s)\n", __LINE__, realpath, mode, i, errno, strerror(errno));
#endif
rv = -1;
break;
}
+ pathtrak[0] = UTIL_PATHSEP_CHAR;
+ ++pathtrak;
}
}
}
if (i == 0)
{
#ifdef UTIL_DEBUG
- fprintf(stderr, "stat(\"%s\") returned 0\n", realpath);
+ fprintf(stderr, "%d stat(\"%s\") returned 0\n", __LINE__, realpath);
#endif
if ((s.st_mode & S_IFMT) == S_IFDIR)
{
if (errno == ENOENT)
{
#ifdef UTIL_DEBUG
- fprintf(stderr, "mkdir(\"%s\", %d)\n", realpath, mode);
+ fprintf(stderr, "%d mkdir(\"%s\", %d)\n", __LINE__, realpath, mode);
#endif
i = mkdir(realpath, mode);
if (i != 0)
{
#ifdef UTIL_DEBUG
- fprintf(stderr, "mkdir(\"%s\", %d) returned %d, errno %d (%s)\n", realpath, mode, i, errno, strerror(errno));
+ fprintf(stderr, "%d mkdir(\"%s\", %d) returned %d, errno %d (%s)\n", __LINE__, realpath, mode, i, errno, strerror(errno));
#endif
rv = -1;
}
else
{
+ fprintf(stderr, "%d mkdir(\"%s\", %d) returned 0\n", __LINE__, realpath, mode);
rv = 0;
}
}
}
/*! \brief compose a directory suffix from a vendor name and an app name
+ *
+ * \todo include proper sanitization of vendor and app strings
+ * \param vendor "Vendor name" to use in suffix
+ * \param app "Application name" to use in suffix
*/
static char *app_suffix(char const *vendor, char const *app)
{
errno = EINVAL;
return NULL;
}
- // TODO include proper sanitization of vendor and app strings
+ // TODO
s1 = strlen(vendor);
s2 = strlen(UTIL_PATHSEP_STRING);
s3 = strlen(app);