Add snprintf wrapper for GCC 8.2/3
[collectd.git] / src / postgresql.c
index 8e4328f..466c0e3 100644 (file)
@@ -58,7 +58,7 @@
  * is ignored. */
 #define C_PSQL_PAR_APPEND(buf, buf_len, parameter, value)                      \
   if ((0 < (buf_len)) && (NULL != (value)) && ('\0' != *(value))) {            \
-    int s = snprintf(buf, buf_len, " %s = '%s'", parameter, value);            \
+    int s = ssnprintf(buf, buf_len, " %s = '%s'", parameter, value);            \
     if (0 < s) {                                                               \
       buf += s;                                                                \
       buf_len -= s;                                                            \
@@ -323,7 +323,7 @@ static int c_psql_connect(c_psql_database_t *db) {
   if ((!db) || (!db->database))
     return -1;
 
-  status = snprintf(buf, buf_len, "dbname = '%s'", db->database);
+  status = ssnprintf(buf, buf_len, "dbname = '%s'", db->database);
   if (0 < status) {
     buf += status;
     buf_len -= status;
@@ -426,7 +426,7 @@ static PGresult *c_psql_exec_query_params(c_psql_database_t *db, udb_query_t *q,
       params[i] = db->user;
       break;
     case C_PSQL_PARAM_INTERVAL:
-      snprintf(interval, sizeof(interval), "%.3f",
+      ssnprintf(interval, sizeof(interval), "%.3f",
                CDTIME_T_TO_DOUBLE(plugin_get_interval()));
       params[i] = interval;
       break;
@@ -632,7 +632,7 @@ static char *values_name_to_sqlarray(const data_set_t *ds, char *string,
   str_len = string_len;
 
   for (size_t i = 0; i < ds->ds_num; ++i) {
-    int status = snprintf(str_ptr, str_len, ",'%s'", ds->ds[i].name);
+    int status = ssnprintf(str_ptr, str_len, ",'%s'", ds->ds[i].name);
 
     if (status < 1)
       return NULL;
@@ -670,9 +670,9 @@ static char *values_type_to_sqlarray(const data_set_t *ds, char *string,
     int status;
 
     if (store_rates)
-      status = snprintf(str_ptr, str_len, ",'gauge'");
+      status = ssnprintf(str_ptr, str_len, ",'gauge'");
     else
-      status = snprintf(str_ptr, str_len, ",'%s'",
+      status = ssnprintf(str_ptr, str_len, ",'%s'",
                         DS_TYPE_TO_STRING(ds->ds[i].type));
 
     if (status < 1) {
@@ -725,7 +725,7 @@ static char *values_to_sqlarray(const data_set_t *ds, const value_list_t *vl,
 
     if (ds->ds[i].type == DS_TYPE_GAUGE)
       status =
-          snprintf(str_ptr, str_len, "," GAUGE_FORMAT, vl->values[i].gauge);
+          ssnprintf(str_ptr, str_len, "," GAUGE_FORMAT, vl->values[i].gauge);
     else if (store_rates) {
       if (rates == NULL)
         rates = uc_get_rate(ds, vl);
@@ -735,14 +735,14 @@ static char *values_to_sqlarray(const data_set_t *ds, const value_list_t *vl,
         return NULL;
       }
 
-      status = snprintf(str_ptr, str_len, ",%lf", rates[i]);
+      status = ssnprintf(str_ptr, str_len, ",%lf", rates[i]);
     } else if (ds->ds[i].type == DS_TYPE_COUNTER)
-      status = snprintf(str_ptr, str_len, ",%" PRIu64,
+      status = ssnprintf(str_ptr, str_len, ",%" PRIu64,
                         (uint64_t)vl->values[i].counter);
     else if (ds->ds[i].type == DS_TYPE_DERIVE)
-      status = snprintf(str_ptr, str_len, ",%" PRIi64, vl->values[i].derive);
+      status = ssnprintf(str_ptr, str_len, ",%" PRIi64, vl->values[i].derive);
     else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
-      status = snprintf(str_ptr, str_len, ",%" PRIu64, vl->values[i].absolute);
+      status = ssnprintf(str_ptr, str_len, ",%" PRIu64, vl->values[i].absolute);
 
     if (status < 1) {
       str_len = 0;
@@ -940,7 +940,7 @@ static int c_psql_shutdown(void) {
 
     if (db->writers_num > 0) {
       char cb_name[DATA_MAX_NAME_LEN];
-      snprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->database);
+      ssnprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->database);
 
       if (!had_flush) {
         plugin_unregister_flush("postgresql");
@@ -1199,7 +1199,7 @@ static int c_psql_config_database(oconfig_item_t *ci) {
     }
   }
 
-  snprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->instance);
+  ssnprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->instance);
 
   user_data_t ud = {.data = db, .free_func = c_psql_database_delete};