00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #include "config.h"
00019 
00020 #include <stdio.h>
00021 #include <string.h>
00022 
00023 #include <sys/types.h>
00024 #include <sys/time.h>
00025 
00026 #include "assert_pp.h"
00027 #include "time_util.h"
00028 
00029 int string_to_microsec(unsigned long long *us_out, const char *str)
00030 {
00031     char dead, units[3] = { 'u', 's', '\0' };
00032     int retval = 0;
00033 
00034     require(us_out != NULL);
00035     require(str != NULL);
00036 
00037     
00038     *us_out = 0;
00039 
00040     
00041 
00042 
00043 
00044 
00045 
00046     switch( sscanf(str, "%qu%c%c%c", us_out, &units[0], &units[1], &dead) )
00047     {
00048     case 1: 
00049     case 3:
00050         if( strcmp(units, "us") == 0 )
00051         {
00052             retval = 1;
00053         }
00054         else if( strcmp(units, "ms") == 0 )
00055         {
00056             *us_out *= 1000;
00057             retval = 1;
00058         }
00059         break;
00060     case 2:
00061         units[1] = '\0';
00062         if( strcmp(units, "s") == 0 )
00063         {
00064             *us_out *= 1000000;
00065             retval = 1;
00066         }
00067         else if( strcmp(units, "m") == 0 )
00068         {
00069             *us_out *= 1000000 * 60;
00070             retval = 1;
00071         }
00072         break;
00073     case 0:
00074         
00075         break;
00076     case 4:
00077         
00078         break;
00079     case EOF:
00080         
00081         break;
00082     default:
00083         ensure(0);
00084         break;
00085     }
00086     return( retval );
00087 }