lametime.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Lame time routines source file
  3. *
  4. * Copyright (c) 2000 Mark Taylor
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. /* $Id: lametime.c,v 1.10 2001/02/26 18:57:20 markt Exp $ */
  22. /*
  23. * name: GetCPUTime ( void )
  24. *
  25. * description: returns CPU time used by the process
  26. * input: none
  27. * output: time in seconds
  28. * known bugs: may not work in SMP and RPC
  29. * conforming: ANSI C
  30. *
  31. * There is some old difficult to read code at the end of this file.
  32. * Can someone integrate this into this function (if useful)?
  33. */
  34. #define _BSD_EXTENSION
  35. #ifdef HAVE_CONFIG_H
  36. # include <config.h>
  37. #endif
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <unistd.h>
  41. #include <assert.h>
  42. #include <time.h>
  43. #include <sys/types.h>
  44. #include <sys/stat.h>
  45. #include <sys/time.h>
  46. #include "lametime.h"
  47. double GetCPUTime ( void )
  48. {
  49. return clock () / (double) CLOCKS_PER_SEC;
  50. }
  51. /*
  52. * name: GetRealTime ( void )
  53. *
  54. * description: returns real (human) time elapsed relative to a fixed time (mostly 1970-01-01 00:00:00)
  55. * input: none
  56. * output: time in seconds
  57. * known bugs: bad precision with time()
  58. */
  59. double GetRealTime ( void ) /* conforming: SVr4, BSD 4.3 */
  60. {
  61. struct timeval t;
  62. if ( 0 != gettimeofday (&t, NULL) )
  63. assert (0);
  64. return t.tv_sec + 1.e-6 * t.tv_usec;
  65. }
  66. int lame_set_stream_binary_mode ( FILE* const fp )
  67. {
  68. return 0;
  69. }
  70. off_t lame_get_file_size ( const char* const filename )
  71. {
  72. struct stat sb;
  73. if ( 0 == stat ( filename, &sb ) )
  74. return sb.st_size;
  75. return (off_t) -1;
  76. }