testfrmw.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2004, Bull S.A.. All rights reserved.
  3. * Created by: Sebastien Decugis
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program; if not, write the Free Software Foundation, Inc.,
  14. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. *
  16. * This file is a wrapper to use the tests from the NPTL Test & Trace Project
  17. * with either the Linux Test Project or the Open POSIX Test Suite.
  18. * The following function are defined:
  19. * void output_init()
  20. * void output_fini()
  21. * void output(char * string, ...)
  22. *
  23. * The are used to output informative text (as a printf).
  24. */
  25. #include <time.h>
  26. #include <sys/types.h>
  27. #include <pthread.h>
  28. #include <stdarg.h>
  29. /* We use a mutex to avoid conflicts in traces */
  30. static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER;
  31. static void output_init(void)
  32. {
  33. return;
  34. }
  35. static void output(char *string, ...)
  36. {
  37. va_list ap;
  38. struct tm *now;
  39. time_t nw;
  40. int oldstate;
  41. pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
  42. pthread_mutex_lock(&m_trace);
  43. nw = time(NULL);
  44. now = localtime(&nw);
  45. if (now == NULL)
  46. printf("[??:??:??]\n");
  47. else
  48. printf("[%2.2d:%2.2d:%2.2d]\n",
  49. now->tm_hour, now->tm_min, now->tm_sec);
  50. va_start(ap, string);
  51. vprintf(string, ap);
  52. va_end(ap);
  53. pthread_mutex_unlock(&m_trace);
  54. pthread_setcancelstate(oldstate, NULL);
  55. }
  56. static void output_fini(void)
  57. {
  58. return;
  59. }