util.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * $Id: util.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
  3. *
  4. * Copyright (C) 1995,1996,1997 Lars Fenneberg
  5. *
  6. * Copyright 1992 Livingston Enterprises, Inc.
  7. *
  8. * Copyright 1992,1993, 1994,1995 The Regents of the University of Michigan
  9. * and Merit Network, Inc. All Rights Reserved
  10. *
  11. * See the file COPYRIGHT for the respective terms and conditions.
  12. * If the file is missing contact me at lf@elemental.net
  13. * and I'll send you a copy.
  14. *
  15. */
  16. #include <includes.h>
  17. #include <radiusclient.h>
  18. /*
  19. * Function: rc_str2tm
  20. *
  21. * Purpose: Turns printable string into correct tm struct entries.
  22. *
  23. */
  24. static const char * months[] =
  25. {
  26. "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  27. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  28. };
  29. void rc_str2tm (char *valstr, struct tm *tm)
  30. {
  31. int i;
  32. /* Get the month */
  33. for (i = 0; i < 12; i++)
  34. {
  35. if (strncmp (months[i], valstr, 3) == 0)
  36. {
  37. tm->tm_mon = i;
  38. i = 13;
  39. }
  40. }
  41. /* Get the Day */
  42. tm->tm_mday = atoi (&valstr[4]);
  43. /* Now the year */
  44. tm->tm_year = atoi (&valstr[7]) - 1900;
  45. }
  46. void rc_mdelay(int msecs)
  47. {
  48. struct timeval tv;
  49. tv.tv_sec = (int) msecs / 1000;
  50. tv.tv_usec = (msecs % 1000) * 1000;
  51. select(0,(fd_set *)NULL,(fd_set *)NULL,(fd_set *)NULL, &tv);
  52. }
  53. /*
  54. * Function: rc_mksid
  55. *
  56. * Purpose: generate a quite unique string
  57. *
  58. * Remarks: not that unique at all...
  59. *
  60. */
  61. char *
  62. rc_mksid (void)
  63. {
  64. static char buf[15];
  65. static unsigned short int cnt = 0;
  66. sprintf (buf, "%08lX%04X%02hX",
  67. (unsigned long int) time (NULL),
  68. (unsigned int) getpid (),
  69. cnt & 0xFF);
  70. cnt++;
  71. return buf;
  72. }