Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/time localtime.c: take indentation style from upstream



details:   https://anonhg.NetBSD.org/src/rev/a0651927b3b4
branches:  trunk
changeset: 364445:a0651927b3b4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Mar 25 19:00:15 2022 +0000

description:
localtime.c: take indentation style from upstream

This reduces the diff to upstream.

No binary change.

diffstat:

 lib/libc/time/localtime.c |  477 ++++++++++++++++++++++-----------------------
 1 files changed, 236 insertions(+), 241 deletions(-)

diffs (truncated from 877 to 300 lines):

diff -r ede21f08823d -r a0651927b3b4 lib/libc/time/localtime.c
--- a/lib/libc/time/localtime.c Fri Mar 25 18:35:50 2022 +0000
+++ b/lib/libc/time/localtime.c Fri Mar 25 19:00:15 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: localtime.c,v 1.130 2022/03/25 18:35:50 rillig Exp $   */
+/*     $NetBSD: localtime.c,v 1.131 2022/03/25 19:00:15 rillig Exp $   */
 
 /* Convert timestamp from time_t to struct tm.  */
 
@@ -12,7 +12,7 @@
 #if 0
 static char    elsieid[] = "@(#)localtime.c    8.17";
 #else
-__RCSID("$NetBSD: localtime.c,v 1.130 2022/03/25 18:35:50 rillig Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.131 2022/03/25 19:00:15 rillig Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -238,11 +238,11 @@
 static void
 init_ttinfo(struct ttinfo *s, int_fast32_t utoff, bool isdst, int desigidx)
 {
-       s->tt_utoff = utoff;
-       s->tt_isdst = isdst;
-       s->tt_desigidx = desigidx;
-       s->tt_ttisstd = false;
-       s->tt_ttisut = false;
+  s->tt_utoff = utoff;
+  s->tt_isdst = isdst;
+  s->tt_desigidx = desigidx;
+  s->tt_ttisstd = false;
+  s->tt_ttisut = false;
 }
 
 /* Return true if SP's time type I does not specify local time.  */
@@ -271,10 +271,10 @@
        if (codep[0] & 0x80) {
          /* Do two's-complement negation even on non-two's-complement machines.
             If the result would be minval - 1, return minval.  */
-           result -= !TWOS_COMPLEMENT(int_fast32_t) && result != 0;
-           result += minval;
+         result -= !TWOS_COMPLEMENT(int_fast32_t) && result != 0;
+         result += minval;
        }
-       return result;
+       return result;
 }
 
 static int_fast64_t
@@ -297,7 +297,7 @@
          result -= !TWOS_COMPLEMENT(int_fast64_t) && result != 0;
          result += minval;
        }
-       return result;
+       return result;
 }
 
 #include <stdio.h>
@@ -339,15 +339,15 @@
 update_tzname_etc(const struct state *sp, const struct ttinfo *ttisp)
 {
 #if HAVE_TZNAME
-       tzname[ttisp->tt_isdst] = __UNCONST(&sp->chars[ttisp->tt_desigidx]);
+  tzname[ttisp->tt_isdst] = __UNCONST(&sp->chars[ttisp->tt_desigidx]);
 #endif
 #if USG_COMPAT
-       if (!ttisp->tt_isdst)
-               timezone = - ttisp->tt_utoff;
+  if (!ttisp->tt_isdst)
+    timezone = - ttisp->tt_utoff;
 #endif
 #if ALTZONE
-       if (ttisp->tt_isdst)
-           altzone = - ttisp->tt_utoff;
+  if (ttisp->tt_isdst)
+    altzone = - ttisp->tt_utoff;
 #endif /* ALTZONE */
 }
 
@@ -414,12 +414,12 @@
 
 /* Input buffer for data read from a compiled tz file.  */
 union input_buffer {
-       /* The first part of the buffer, interpreted as a header.  */
-       struct tzhead tzhead;
+  /* The first part of the buffer, interpreted as a header.  */
+  struct tzhead tzhead;
 
-       /* The entire buffer.  */
-       char buf[2 * sizeof(struct tzhead) + 2 * sizeof(struct state)
-         + 4 * TZ_MAX_TIMES];
+  /* The entire buffer.  */
+  char buf[2 * sizeof(struct tzhead) + 2 * sizeof(struct state)
+          + 4 * TZ_MAX_TIMES];
 };
 
 /* TZDIR with a trailing '/' rather than a trailing '\0'.  */
