mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
Add use of asprintf()
Add asprintf(), pg_asprintf(), and psprintf() to simplify string allocation and composition. Replacement implementations taken from NetBSD. Reviewed-by: Álvaro Herrera <alvherre@2ndquadrant.com> Reviewed-by: Asif Naeem <anaeem.it@gmail.com>
This commit is contained in:
@ -377,18 +377,16 @@ cash_out(PG_FUNCTION_ARGS)
|
||||
* from the value.
|
||||
*----------
|
||||
*/
|
||||
result = palloc(strlen(bufptr) + strlen(csymbol) + strlen(signsymbol) + 4);
|
||||
|
||||
switch (sign_posn)
|
||||
{
|
||||
case 0:
|
||||
if (cs_precedes)
|
||||
sprintf(result, "(%s%s%s)",
|
||||
result = psprintf("(%s%s%s)",
|
||||
csymbol,
|
||||
(sep_by_space == 1) ? " " : "",
|
||||
bufptr);
|
||||
else
|
||||
sprintf(result, "(%s%s%s)",
|
||||
result = psprintf("(%s%s%s)",
|
||||
bufptr,
|
||||
(sep_by_space == 1) ? " " : "",
|
||||
csymbol);
|
||||
@ -396,14 +394,14 @@ cash_out(PG_FUNCTION_ARGS)
|
||||
case 1:
|
||||
default:
|
||||
if (cs_precedes)
|
||||
sprintf(result, "%s%s%s%s%s",
|
||||
result = psprintf("%s%s%s%s%s",
|
||||
signsymbol,
|
||||
(sep_by_space == 2) ? " " : "",
|
||||
csymbol,
|
||||
(sep_by_space == 1) ? " " : "",
|
||||
bufptr);
|
||||
else
|
||||
sprintf(result, "%s%s%s%s%s",
|
||||
result = psprintf("%s%s%s%s%s",
|
||||
signsymbol,
|
||||
(sep_by_space == 2) ? " " : "",
|
||||
bufptr,
|
||||
@ -412,14 +410,14 @@ cash_out(PG_FUNCTION_ARGS)
|
||||
break;
|
||||
case 2:
|
||||
if (cs_precedes)
|
||||
sprintf(result, "%s%s%s%s%s",
|
||||
result = psprintf("%s%s%s%s%s",
|
||||
csymbol,
|
||||
(sep_by_space == 1) ? " " : "",
|
||||
bufptr,
|
||||
(sep_by_space == 2) ? " " : "",
|
||||
signsymbol);
|
||||
else
|
||||
sprintf(result, "%s%s%s%s%s",
|
||||
result = psprintf("%s%s%s%s%s",
|
||||
bufptr,
|
||||
(sep_by_space == 1) ? " " : "",
|
||||
csymbol,
|
||||
@ -428,14 +426,14 @@ cash_out(PG_FUNCTION_ARGS)
|
||||
break;
|
||||
case 3:
|
||||
if (cs_precedes)
|
||||
sprintf(result, "%s%s%s%s%s",
|
||||
result = psprintf("%s%s%s%s%s",
|
||||
signsymbol,
|
||||
(sep_by_space == 2) ? " " : "",
|
||||
csymbol,
|
||||
(sep_by_space == 1) ? " " : "",
|
||||
bufptr);
|
||||
else
|
||||
sprintf(result, "%s%s%s%s%s",
|
||||
result = psprintf("%s%s%s%s%s",
|
||||
bufptr,
|
||||
(sep_by_space == 1) ? " " : "",
|
||||
signsymbol,
|
||||
@ -444,14 +442,14 @@ cash_out(PG_FUNCTION_ARGS)
|
||||
break;
|
||||
case 4:
|
||||
if (cs_precedes)
|
||||
sprintf(result, "%s%s%s%s%s",
|
||||
result = psprintf("%s%s%s%s%s",
|
||||
csymbol,
|
||||
(sep_by_space == 2) ? " " : "",
|
||||
signsymbol,
|
||||
(sep_by_space == 1) ? " " : "",
|
||||
bufptr);
|
||||
else
|
||||
sprintf(result, "%s%s%s%s%s",
|
||||
result = psprintf("%s%s%s%s%s",
|
||||
bufptr,
|
||||
(sep_by_space == 1) ? " " : "",
|
||||
csymbol,
|
||||
|
Reference in New Issue
Block a user