]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: standard: add function that converts signed int to a string
authorThierry FOURNIER <tfournier@arpalert.org>
Sat, 6 Jun 2015 17:14:59 +0000 (19:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 13 Jun 2015 20:59:14 +0000 (22:59 +0200)
This function is the same as "ultoa_r", but it takes a signed value
as input.

include/common/standard.h
src/standard.c

index 759d0a11ca68d47b6a608773d2affec1beb95897..df2444d3350b413e6b5b5c34487f172da5788c63 100644 (file)
@@ -105,6 +105,7 @@ extern int strlcpy2(char *dst, const char *src, int size);
  */
 extern char itoa_str[][171];
 extern char *ultoa_r(unsigned long n, char *buffer, int size);
+extern char *sltoa_r(long n, char *buffer, int size);
 extern const char *ulltoh_r(unsigned long long n, char *buffer, int size);
 static inline const char *ultoa(unsigned long n)
 {
index 4e458c25c1eae761fa5dd3fe9250a6ec2fcefc20..fb24f7d37cc8190baf12d1cfd002ac43b32554d4 100644 (file)
@@ -406,6 +406,22 @@ char *ultoa_r(unsigned long n, char *buffer, int size)
        return pos + 1;
 }
 
+/*
+ * This function simply returns a locally allocated string containing
+ * the ascii representation for signed number 'n' in decimal.
+ */
+char *sltoa_r(long n, char *buffer, int size)
+{
+       char *pos;
+
+       if (n >= 0)
+               return ultoa_r(n, buffer, size);
+
+       pos = ultoa_r(-n, buffer + 1, size - 1) - 1;
+       *pos = '-';
+       return pos;
+}
+
 /*
  * This function simply returns a locally allocated string containing
  * the ascii representation for number 'n' in decimal, formatted for