UTI_RenameTempFile(const char *basedir, const char *name,
                   const char *old_suffix, const char *new_suffix)
{
  char old_path[PATH_MAX], new_path[PATH_MAX];

  if (!join_path(basedir, name, old_suffix, old_path, sizeof (old_path), LOGS_ERR))
    return 0;

  if (!join_path(basedir, name, new_suffix, new_path, sizeof (new_path), LOGS_ERR))
    goto error;

  if (rename(old_path, new_path) < 0) {
    LOG(LOGS_ERR, "Could not replace %s with %s : %s", new_path, old_path, strerror(errno));
    goto error;
  }

  DEBUG_LOG("Renamed %s to %s", old_path, new_path);

  return 1;

error:
  if (unlink(old_path) < 0)
    LOG(LOGS_ERR, "Could not remove %s : %s", old_path, strerror(errno));

  return 0;
}
UTI_RenameTempFile(const char *basedir, const char *name,
                   const char *old_suffix, const char *new_suffix)
{
  char old_path[PATH_MAX], new_path[PATH_MAX];

  if (!join_path(basedir, name, old_suffix, old_path, sizeof (old_path), LOGS_ERR))
    return 0;

  if (!join_path(basedir, name, new_suffix, new_path, sizeof (new_path), LOGS_ERR))
    goto error;

  if (rename(old_path, new_path) < 0) {
    LOG(LOGS_ERR, "Could not replace %s with %s : %s", new_path, old_path, strerror(errno));
    goto error;
  }

  DEBUG_LOG("Renamed %s to %s", old_path, new_path);

  return 1;

error:
  if (unlink(old_path) < 0)
    LOG(LOGS_ERR, "Could not remove %s : %s", old_path, strerror(errno));

  return 0;
}