summaryrefslogtreecommitdiff
path: root/examples/dom-structure-dump.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2011-12-22 10:49:34 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2011-12-22 10:49:34 +0000
commitea291a30ddaa177f9fd9ffe402bda293c5a6f121 (patch)
tree8e309abd5d1708182078a51893180e9257e50d62 /examples/dom-structure-dump.c
parent70d69c686d657be26c94e176b002f7f754d4cb19 (diff)
downloadlibdom-ea291a30ddaa177f9fd9ffe402bda293c5a6f121.tar.gz
libdom-ea291a30ddaa177f9fd9ffe402bda293c5a6f121.tar.bz2
Use ANSI functions for file handling.
svn path=/trunk/libdom/; revision=13323
Diffstat (limited to 'examples/dom-structure-dump.c')
-rw-r--r--examples/dom-structure-dump.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/examples/dom-structure-dump.c b/examples/dom-structure-dump.c
index 8850df2..020033a 100644
--- a/examples/dom-structure-dump.c
+++ b/examples/dom-structure-dump.c
@@ -35,14 +35,12 @@
*
*/
-#define _GNU_SOURCE /* for strndup */
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <fcntl.h>
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
@@ -71,9 +69,9 @@ void test_msg(uint32_t severity, void *ctx, const char *msg, ...)
*/
dom_document *create_doc_dom_from_file(char *file)
{
- const unsigned int buffer_size = 1024;
+ size_t buffer_size = 1024;
dom_hubbub_parser *parser = NULL;
- int handle;
+ FILE *handle;
int chunk_length;
dom_hubbub_error error;
dom_document *doc;
@@ -87,8 +85,8 @@ dom_document *create_doc_dom_from_file(char *file)
}
/* Open input file */
- handle = open(file, O_RDONLY);
- if (handle == -1) {
+ handle = fopen(file, "rb");
+ if (handle == NULL) {
dom_hubbub_parser_destroy(parser);
printf("Can't open test input file: %s\n", file);
return NULL;
@@ -97,7 +95,7 @@ dom_document *create_doc_dom_from_file(char *file)
/* Parse input file in chunks */
chunk_length = buffer_size;
while(chunk_length == buffer_size) {
- chunk_length = read(handle, buffer, buffer_size);
+ chunk_length = fread(buffer, 1, buffer_size, handle);
error = dom_hubbub_parser_parse_chunk(parser, buffer,
chunk_length);
if (error != DOM_HUBBUB_OK) {
@@ -122,7 +120,7 @@ dom_document *create_doc_dom_from_file(char *file)
dom_hubbub_parser_destroy(parser);
/* Close input file */
- if (close(handle) == -1) {
+ if (fclose(handle) != 0) {
printf("Can't close test input file: %s\n", file);
return NULL;
}