3
0

info_msg.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routines.
  4. *
  5. * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  8. */
  9. #include "libbb.h"
  10. #if ENABLE_FEATURE_SYSLOG
  11. # include <syslog.h>
  12. #endif
  13. void FAST_FUNC bb_info_msg(const char *s, ...)
  14. {
  15. #ifdef THIS_ONE_DOESNT_DO_SINGLE_WRITE
  16. va_list p;
  17. /* va_copy is used because it is not portable
  18. * to use va_list p twice */
  19. va_list p2;
  20. va_start(p, s);
  21. va_copy(p2, p);
  22. if (logmode & LOGMODE_STDIO) {
  23. vprintf(s, p);
  24. fputs(msg_eol, stdout);
  25. }
  26. # if ENABLE_FEATURE_SYSLOG
  27. if (logmode & LOGMODE_SYSLOG)
  28. vsyslog(LOG_INFO, s, p2);
  29. # endif
  30. va_end(p2);
  31. va_end(p);
  32. #else
  33. int used;
  34. char *msg;
  35. va_list p;
  36. if (logmode == 0)
  37. return;
  38. va_start(p, s);
  39. used = vasprintf(&msg, s, p);
  40. va_end(p);
  41. if (used < 0)
  42. return;
  43. # if ENABLE_FEATURE_SYSLOG
  44. if (logmode & LOGMODE_SYSLOG)
  45. syslog(LOG_INFO, "%s", msg);
  46. # endif
  47. if (logmode & LOGMODE_STDIO) {
  48. fflush_all();
  49. /* used = strlen(msg); - must be true already */
  50. msg[used++] = '\n';
  51. full_write(STDOUT_FILENO, msg, used);
  52. }
  53. free(msg);
  54. #endif
  55. }