home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / desklib / sources / DeskLib / !DLSources / OtherLibs / Debugs / c / uniquefile < prev    next >
Encoding:
Text File  |  1995-07-15  |  1.7 KB  |  74 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Debug.c.uniquefile
  12.     Author:  Julian Smith
  13.     Version: 0.00 (04 Jun 1995)
  14.     Purpose: Provides a set of Debug_ function which send stuff to a unique
  15.              file found using tmpnam().
  16. */
  17.  
  18.  
  19. #include <stdarg.h>
  20. #include <stdio.h>
  21.  
  22. #include "DeskLib:Error.h"
  23. #include "DeskLib:Str.h"
  24. #include "DeskLib:Debug.h"
  25.  
  26.  
  27.  
  28. static char    debug__filename[ 256] = "";
  29. static FILE    *debug__file;
  30. static BOOL    debug__initialised = FALSE;
  31.  
  32.  
  33.  
  34. #define Debug__EnsureInitialised()    if ( !debug__initialised)    Debug_Initialise()
  35.  
  36.  
  37.  
  38. void    Debug_Initialise( void)
  39. {
  40. debug__initialised = TRUE;
  41. tmpnam( debug__filename);
  42. debug__file = fopen( debug__filename, "w");
  43. if ( !debug__file)
  44.     Error_ReportFatal( 1, "Debug_Initialise can't open output file '%s'\n", debug__filename);
  45.  
  46. if (setvbuf( debug__file, NULL, _IONBF, 0))        /* Turn off buffering    */
  47.     Error_Report( 1, error_PLACE "Couldn't turn buffering off for output debug file");
  48. }
  49.  
  50.  
  51.  
  52. int    Debug_Printf( const char *format, ...)
  53. {
  54. va_list    va;
  55. int    i;
  56.  
  57. Debug__EnsureInitialised();
  58. va_start( va, format);
  59. i = vfprintf( debug__file, format, va);
  60. va_end( va);
  61.  
  62. return i;
  63. }
  64.  
  65.  
  66.  
  67. void    Debug_Print( const char *text)
  68. {
  69. Debug__EnsureInitialised();
  70. fputs( text, debug__file);
  71. }
  72.  
  73.  
  74.