summaryrefslogtreecommitdiff
path: root/src/libstddjb/ip4_fmt.c
blob: 441df5a571b8ea57c7dc0adce919f21d67bc7884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* ISC license. */

#include <skalibs/uint32.h>
#include <skalibs/fmtscan.h>

size_t ip4_fmt (char *s, char const *ip)
{
  size_t len = 0 ;
  unsigned int j = 0 ;
  for (; j < 4 ; j++)
  {
    size_t i = uint32_fmt(s, (unsigned char)ip[j]) ;
    len += i ;
    if (s) s += i ;
    if (j == 3) break ;
    if (s) *s++ = '.' ;
    ++len ;
  }
  return len ;
}