#ifndef LIBSOLV_TOOLS_UTIL_H
#define LIBSOLV_TOOLS_UTIL_H
-static char *_join_tmp;
-static int _join_tmpl;
-
-struct parsedata_common {
- char *tmp;
- int tmpl;
- Pool *pool;
- Repo *repo;
-};
-
static inline Id
makeevr(Pool *pool, const char *s)
{
}
#endif
+#ifndef DISABLE_JOIN2
+
+struct joindata {
+ char *tmp;
+ int tmpl;
+};
+
/* this join does not depend on parsedata */
static char *
-join2(const char *s1, const char *s2, const char *s3)
+join2(struct joindata *jd, const char *s1, const char *s2, const char *s3)
{
int l = 1;
char *p;
l += strlen(s2);
if (s3)
l += strlen(s3);
- if (l > _join_tmpl)
+ if (l > jd->tmpl)
{
- _join_tmpl = l + 256;
- if (!_join_tmp)
- _join_tmp = malloc(_join_tmpl);
- else
- _join_tmp = realloc(_join_tmp, _join_tmpl);
+ jd->tmpl = l + 256;
+ jd->tmp = solv_realloc(jd->tmp, jd->tmpl);
}
- p = _join_tmp;
+ p = jd->tmp;
if (s1)
{
strcpy(p, s1);
p += strlen(s3);
}
*p = 0;
- return _join_tmp;
+ return jd->tmp;
}
-static inline void
-join_freemem(void)
+static inline char *
+join_dup(struct joindata *jd, const char *s)
{
- if (_join_tmp)
- free(_join_tmp);
- _join_tmp = 0;
- _join_tmpl = 0;
+ return s ? join2(jd, s, 0, 0) : 0;
}
-/* util function to set a translated string */
-static inline void repodata_set_tstr(Repodata *data, Id handle, const char *attrname, const char *lang, const char *str)
+static inline void
+join_freemem(struct joindata *jd)
{
- Id attrid;
- attrid = pool_str2id(data->repo->pool, join2(attrname, ":", lang), 1);
- repodata_set_str(data, handle, attrid, str);
+ if (jd->tmp)
+ free(jd->tmp);
+ jd->tmp = 0;
+ jd->tmpl = 0;
}
+#endif
+
#endif /* LIBSOLV_TOOLS_UTIL_H */