

/*
 * util.c:
 *
 * Copyright (c) 2000 James McKenzie <james@fishsoup.dhs.org>.
 * All rights reserved.
 *
 * $Log: utils.c,v $
 * Revision 1.18  2001/10/12 13:51:11  root
 * #
 *
 * Revision 1.17  2001/01/30 06:16:17  root
 * #
 *
 * Revision 1.16  2000/12/01 04:42:09  root
 * #
 *
 * Revision 1.15  2000/12/01 04:13:41  root
 * #
 *
 * Revision 1.14  2000/10/07 18:30:02  root
 * #
 *
 * Revision 1.13  2000/10/06 19:52:17  root
 * #
 *
 * Revision 1.12  2000/09/24 01:57:55  root
 * #
 *
 * Revision 1.11  2000/09/24 01:57:53  root
 * #
 *
 * Revision 1.10  2000/09/24 01:57:40  root
 * #
 *
 * Revision 1.9  2000/09/24 01:48:12  root
 * #
 *
 * Revision 1.8  2000/09/24 01:46:04  root
 * #
 *
 * Revision 1.7  2000/09/24 01:12:46  root
 * #
 *
 * Revision 1.6  2000/02/21 04:11:26  root
 * #
 *
 * Revision 1.5  2000/02/21 04:01:01  root
 * #
 *
 * Revision 1.4  2000/02/21 02:53:46  root
 * #
 *
 * Revision 1.3  2000/02/21 00:49:53  root
 * #
 *
 * Revision 1.2  2000/02/20 18:22:59  root
 * #
 *
 * Revision 1.1  2000/02/20 14:07:12  root
 * #
 *
 *
 */

static char rcsid[] =
  "$Id: utils.c,v 1.18 2001/10/12 13:51:11 root Exp root $";

#include "hifimsg.h"
#include "hifimsg_private.h"

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/limits.h>
#include <sys/un.h>
#include <stdio.h>


void
hifimsg_dumpbytes (unsigned char *in, int len)
{

  printf ("%d bytes ", len);

  while (len--)
    {
      /*  if ((*in > 31) && (*in < 127))
         {
         putchar (*in);
         }
         else */
      {
        printf ("<%02x>", *in);
      }

      in++;
    }
}


void
hifimsg_moan (char *fmt, ...)
{
  va_list ap;
  va_start (ap, fmt);
  (void) vfprintf (stderr, fmt, ap);
  va_end (ap);
}

void
hifimsg_disinherit (void)
{
  int fd, max;

  fd = open ("/dev/tty", O_RDONLY);

  if (!fd)
    {
      ioctl (fd, TIOCNOTTY, 0);
      close (fd);
    }

  fd = open ("/dev/null", O_RDWR);

  dup2 (fd, 0);
  dup2 (fd, 1);
  dup2 (fd, 2);


  setsid ();

}

time_t hifimsg_timestamp ()
{
  time_t ret;
  time (&ret);
  return ret;
}
