OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [net/] [ns_ttl.c] - Diff between revs 148 and 158

Only display areas with differences | Details | Blame | View Log

Rev 148 Rev 158
/*
/*
 * Copyright (c) 1996,1999 by Internet Software Consortium.
 * Copyright (c) 1996,1999 by Internet Software Consortium.
 *
 *
 * Permission to use, copy, modify, and distribute this software for any
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * copyright notice and this permission notice appear in all copies.
 *
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 * SOFTWARE.
 */
 */
 
 
#if !defined(_LIBC) && !defined(lint)
#if !defined(_LIBC) && !defined(lint)
static const char rcsid[] = "$BINDId: ns_ttl.c,v 8.8 1999/10/13 16:39:36 vixie Exp $";
static const char rcsid[] = "$BINDId: ns_ttl.c,v 8.8 1999/10/13 16:39:36 vixie Exp $";
#endif
#endif
 
 
/* Import. */
/* Import. */
 
 
#include <arpa/nameser.h>
#include <arpa/nameser.h>
 
 
#include <ctype.h>
#include <ctype.h>
#include <errno.h>
#include <errno.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
 
 
#include "libc-symbols.h"
#include "libc-symbols.h"
 
 
#ifdef SPRINTF_CHAR
#ifdef SPRINTF_CHAR
# define SPRINTF(x) strlen(sprintf/**/x)
# define SPRINTF(x) strlen(sprintf/**/x)
#else
#else
# define SPRINTF(x) ((size_t)sprintf x)
# define SPRINTF(x) ((size_t)sprintf x)
#endif
#endif
 
 
/* Forward. */
/* Forward. */
 
 
static int      fmt1(int t, char s, char **buf, size_t *buflen);
static int      fmt1(int t, char s, char **buf, size_t *buflen);
 
 
/* Macros. */
/* Macros. */
 
 
#define T(x) if ((x) < 0) return (-1); else (void)NULL
#define T(x) if ((x) < 0) return (-1); else (void)NULL
 
 
/* Public. */
/* Public. */
 
 
int
int
ns_format_ttl(u_long src, char *dst, size_t dstlen) {
ns_format_ttl(u_long src, char *dst, size_t dstlen) {
        char *odst = dst;
        char *odst = dst;
        int secs, mins, hours, days, weeks, x;
        int secs, mins, hours, days, weeks, x;
        char *p;
        char *p;
 
 
        secs = src % 60;   src /= 60;
        secs = src % 60;   src /= 60;
        mins = src % 60;   src /= 60;
        mins = src % 60;   src /= 60;
        hours = src % 24;  src /= 24;
        hours = src % 24;  src /= 24;
        days = src % 7;    src /= 7;
        days = src % 7;    src /= 7;
        weeks = src;       src = 0;
        weeks = src;       src = 0;
 
 
        x = 0;
        x = 0;
        if (weeks) {
        if (weeks) {
                T(fmt1(weeks, 'W', &dst, &dstlen));
                T(fmt1(weeks, 'W', &dst, &dstlen));
                x++;
                x++;
        }
        }
        if (days) {
        if (days) {
                T(fmt1(days, 'D', &dst, &dstlen));
                T(fmt1(days, 'D', &dst, &dstlen));
                x++;
                x++;
        }
        }
        if (hours) {
        if (hours) {
                T(fmt1(hours, 'H', &dst, &dstlen));
                T(fmt1(hours, 'H', &dst, &dstlen));
                x++;
                x++;
        }
        }
        if (mins) {
        if (mins) {
                T(fmt1(mins, 'M', &dst, &dstlen));
                T(fmt1(mins, 'M', &dst, &dstlen));
                x++;
                x++;
        }
        }
        if (secs || !(weeks || days || hours || mins)) {
        if (secs || !(weeks || days || hours || mins)) {
                T(fmt1(secs, 'S', &dst, &dstlen));
                T(fmt1(secs, 'S', &dst, &dstlen));
                x++;
                x++;
        }
        }
 
 
        if (x > 1) {
        if (x > 1) {
                int ch;
                int ch;
 
 
                for (p = odst; (ch = *p) != '\0'; p++)
                for (p = odst; (ch = *p) != '\0'; p++)
                        if (isascii(ch) && isupper(ch))
                        if (isascii(ch) && isupper(ch))
                                *p = tolower(ch);
                                *p = tolower(ch);
        }
        }
 
 
        return (dst - odst);
        return (dst - odst);
}
}
 
 
#ifndef SHARED
#ifndef SHARED
// Seems not to be needed.  It's not exported from the DSO.  Some libresolv.a
// Seems not to be needed.  It's not exported from the DSO.  Some libresolv.a
// might depend on it so we let it in.
// might depend on it so we let it in.
int
int
ns_parse_ttl(const char *src, u_long *dst) {
ns_parse_ttl(const char *src, u_long *dst) {
        u_long ttl, tmp;
        u_long ttl, tmp;
        int ch, digits, dirty;
        int ch, digits, dirty;
 
 
        ttl = 0;
        ttl = 0;
        tmp = 0;
        tmp = 0;
        digits = 0;
        digits = 0;
        dirty = 0;
        dirty = 0;
        while ((ch = *src++) != '\0') {
        while ((ch = *src++) != '\0') {
                if (!isascii(ch) || !isprint(ch))
                if (!isascii(ch) || !isprint(ch))
                        goto einval;
                        goto einval;
                if (isdigit(ch)) {
                if (isdigit(ch)) {
                        tmp *= 10;
                        tmp *= 10;
                        tmp += (ch - '0');
                        tmp += (ch - '0');
                        digits++;
                        digits++;
                        continue;
                        continue;
                }
                }
                if (digits == 0)
                if (digits == 0)
                        goto einval;
                        goto einval;
                if (islower(ch))
                if (islower(ch))
                        ch = toupper(ch);
                        ch = toupper(ch);
                switch (ch) {
                switch (ch) {
                case 'W':  tmp *= 7;
                case 'W':  tmp *= 7;
                case 'D':  tmp *= 24;
                case 'D':  tmp *= 24;
                case 'H':  tmp *= 60;
                case 'H':  tmp *= 60;
                case 'M':  tmp *= 60;
                case 'M':  tmp *= 60;
                case 'S':  break;
                case 'S':  break;
                default:   goto einval;
                default:   goto einval;
                }
                }
                ttl += tmp;
                ttl += tmp;
                tmp = 0;
                tmp = 0;
                digits = 0;
                digits = 0;
                dirty = 1;
                dirty = 1;
        }
        }
        if (digits > 0) {
        if (digits > 0) {
                if (dirty)
                if (dirty)
                        goto einval;
                        goto einval;
                else
                else
                        ttl += tmp;
                        ttl += tmp;
        }
        }
        *dst = ttl;
        *dst = ttl;
        return (0);
        return (0);
 
 
 einval:
 einval:
        __set_errno (EINVAL);
        __set_errno (EINVAL);
        return (-1);
        return (-1);
}
}
#endif
#endif
 
 
/* Private. */
/* Private. */
 
 
static int
static int
fmt1(int t, char s, char **buf, size_t *buflen) {
fmt1(int t, char s, char **buf, size_t *buflen) {
        char tmp[50];
        char tmp[50];
        size_t len;
        size_t len;
 
 
        len = SPRINTF((tmp, "%d%c", t, s));
        len = SPRINTF((tmp, "%d%c", t, s));
        if (len + 1 > *buflen)
        if (len + 1 > *buflen)
                return (-1);
                return (-1);
        strcpy(*buf, tmp);
        strcpy(*buf, tmp);
        *buf += len;
        *buf += len;
        *buflen -= len;
        *buflen -= len;
        return (0);
        return (0);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.