Changeset 251 for trunk/lib


Ignore:
Timestamp:
05/05/11 21:34:35 (13 years ago)
Author:
tim
Message:

simplified NTTIME storage and conversions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/regfi.c

    r250 r251  
    27532753  ret_val->sequence1 = IVAL(file_header, 0x4);
    27542754  ret_val->sequence2 = IVAL(file_header, 0x8);
    2755   ret_val->mtime.low = IVAL(file_header, 0xC);
    2756   ret_val->mtime.high = IVAL(file_header, 0x10);
     2755  ret_val->mtime = ((uint64_t)IVAL(file_header, 0x10)) << 32;
     2756  ret_val->mtime |= IVAL(file_header, 0xC);
    27572757  ret_val->major_version = IVAL(file_header, 0x14);
    27582758  ret_val->minor_version = IVAL(file_header, 0x18);
     
    29362936  }
    29372937
    2938   ret_val->mtime.low = IVAL(nk_header, 0x4);
    2939   ret_val->mtime.high = IVAL(nk_header, 0x8);
     2938  ret_val->mtime = ((uint64_t)IVAL(nk_header, 0x8)) << 32;
     2939  ret_val->mtime |= IVAL(nk_header, 0x4);
    29402940  /* If the key is unallocated and the MTIME is earlier than Jan 1, 1990
    29412941   * or later than Jan 1, 2290, we consider this a bad key.  This helps
     
    29432943   */
    29442944  if(unalloc
    2945      && (ret_val->mtime.high < REGFI_MTIME_MIN_HIGH
    2946          || ret_val->mtime.high > REGFI_MTIME_MAX_HIGH))
     2945     && (ret_val->mtime < REGFI_MTIME_MIN
     2946         || ret_val->mtime > REGFI_MTIME_MAX))
    29472947  { goto fail_locked; }
    29482948
     
    37943794
    37953795/****************************************************************************
    3796  Put a 8 byte filetime from a time_t
     3796 Returns an 8 byte filetime from a time_t
    37973797 This takes real GMT as input and converts to kludge-GMT
    37983798****************************************************************************/
    3799 void regfi_unix2nt_time(REGFI_NTTIME *nt, time_t t)
     3799REGFI_NTTIME regfi_unix2nt_time(time_t t)
    38003800{
    38013801  double d;
    3802  
    3803   if (t==0)
    3804   {
    3805     nt->low = 0;
    3806     nt->high = 0;
    3807     return;
    3808   }
     3802
     3803  if (t==0)
     3804    return 0L;
    38093805 
    38103806  if (t == TIME_T_MAX)
    3811   {
    3812     nt->low = 0xffffffff;
    3813     nt->high = 0x7fffffff;
    3814     return;
    3815   }             
     3807    return 0x7fffffffffffffffL;
    38163808 
    38173809  if (t == -1)
    3818   {
    3819     nt->low = 0xffffffff;
    3820     nt->high = 0xffffffff;
    3821     return;
    3822   }             
     3810    return 0xffffffffffffffffL;
    38233811 
    38243812  /* this converts GMT to kludge-GMT */
     
    38293817  /* t -= TimeDiff(t) - get_serverzone(); */
    38303818 
    3831   d = (double)(t);
    3832   d += TIME_FIXUP_CONSTANT;
     3819  d = (double)(t) + REGFI_TIME_FIXUP;
    38333820  d *= 1.0e7;
    3834  
    3835   nt->high = (uint32_t)(d * (1.0/(4.0*(double)(1<<30))));
    3836   nt->low  = (uint32_t)(d - ((double)nt->high)*4.0*(double)(1<<30));
     3821  /*
     3822  nt->high = (uint32_t)(d * (1.0/c));
     3823  nt->low  = (uint32_t)(d - ((double)nt->high) * c);
     3824  */
     3825
     3826  return (REGFI_NTTIME) d;
    38373827}
    38383828
     
    38493839 converts this to real GMT.
    38503840****************************************************************************/
    3851 double regfi_nt2unix_time(const REGFI_NTTIME* nt)
     3841double regfi_nt2unix_time(REGFI_NTTIME nt)
    38523842{
    38533843  double ret_val;
    3854 
    3855   /* The next two lines are a fix needed for the
    3856      broken SCO compiler. JRA. */
    3857   time_t l_time_min = TIME_T_MIN;
    3858   time_t l_time_max = TIME_T_MAX;
    3859  
    3860   if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff))
    3861     return(0);
    3862  
    3863   ret_val = ((double)nt->high)*4.0*(double)(1<<30);
    3864   ret_val += nt->low;
    3865   ret_val *= 1.0e-7;
     3844 
     3845  if (nt == 0 || nt == 0xffffffffffffffffL)
     3846    return 0;
     3847 
     3848  ret_val = (double)(nt) * 1.0e-7;
    38663849 
    38673850  /* now adjust by 369 years to make the secs since 1970 */
    3868   ret_val -= TIME_FIXUP_CONSTANT;
    3869  
    3870   /* XXX: should these sanity checks be removed? */
    3871   if (ret_val <= l_time_min)
    3872     return (l_time_min);
    3873  
    3874   if (ret_val >= l_time_max)
    3875     return (l_time_max);
     3851  ret_val -= REGFI_TIME_FIXUP;
    38763852 
    38773853  /* this takes us from kludge-GMT to real GMT */
Note: See TracChangeset for help on using the changeset viewer.