dataspec.c.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. dataspec.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='coqos_rel.c.html' title=' coqos_rel.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='debug.c.html' title=' debug.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * size_t dataspec (char const * string, void * memory, size_t extent);
  24. *
  25. * memory.h
  26. *
  27. * encode a memory region with a variable-length hexadecimal string;
  28. * return the number of bytes encoded or terminate the program on
  29. * error;
  30. *
  31. * the number of octets in string must equal the memory extent or
  32. * an error will occur; octets may be seperated by semi-colons;
  33. * empty octets are illegal;
  34. *
  35. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  36. * Copyright (c) 2001-2006 by Charles Maier Associates;
  37. * Licensed under the Internet Software Consortium License;
  38. *
  39. *--------------------------------------------------------------------*/
  40. #ifndef DATASPEC_SOURCE
  41. #define DATASPEC_SOURCE
  42. #include &lt;ctype.h&gt;
  43. #include &lt;errno.h&gt;
  44. #include &quot;../tools/memory.h&quot;
  45. #include &quot;../tools/number.h&quot;
  46. #include &quot;../tools/error.h&quot;
  47. size_t dataspec (char const * string, void * memory, size_t extent)
  48. {
  49. char const * number = string;
  50. byte * origin = (byte *)(memory);
  51. byte * offset = (byte *)(memory);
  52. if (!number)
  53. {
  54. error (1, EFAULT, &quot;dataspec&quot;);
  55. }
  56. #ifdef WIN32
  57. while (isspace (*number))
  58. {
  59. number++;
  60. }
  61. #endif
  62. while ((*number) &amp;&amp; (extent))
  63. {
  64. unsigned digit = 0;
  65. #ifdef WIN32
  66. if (isspace (*number))
  67. {
  68. break;
  69. }
  70. #endif
  71. if ((offset &gt; origin) &amp;&amp; (*number == HEX_EXTENDER))
  72. {
  73. number++;
  74. }
  75. if ((digit = todigit (*number++)) &gt;= RADIX_HEX)
  76. {
  77. error (1, EINVAL, &quot;You said '%s' but I want a hex digit&quot;, string);
  78. }
  79. *offset = digit &lt;&lt; 4;
  80. if (!*number)
  81. {
  82. error (1, EINVAL, &quot;You said '%s' but I want another hex digit&quot;, string);
  83. }
  84. if ((digit = todigit (*number++)) &gt;= 0x10)
  85. {
  86. error (1, EINVAL, &quot;You said '%s' but I want valid hex data&quot;, string);
  87. }
  88. *offset |= digit;
  89. offset++;
  90. extent--;
  91. }
  92. #ifdef WIN32
  93. while (isspace (*number))
  94. {
  95. number++;
  96. }
  97. #endif
  98. if (*number &amp;&amp; !extent)
  99. {
  100. error (1, EINVAL, &quot;'%s' exceeds %d bytes&quot;, string, (unsigned)(offset - origin - extent));
  101. }
  102. if (*number)
  103. {
  104. error (1, EINVAL, &quot;String '%s' contains trash&quot;, string);
  105. }
  106. return (offset - origin);
  107. }
  108. #endif
  109. </pre>
  110. <div class='footerlink'>
  111. [<a href='coqos_rel.c.html' title=' coqos_rel.c '>PREV</a>]
  112. [<a href='toolkit.html' title=' Index '>HOME</a>]
  113. [<a href='debug.c.html' title=' debug.c '>NEXT</a>]
  114. </div>
  115. </body>
  116. </html>