@@ -427,18 +427,18 @@
 
 /* Local storage needed for 'tzloadbody'.  */
 union local_storage {
-       /* The results of analyzing the file's contents after it is opened.  */
-       struct file_analysis {
-               /* The input buffer.  */
-               union input_buffer u;
+  /* The results of analyzing the file's contents after it is opened.  */
+  struct file_analysis {
+    /* The input buffer.  */
+    union input_buffer u;
 
-               /* A temporary state used for parsing a TZ string in the file.  */
-               struct state st;
-       } u;
+    /* A temporary state used for parsing a TZ string in the file.  */
+    struct state st;
+  } u;
 
-       /* The file name to be opened.  */
-       char fullname[/*CONSTCOND*/BIGGEST(sizeof(struct file_analysis),
-           sizeof tzdirslash + 1024)];
+  /* The file name to be opened.  */
+  char fullname[/*CONSTCOND*/BIGGEST(sizeof(struct file_analysis),
+                       sizeof tzdirslash + 1024)];
 };
 
 /* Load tz data from the file named NAME into *SP.  Read extended
@@ -446,7 +446,7 @@
    success, an errno value on failure.  */
 static int
 tzloadbody(char const *name, struct state *sp, bool doextend,
-  union local_storage *lsp)
+          union local_storage *lsp)
 {
        register int                    i;
        register int                    fid;
@@ -461,7 +461,7 @@
        if (! name) {
                name = TZDEFAULT;
                if (! name)
-                       return EINVAL;
+                 return EINVAL;
        }
 
        if (name[0] == ':')
@@ -477,7 +477,7 @@
                char const *dot;
                size_t namelen = strlen(name);
                if (sizeof lsp->fullname - sizeof tzdirslash <= namelen)
-                       return ENAMETOOLONG;
+                 return ENAMETOOLONG;
 
                /* Create a string "TZDIR/NAME".  Using sprintf here
                   would pull in stdio (and would fail if the
@@ -498,19 +498,19 @@
                name = lsp->fullname;
        }
        if (doaccess && access(name, R_OK) != 0)
-               return errno;
+         return errno;
        fid = open(name, OPEN_MODE);
        if (fid < 0)
-               return errno;
+         return errno;
 
        nread = read(fid, up->buf, sizeof up->buf);
        if (nread < (ssize_t)tzheadsize) {
-               int err = nread < 0 ? errno : EINVAL;
-               close(fid);
-               return err;
+         int err = nread < 0 ? errno : EINVAL;
+         close(fid);
+         return err;
        }
        if (close(fid) < 0)
-               return errno;
+         return errno;
        for (stored = 4; stored <= 8; stored *= 2) {
            char version = up->tzhead.tzh_version[0];
            bool skip_datablock = stored == 4 && version;
@@ -565,17 +565,16 @@
                          = stored == 4 ? detzcode(p) : detzcode64(p);
                        sp->types[i] = at <= TIME_T_MAX;
                        if (sp->types[i]) {
-                               time_t attime
-                                   = ((TYPE_SIGNED(time_t) ?
-                                   at < TIME_T_MIN : at < 0)
-                                   ? TIME_T_MIN : (time_t)at);
-                               if (timecnt && attime <= sp->ats[timecnt - 1]) {
-                                       if (attime < sp->ats[timecnt - 1])
-                                               return EINVAL;
-                                       sp->types[i - 1] = 0;
-                                       timecnt--;
-                               }
-                               sp->ats[timecnt++] = attime;
+                         time_t attime
+                           = ((TYPE_SIGNED(time_t) ? at < TIME_T_MIN : at < 0)
+                              ? TIME_T_MIN : (time_t)at);
+                         if (timecnt && attime <= sp->ats[timecnt - 1]) {
+                           if (attime < sp->ats[timecnt - 1])
+                             return EINVAL;
+                           sp->types[i - 1] = 0;
+                           timecnt--;
+                         }
+                         sp->ats[timecnt++] = attime;
                        }
                        p += stored;
                }
@@ -598,11 +597,11 @@
                        p += 4;
                        isdst = *p++;
                        if (! (isdst < 2))
-                               return EINVAL;
+                         return EINVAL;
                        ttisp->tt_isdst = isdst;
                        desigidx = *p++;
                        if (! (desigidx < sp->charcnt))
-                               return EINVAL;
+                         return EINVAL;
                        ttisp->tt_desigidx = desigidx;
                }
                for (i = 0; i < sp->charcnt; ++i)
@@ -614,35 +613,34 @@
                /* Read leap seconds, discarding those out of time_t range.  */
                leapcnt = 0;
                for (i = 0; i < sp->leapcnt; ++i) {
-                       int_fast64_t tr = stored == 4 ? detzcode(p) :
-                           detzcode64(p);
-                       int_fast32_t corr = detzcode(p + stored);
-                       p += stored + 4;
+                 int_fast64_t tr = stored == 4 ? detzcode(p) : detzcode64(p);
+                 int_fast32_t corr = detzcode(p + stored);
+                 p += stored + 4;
 
-                       /* Leap seconds cannot occur before the Epoch,
-                          or out of order.  */
-                       if (tr <= prevtr)
-                               return EINVAL;
+                 /* Leap seconds cannot occur before the Epoch,
+                    or out of order.  */
+                 if (tr <= prevtr)
+                   return EINVAL;
 
-                       /* To avoid other botches in this code, each leap second's
-                          correction must differ from the previous one's by 1
-                          second or less, except that the first correction can be
-                          any value; these requirements are more generous than
-                          RFC 8536, to allow future RFC extensions.  */
-                       if (! (i == 0
-                          || (prevcorr < corr
-                              ? corr == prevcorr + 1
-                              : (corr == prevcorr
-                                 || corr == prevcorr - 1))))
-                             return EINVAL;
-                       prevtr = tr;
-                       prevcorr = corr;
+                 /* To avoid other botches in this code, each leap second's
+                    correction must differ from the previous one's by 1
+                    second or less, except that the first correction can be
+                    any value; these requirements are more generous than
+                    RFC 8536, to allow future RFC extensions.  */
+                 if (! (i == 0
+                        || (prevcorr < corr
+                            ? corr == prevcorr + 1
+                            : (corr == prevcorr
+                               || corr == prevcorr - 1))))
+                   return EINVAL;
+                 prevtr = tr;
+                 prevcorr = corr;
 
-                       if (tr <= TIME_T_MAX) {
-                               sp->lsis[leapcnt].ls_trans = (time_t)tr;
-                               sp->lsis[leapcnt].ls_corr = corr;
-                               leapcnt++;
-                       }
+                 if (tr <= TIME_T_MAX) {
+                   sp->lsis[leapcnt].ls_trans = (time_t)tr;
+                   sp->lsis[leapcnt].ls_corr = corr;
+                   leapcnt++;
+                 }
                }
                sp->leapcnt = leapcnt;
 
@@ -682,7 +680,7 @@
        if (doextend && nread > 2 &&
                up->buf[0] == '\n' && up->buf[nread - 1] == '\n' &&
                sp->typecnt + 2 <= TZ_MAX_TYPES) {
-                       struct state *ts = &lsp->u.st;
+                       struct state    *ts = &lsp->u.st;
 
                        up->buf[nread - 1] = '\0';
                        if (tzparse(&up->buf[1], ts, sp)) {
@@ -830,14 +828,14 @@
 static int
 tzload(char const *name, struct state *sp, bool doextend)
 {
-       union local_storage *lsp = malloc(sizeof *lsp);
-       if (!lsp) {
-               return /*CONSTCOND*/HAVE_MALLOC_ERRNO ? errno : ENOMEM;
-       } else {
-               int err = tzloadbody(name, sp, doextend, lsp);



Home | Main Index | Thread Index | Old Index