summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Patrick Griffis <tingping@tingping.se>2016-01-19 18:51:45 -0500
committerGravatar Patrick Griffis <tingping@tingping.se>2016-01-19 19:35:10 -0500
commit36d32c0c9a86ada87843b062f81783c8711dec3e (patch)
treed35133b17460535e1c4f3f637c582e4e7f566533 /src
parentb40ee0f6522dcbbca6ebfe80d365590b6593e9a1 (diff)
Remove custom string functions provided by glib
Diffstat (limited to 'src')
-rw-r--r--src/trg-general-panel.c4
-rw-r--r--src/util.c78
-rw-r--r--src/util.h5
3 files changed, 13 insertions, 74 deletions
diff --git a/src/trg-general-panel.c b/src/trg-general-panel.c
index de05b13..cbcad42 100644
--- a/src/trg-general-panel.c
+++ b/src/trg-general-panel.c
@@ -216,10 +216,10 @@ trg_general_panel_update(TrgGeneralPanel * panel, JsonObject * t,
gtk_label_set_text(GTK_LABEL(priv->gen_eta_label), _("N/A"));
}
- snprintf(buf, sizeof(buf), "%" G_GINT64_FORMAT,
+ g_snprintf(buf, sizeof(buf), "%" G_GINT64_FORMAT,
seeders >= 0 ? seeders : 0);
gtk_label_set_text(GTK_LABEL(priv->gen_seeders_label), buf);
- snprintf(buf, sizeof(buf), "%" G_GINT64_FORMAT,
+ g_snprintf(buf, sizeof(buf), "%" G_GINT64_FORMAT,
leechers >= 0 ? leechers : 0);
gtk_label_set_text(GTK_LABEL(priv->gen_leechers_label), buf);
}
diff --git a/src/util.c b/src/util.c
index d45822c..472af3b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -113,7 +113,7 @@ static char *formatter_get_size_str(const struct formatter_units *u,
precision = 2;
else
precision = 1;
- tr_snprintf(buf, buflen, "%.*f %s", precision, value, units);
+ g_snprintf(buf, buflen, "%.*f %s", precision, value, units);
return buf;
}
@@ -151,19 +151,19 @@ char *tr_formatter_speed_KBps(char *buf, double KBps, size_t buflen)
double speed = KBps;
if (speed <= 999.95) /* 0.0 KB to 999.9 KB */
- tr_snprintf(buf, buflen, "%d %s", (int) speed,
+ g_snprintf(buf, buflen, "%d %s", (int) speed,
speed_units.units[TR_FMT_KB].name);
else {
speed /= K;
if (speed <= 99.995) /* 0.98 MB to 99.99 MB */
- tr_snprintf(buf, buflen, "%.2f %s", speed,
+ g_snprintf(buf, buflen, "%.2f %s", speed,
speed_units.units[TR_FMT_MB].name);
else if (speed <= 999.95) /* 100.0 MB to 999.9 MB */
- tr_snprintf(buf, buflen, "%.1f %s", speed,
+ g_snprintf(buf, buflen, "%.1f %s", speed,
speed_units.units[TR_FMT_MB].name);
else {
speed /= K;
- tr_snprintf(buf, buflen, "%.1f %s", speed,
+ g_snprintf(buf, buflen, "%.1f %s", speed,
speed_units.units[TR_FMT_GB].name);
}
}
@@ -367,7 +367,7 @@ char *tr_strlpercent(char *buf, double x, size_t buflen)
else
precision = 0;
- tr_snprintf(buf, buflen, "%.*f%%", precision, tr_truncd(x, precision));
+ g_snprintf(buf, buflen, "%.*f%%", precision, tr_truncd(x, precision));
return buf;
}
@@ -382,15 +382,15 @@ char *tr_strratio(char *buf, size_t buflen, double ratio,
const char *infinity)
{
if ((int) ratio == TR_RATIO_NA)
- tr_strlcpy(buf, _("None"), buflen);
+ g_strlcpy(buf, _("None"), buflen);
else if ((int) ratio == TR_RATIO_INF)
- tr_strlcpy(buf, infinity, buflen);
+ g_strlcpy(buf, infinity, buflen);
else if (ratio < 10.0)
- tr_snprintf(buf, buflen, "%.2f", tr_truncd(ratio, 2));
+ g_snprintf(buf, buflen, "%.2f", tr_truncd(ratio, 2));
else if (ratio < 100.0)
- tr_snprintf(buf, buflen, "%.1f", tr_truncd(ratio, 1));
+ g_snprintf(buf, buflen, "%.1f", tr_truncd(ratio, 1));
else
- tr_snprintf(buf, buflen, "%'.0f", ratio);
+ g_snprintf(buf, buflen, "%'.0f", ratio);
return buf;
}
@@ -481,17 +481,6 @@ char *gtr_localtime2(char *buf, time_t time, size_t buflen)
return buf;
}
-int tr_snprintf(char *buf, size_t buflen, const char *fmt, ...)
-{
- int len;
- va_list args;
-
- va_start(args, fmt);
- len = evutil_vsnprintf(buf, buflen, fmt, args);
- va_end(args);
- return len;
-}
-
gchar *epoch_to_string(gint64 epoch)
{
GDateTime *dt = g_date_time_new_from_unix_local(epoch);
@@ -534,51 +523,6 @@ gchar *add_links_to_text(const gchar * original)
return newText;
}
-size_t tr_strlcpy(char *dst, const void *src, size_t siz)
-{
-#ifdef HAVE_STRLCPY
- return strlcpy(dst, src, siz);
-#else
- char *d = dst;
- const char *s = src;
- size_t n = siz;
-
- /* Copy as many bytes as will fit */
- if (n != 0) {
- while (--n != 0) {
- if ((*d++ = *s++) == '\0')
- break;
- }
- }
-
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0) {
- if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
- while (*s++);
- }
-
- return s - (char *) src - 1; /* count does not include NUL */
-#endif
-}
-
-int
-evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap)
-{
-#ifdef _MSC_VER
- int r = _vsnprintf(buf, buflen, format, ap);
- buf[buflen - 1] = '\0';
- if (r >= 0)
- return r;
- else
- return _vscprintf(format, ap);
-#else
- int r = vsnprintf(buf, buflen, format, ap);
- buf[buflen - 1] = '\0';
- return r;
-#endif
-}
-
char *tr_strlsize(char *buf, guint64 bytes, size_t buflen)
{
if (!bytes)
diff --git a/src/util.h b/src/util.h
index e7f4c07..76d95a5 100644
--- a/src/util.h
+++ b/src/util.h
@@ -79,12 +79,7 @@ char *tr_strratio(char *buf, size_t buflen, double ratio,
char *tr_strlratio(char *buf, double ratio, size_t buflen);
char *gtr_localtime(time_t time);
char *gtr_localtime2(char *buf, time_t time, size_t buflen);
-int tr_snprintf(char *buf, size_t buflen, const char *fmt, ...);
-int tr_snprintf(char *buf, size_t buflen, const char *fmt, ...);
-size_t tr_strlcpy(char *dst, const void *src, size_t siz);
double tr_truncd(double x, int decimal_places);
-int evutil_vsnprintf(char *buf, size_t buflen, const char *format,
- va_list ap);
char *tr_strlsize(char *buf, guint64 bytes, size_t buflen);
void rm_trailing_slashes(gchar * str);
void trg_widget_set_visible(GtkWidget * w, gboolean visible);