Back to index

glibc  2.9
Defines | Functions | Variables
ns_ttl.c File Reference
#include <arpa/nameser.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Defines

#define SPRINTF(x)   ((size_t)sprintf x)
#define T(x)   if ((x) < 0) return (-1); else (void)NULL

Functions

static int fmt1 (int t, char s, char **buf, size_t *buflen)
int ns_format_ttl (u_long src, char *dst, size_t dstlen)
 libresolv_hidden_def (ns_format_ttl)

Variables

static const char rcsid [] = "$BINDId: ns_ttl.c,v 8.8 1999/10/13 16:39:36 vixie Exp $"

Detailed Description

Definition in file ns_ttl.c.


Define Documentation

#define SPRINTF (   x)    ((size_t)sprintf x)

Definition at line 35 of file ns_ttl.c.

#define T (   x)    if ((x) < 0) return (-1); else (void)NULL

Definition at line 44 of file ns_ttl.c.


Function Documentation

static int fmt1 ( int  t,
char  s,
char **  buf,
size_t buflen 
) [static]

Definition at line 149 of file ns_ttl.c.

                                                {
       char tmp[50];
       size_t len;

       len = SPRINTF((tmp, "%d%c", t, s));
       if (len + 1 > *buflen)
              return (-1);
       strcpy(*buf, tmp);
       *buf += len;
       *buflen -= len;
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 92 of file ns_ttl.c.

                                           {
       u_long ttl, tmp;
       int ch, digits, dirty;

       ttl = 0;
       tmp = 0;
       digits = 0;
       dirty = 0;
       while ((ch = *src++) != '\0') {
              if (!isascii(ch) || !isprint(ch))
                     goto einval;
              if (isdigit(ch)) {
                     tmp *= 10;
                     tmp += (ch - '0');
                     digits++;
                     continue;
              }
              if (digits == 0)
                     goto einval;
              if (islower(ch))
                     ch = toupper(ch);
              switch (ch) {
              case 'W':  tmp *= 7;
              case 'D':  tmp *= 24;
              case 'H':  tmp *= 60;
              case 'M':  tmp *= 60;
              case 'S':  break;
              default:   goto einval;
              }
              ttl += tmp;
              tmp = 0;
              digits = 0;
              dirty = 1;
       }
       if (digits > 0) {
              if (dirty)
                     goto einval;
              else
                     ttl += tmp;
       } else if (!dirty)
              goto einval;
       *dst = ttl;
       return (0);

 einval:
       __set_errno (EINVAL);
       return (-1);
}

Here is the call graph for this function:

int ns_format_ttl ( u_long  src,
char *  dst,
size_t  dstlen 
)

Definition at line 49 of file ns_ttl.c.

                                                    {
       char *odst = dst;
       int secs, mins, hours, days, weeks, x;
       char *p;

       secs = src % 60;   src /= 60;
       mins = src % 60;   src /= 60;
       hours = src % 24;  src /= 24;
       days = src % 7;    src /= 7;
       weeks = src;       src = 0;

       x = 0;
       if (weeks) {
              T(fmt1(weeks, 'W', &dst, &dstlen));
              x++;
       }
       if (days) {
              T(fmt1(days, 'D', &dst, &dstlen));
              x++;
       }
       if (hours) {
              T(fmt1(hours, 'H', &dst, &dstlen));
              x++;
       }
       if (mins) {
              T(fmt1(mins, 'M', &dst, &dstlen));
              x++;
       }
       if (secs || !(weeks || days || hours || mins)) {
              T(fmt1(secs, 'S', &dst, &dstlen));
              x++;
       }

       if (x > 1) {
              int ch;

              for (p = odst; (ch = *p) != '\0'; p++)
                     if (isascii(ch) && isupper(ch))
                            *p = tolower(ch);
       }

       return (dst - odst);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char rcsid[] = "$BINDId: ns_ttl.c,v 8.8 1999/10/13 16:39:36 vixie Exp $" [static]

Definition at line 20 of file ns_ttl.c.