You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

printf.h 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2024 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef PRINTF_H_
  17. #define PRINTF_H_
  18. #include "config.h"
  19. #include "fstring.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /*
  24. * supported formats:
  25. * %[0][width][x][X]O off_t
  26. * %[0][width]T time_t
  27. * %[0][width][u][x|X|h|H|b|B]z ssize_t/size_t
  28. * %[0][width][u][x|X|h|H|b|B]d gint/guint
  29. * %[0][width][u][x|X|h|H|b|B]l long
  30. * %[0][width][u][x|X|h|H|b|B]D int32_t/uint32_t
  31. * %[0][width][u][x|X|h|H|b|B]L int64_t/uint64_t
  32. * %[0][width][.width]f double
  33. * %[0][width][.width]F long double
  34. * %[0][width][.width]g double
  35. * %[0][width][.width]G long double
  36. * %P pid_t
  37. * %r rlim_t
  38. * %p void *
  39. * %V rspamd_fstring_t *
  40. * %T rspamd_ftok_t
  41. * %v GString *
  42. * %s null-terminated string
  43. * %xs hex encoded string
  44. * %bs base32 encoded string
  45. * %Bs base64 encoded string
  46. * %*s length and string
  47. * %Z '\0'
  48. * %N '\n'
  49. * %c gchar
  50. * %t time_t
  51. * %e GError *
  52. * %% %
  53. *
  54. */
  55. /**
  56. * Callback used for common printf operations
  57. * @param buf buffer to append
  58. * @param buflen length of the buffer
  59. * @param ud opaque pointer
  60. * @return number of characters written
  61. */
  62. typedef glong (*rspamd_printf_append_func)(const gchar *buf, glong buflen,
  63. gpointer ud);
  64. glong rspamd_fprintf(FILE *f, const gchar *fmt, ...);
  65. glong rspamd_printf(const gchar *fmt, ...);
  66. glong rspamd_log_fprintf(FILE *f, const gchar *fmt, ...);
  67. glong rspamd_snprintf(gchar *buf, glong max, const gchar *fmt, ...);
  68. gchar *rspamd_vsnprintf(gchar *buf, glong max, const gchar *fmt,
  69. va_list args);
  70. glong rspamd_printf_gstring(GString *s, const gchar *fmt, ...);
  71. glong rspamd_vprintf_gstring(GString *s, const gchar *fmt, va_list args);
  72. glong rspamd_printf_fstring(rspamd_fstring_t **s, const gchar *fmt, ...);
  73. glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const gchar *fmt, va_list args);
  74. glong rspamd_vprintf_common(rspamd_printf_append_func func,
  75. gpointer apd,
  76. const gchar *fmt,
  77. va_list args);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /* PRINTF_H_ */