xmlread.c.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. xmlread.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='xmlopen.c.html' title=' xmlopen.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='xmlscan.c.html' title=' xmlscan.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * NODE * xmlread (NODE * node, char const * filename);
  24. *
  25. * node.h
  26. *
  27. * open an XML file and return the parse tree root;
  28. *
  29. * the entire file is read into a buffer associated with the text
  30. * member in the root node; the buffer is then split into strings
  31. * referenced by child nodes, forming a hierarchial string vector;
  32. *
  33. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  34. * Copyright (c) 2001-2006 by Charles Maier Associates;
  35. * Licensed under the Internet Software Consortium License;
  36. *
  37. *--------------------------------------------------------------------*/
  38. #ifndef XMLREAD_SOURCE
  39. #define XMLREAD_SOURCE
  40. #include &lt;unistd.h&gt;
  41. #include &lt;stdlib.h&gt;
  42. #include &lt;sys/stat.h&gt;
  43. #include &lt;memory.h&gt;
  44. #include &lt;fcntl.h&gt;
  45. #include &lt;errno.h&gt;
  46. #include &quot;../tools/error.h&quot;
  47. #include &quot;../tools/files.h&quot;
  48. #include &quot;../nodes/node.h&quot;
  49. signed xmlread (NODE * node, char const * filename)
  50. {
  51. struct stat stat;
  52. signed fd;
  53. memset (node, 0, sizeof (NODE));
  54. if (lstat (filename, &amp;stat))
  55. {
  56. error (1, errno, FILE_CANTSTAT, filename);
  57. }
  58. if (!(node-&gt;text = malloc (stat.st_size + 1)))
  59. {
  60. error (1, errno, FILE_CANTLOAD, filename);
  61. }
  62. if ((fd = open (filename, O_BINARY|O_RDONLY)) == -1)
  63. {
  64. error (1, errno, FILE_CANTOPEN, filename);
  65. }
  66. if (read (fd, node-&gt;text, stat.st_size) != stat.st_size)
  67. {
  68. error (1, errno, FILE_CANTREAD, filename);
  69. }
  70. node-&gt;text [stat.st_size] = (char)(0);
  71. close (fd);
  72. return (0);
  73. }
  74. #endif
  75. </pre>
  76. <div class='footerlink'>
  77. [<a href='xmlopen.c.html' title=' xmlopen.c '>PREV</a>]
  78. [<a href='toolkit.html' title=' Index '>HOME</a>]
  79. [<a href='xmlscan.c.html' title=' xmlscan.c '>NEXT</a>]
  80. </div>
  81. </body>
  82. </html>