Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/lib/time.c

    r478 r740  
    3737#endif
    3838
    39 /*******************************************************************
    40   create a 16 bit dos packed date
    41 ********************************************************************/
    42 static uint16_t make_dos_date1(struct tm *t)
    43 {
    44         uint16_t ret=0;
    45         ret = (((unsigned int)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1);
    46         ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5));
    47         return ret;
    48 }
    49 
    50 /*******************************************************************
    51   create a 16 bit dos packed time
    52 ********************************************************************/
    53 static uint16_t make_dos_time1(struct tm *t)
    54 {
    55         uint16_t ret=0;
    56         ret = ((((unsigned int)t->tm_min >> 3)&0x7) | (((unsigned int)t->tm_hour) << 3));
    57         ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5));
    58         return ret;
    59 }
    60 
    61 /*******************************************************************
    62   create a 32 bit dos packed date/time from some parameters
    63   This takes a GMT time and returns a packed localtime structure
    64 ********************************************************************/
    65 static uint32_t make_dos_date(time_t unixdate, int zone_offset)
    66 {
    67         struct tm *t;
    68         uint32_t ret=0;
    69 
    70         if (unixdate == 0) {
    71                 return 0;
    72         }
    73 
    74         unixdate -= zone_offset;
    75 
    76         t = gmtime(&unixdate);
    77         if (!t) {
    78                 return 0xFFFFFFFF;
    79         }
    80 
    81         ret = make_dos_date1(t);
    82         ret = ((ret&0xFFFF)<<16) | make_dos_time1(t);
    83 
    84         return ret;
    85 }
    8639
    8740/**
     
    9851**************************************************************/
    9952
    100 uint32_t convert_time_t_to_uint32(time_t t)
     53uint32_t convert_time_t_to_uint32_t(time_t t)
    10154{
    10255#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8))
     
    11164}
    11265
    113 time_t convert_uint32_to_time_t(uint32_t u)
     66time_t convert_uint32_t_to_time_t(uint32_t u)
    11467{
    11568#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8))
     
    177130}
    178131
    179 /****************************************************************************
    180  Return the date and time as a string
    181 ****************************************************************************/
    182 
    183 char *timeval_string(TALLOC_CTX *ctx, const struct timeval *tp, bool hires)
    184 {
    185         fstring TimeBuf;
    186         time_t t;
    187         struct tm *tm;
    188 
    189         t = (time_t)tp->tv_sec;
    190         tm = localtime(&t);
    191         if (!tm) {
    192                 if (hires) {
    193                         slprintf(TimeBuf,
    194                                  sizeof(TimeBuf)-1,
    195                                  "%ld.%06ld seconds since the Epoch",
    196                                  (long)tp->tv_sec,
    197                                  (long)tp->tv_usec);
    198                 } else {
    199                         slprintf(TimeBuf,
    200                                  sizeof(TimeBuf)-1,
    201                                  "%ld seconds since the Epoch",
    202                                  (long)t);
    203                 }
    204         } else {
    205 #ifdef HAVE_STRFTIME
    206                 if (hires) {
    207                         strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
    208                         slprintf(TimeBuf+strlen(TimeBuf),
    209                                  sizeof(TimeBuf)-1 - strlen(TimeBuf),
    210                                  ".%06ld",
    211                                  (long)tp->tv_usec);
    212                 } else {
    213                         strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
    214                 }
    215 #else
    216                 if (hires) {
    217                         const char *asct = asctime(tm);
    218                         slprintf(TimeBuf,
    219                                  sizeof(TimeBuf)-1,
    220                                  "%s.%06ld",
    221                                  asct ? asct : "unknown",
    222                                  (long)tp->tv_usec);
    223                 } else {
    224                         const char *asct = asctime(tm);
    225                         fstrcpy(TimeBuf, asct ? asct : "unknown");
    226                 }
    227 #endif
    228         }
    229         return talloc_strdup(ctx, TimeBuf);
    230 }
    231 
    232 char *current_timestring(TALLOC_CTX *ctx, bool hires)
    233 {
    234         struct timeval tv;
    235 
    236         GetTimeOfDay(&tv);
    237         return timeval_string(ctx, &tv, hires);
    238 }
    239 
    240 /*******************************************************************
    241  Put a dos date into a buffer (time/date format).
    242  This takes GMT time and puts local time in the buffer.
    243 ********************************************************************/
    244 
    245 static void put_dos_date(char *buf,int offset,time_t unixdate, int zone_offset)
    246 {
    247         uint32_t x = make_dos_date(unixdate, zone_offset);
    248         SIVAL(buf,offset,x);
    249 }
    250 
    251 /*******************************************************************
    252  Put a dos date into a buffer (date/time format).
    253  This takes GMT time and puts local time in the buffer.
    254 ********************************************************************/
    255 
    256 static void put_dos_date2(char *buf,int offset,time_t unixdate, int zone_offset)
    257 {
    258         uint32_t x = make_dos_date(unixdate, zone_offset);
    259         x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
    260         SIVAL(buf,offset,x);
    261 }
    262 
    263 /*******************************************************************
    264  Put a dos 32 bit "unix like" date into a buffer. This routine takes
    265  GMT and converts it to LOCAL time before putting it (most SMBs assume
    266  localtime for this sort of date)
    267 ********************************************************************/
    268 
    269 static void put_dos_date3(char *buf,int offset,time_t unixdate, int zone_offset)
    270 {
    271         if (!null_mtime(unixdate)) {
    272                 unixdate -= zone_offset;
    273         }
    274         SIVAL(buf,offset,unixdate);
    275 }
    276 
    277 
    278132/***************************************************************************
    279133 Server versions of the above functions.
     
    282136void srv_put_dos_date(char *buf,int offset,time_t unixdate)
    283137{
    284         put_dos_date(buf, offset, unixdate, server_zone_offset);
     138        push_dos_date((uint8_t *)buf, offset, unixdate, server_zone_offset);
    285139}
    286140
    287141void srv_put_dos_date2(char *buf,int offset, time_t unixdate)
    288142{
    289         put_dos_date2(buf, offset, unixdate, server_zone_offset);
     143        push_dos_date2((uint8_t *)buf, offset, unixdate, server_zone_offset);
    290144}
    291145
    292146void srv_put_dos_date3(char *buf,int offset,time_t unixdate)
    293147{
    294         put_dos_date3(buf, offset, unixdate, server_zone_offset);
     148        push_dos_date3((uint8_t *)buf, offset, unixdate, server_zone_offset);
    295149}
    296150
     
    343197********************************************************************/
    344198
    345 static time_t make_unix_date(const void *date_ptr, int zone_offset)
     199time_t make_unix_date(const void *date_ptr, int zone_offset)
    346200{
    347201        uint32_t dos_date=0;
     
    389243{
    390244        time_t t = (time_t)IVAL(date_ptr,0);
    391         if (!null_mtime(t)) {
     245        if (!null_time(t)) {
    392246                t += zone_offset;
    393247        }
     
    440294struct timespec timespec_current(void)
    441295{
    442         struct timeval tv;
    443296        struct timespec ts;
    444         GetTimeOfDay(&tv);
    445         ts.tv_sec = tv.tv_sec;
    446         ts.tv_nsec = tv.tv_usec * 1000;
     297        clock_gettime(CLOCK_REALTIME, &ts);
    447298        return ts;
    448299}
     
    496347        struct timeval tv = convert_timespec_to_timeval(*ts);
    497348        *ts = convert_timeval_to_timespec(tv);
     349        while (ts->tv_nsec > 1000000000) {
     350                ts->tv_sec += 1;
     351                ts->tv_nsec -= 1000000000;
     352        }
    498353}
    499354
     
    517372}
    518373
    519 /***************************************************************************
    520  Client versions of the above functions.
    521 ***************************************************************************/
    522 
    523 void cli_put_dos_date(struct cli_state *cli, char *buf, int offset, time_t unixdate)
    524 {
    525         put_dos_date(buf, offset, unixdate, cli->serverzone);
    526 }
    527 
    528 void cli_put_dos_date2(struct cli_state *cli, char *buf, int offset, time_t unixdate)
    529 {
    530         put_dos_date2(buf, offset, unixdate, cli->serverzone);
    531 }
    532 
    533 void cli_put_dos_date3(struct cli_state *cli, char *buf, int offset, time_t unixdate)
    534 {
    535         put_dos_date3(buf, offset, unixdate, cli->serverzone);
    536 }
    537 
    538 time_t cli_make_unix_date(struct cli_state *cli, const void *date_ptr)
    539 {
    540         return make_unix_date(date_ptr, cli->serverzone);
    541 }
    542 
    543 time_t cli_make_unix_date2(struct cli_state *cli, const void *date_ptr)
    544 {
    545         return make_unix_date2(date_ptr, cli->serverzone);
    546 }
    547 
    548 time_t cli_make_unix_date3(struct cli_state *cli, const void *date_ptr)
    549 {
    550         return make_unix_date3(date_ptr, cli->serverzone);
    551 }
    552 
    553 /****************************************************************************
    554  Check if two NTTIMEs are the same.
    555 ****************************************************************************/
    556 
    557 bool nt_time_equals(const NTTIME *nt1, const NTTIME *nt2)
    558 {
    559         return (*nt1 == *nt2);
    560 }
    561 
    562374/*******************************************************************
    563375 Re-read the smb serverzone value.
     
    598410}
    599411
     412/**
     413 * @brief Get the startup time of the server.
     414 *
     415 * @param[out] ret_time A pointer to a timveal structure to set the startup
     416 *                      time.
     417 */
     418void get_startup_time(struct timeval *ret_time)
     419{
     420        ret_time->tv_sec = start_time_hires.tv_sec;
     421        ret_time->tv_usec = start_time_hires.tv_usec;
     422}
     423
     424
    600425/****************************************************************************
    601426 Convert a NTTIME structure to a time_t.
     
    740565
    741566/****************************************************************************
    742  Check if it's a null mtime.
    743 ****************************************************************************/
    744 
    745 bool null_mtime(time_t mtime)
    746 {
    747         if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1)
    748                 return true;
    749         return false;
    750 }
    751 
    752 /****************************************************************************
    753567 Utility function that always returns a const string even if localtime
    754568 and asctime fail.
Note: See TracChangeset for help on using the changeset viewer.