[BACK]Return to rcstime.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rcs

Annotation of src/usr.bin/rcs/rcstime.c, Revision 1.3

1.3     ! xsa         1: /*     $OpenBSD: rcstime.c,v 1.2 2006/05/29 03:00:12 niallo Exp $      */
1.1       joris       2: /*
                      3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. The name of the author may not be used to endorse or promote products
                     13:  *    derived from this software without specific prior written permission.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     16:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     17:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
                     18:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     19:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     20:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     21:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     22:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     23:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26:
1.3     ! xsa        27: #include <err.h>
        !            28: #include <stdlib.h>
        !            29: #include <string.h>
1.1       joris      30:
                     31: #include "rcs.h"
                     32:
                     33: void
                     34: rcs_set_tz(char *tz, struct rcs_delta *rdp, struct tm *tb)
                     35: {
                     36:        int tzone;
                     37:        int pos;
                     38:        char *h, *m;
                     39:        struct tm *ltb;
                     40:        time_t now;
                     41:
                     42:        if (!strcmp(tz, "LT")) {
                     43:                now = mktime(&rdp->rd_date);
                     44:                ltb = localtime(&now);
                     45:                ltb->tm_hour += ((int)ltb->tm_gmtoff/3600);
1.2       niallo     46:                memcpy(tb, ltb, sizeof(*tb));
1.1       joris      47:        } else {
                     48:                pos = 0;
                     49:                switch (*tz) {
                     50:                case '-':
                     51:                        break;
                     52:                case '+':
                     53:                        pos = 1;
                     54:                        break;
                     55:                default:
                     56:                        errx(1, "%s: not a known time zone", tz);
                     57:                }
                     58:
                     59:                h = (tz + 1);
                     60:                if ((m = strrchr(tz, ':')) != NULL)
                     61:                        *(m++) = '\0';
                     62:
1.2       niallo     63:                memcpy(tb, &rdp->rd_date, sizeof(*tb));
1.1       joris      64:
                     65:                tzone = atoi(h);
                     66:                if ((tzone >= 24) && (tzone <= -24))
                     67:                        errx(1, "%s: not a known time zone", tz);
                     68:
                     69:                if (pos) {
                     70:                        tb->tm_hour += tzone;
                     71:                        tb->tm_gmtoff += (tzone * 3600);
                     72:                } else {
                     73:                        tb->tm_hour -= tzone;
                     74:                        tb->tm_gmtoff -= (tzone * 3600);
                     75:                }
                     76:
                     77:                if ((tb->tm_hour >= 24) || (tb->tm_hour <= -24))
                     78:                        tb->tm_hour = 0;
                     79:
                     80:                if (m != NULL) {
                     81:                        tzone = atoi(m);
                     82:                        if (tzone >= 60)
                     83:                                errx(1, "%s: not a known time zone", tz);
                     84:
                     85:                        if ((tb->tm_min + tzone) >= 60) {
                     86:                                tb->tm_hour++;
                     87:                                tb->tm_min -= (60 - tzone);
                     88:                        } else
                     89:                                tb->tm_min += tzone;
                     90:
                     91:                        tb->tm_gmtoff += (tzone*60);
                     92:                }
                     93:        }
                     94: }