MCPcopy Create free account
hub / github.com/apache/cloudberry / psprintf

Function psprintf

src/common/psprintf.c:45–76  ·  view source on GitHub ↗

* psprintf * * Format text data under the control of fmt (an sprintf-style format string) * and return it in an allocated-on-demand buffer. The buffer is allocated * with palloc in the backend, or malloc in frontend builds. Caller is * responsible to free the buffer when no longer needed, if appropriate. * * Errors are not returned to the caller, but are reported via elog(ERROR) * in the

Source from the content-addressed store, hash-verified

43 * One should therefore think twice about using this in libpq.
44 */
45char *
46psprintf(const char *fmt,...)
47{
48 int save_errno = errno;
49 size_t len = 128; /* initial assumption about buffer size */
50
51 for (;;)
52 {
53 char *result;
54 va_list args;
55 size_t newlen;
56
57 /*
58 * Allocate result buffer. Note that in frontend this maps to malloc
59 * with exit-on-error.
60 */
61 result = (char *) palloc(len);
62
63 /* Try to format the data. */
64 errno = save_errno;
65 va_start(args, fmt);
66 newlen = pvsnprintf(result, len, fmt, args);
67 va_end(args);
68
69 if (newlen < len)
70 return result; /* success */
71
72 /* Release buffer and loop around to try again with larger len. */
73 pfree(result);
74 len = newlen;
75 }
76}
77
78/*
79 * pvsnprintf

Callers 15

foreign_join_okFunction · 0.85
foreign_grouping_okFunction · 0.85
verify_heapamFunction · 0.85
check_tuple_headerFunction · 0.85
check_tuple_visibilityFunction · 0.85
check_toast_tupleFunction · 0.85
check_tuple_attributeFunction · 0.85
check_toasted_attributeFunction · 0.85
check_tupleFunction · 0.85
bt_target_page_checkFunction · 0.85
bt_page_stats_internalFunction · 0.85

Calls 3

pvsnprintfFunction · 0.85
pallocFunction · 0.70
pfreeFunction · 0.70

Tested by 13

isolation_start_testFunction · 0.68
isolation_initFunction · 0.68
mainFunction · 0.68
test_singlerowmodeFunction · 0.68
psql_start_testFunction · 0.68
make_temp_sockdirFunction · 0.68
initialize_environmentFunction · 0.68
spawn_processFunction · 0.68
regression_mainFunction · 0.68
get_host_nameFunction · 0.68
widget_outFunction · 0.68
ecpg_start_testFunction · 0.68