summaryrefslogtreecommitdiff
path: root/libspectre/spectre-document.c
diff options
context:
space:
mode:
Diffstat (limited to 'libspectre/spectre-document.c')
-rw-r--r--libspectre/spectre-document.c47
1 files changed, 11 insertions, 36 deletions
diff --git a/libspectre/spectre-document.c b/libspectre/spectre-document.c
index ff3e57c..3cd9d7d 100644
--- a/libspectre/spectre-document.c
+++ b/libspectre/spectre-document.c
@@ -53,24 +53,10 @@ spectre_document_new (void)
static void
document_load (SpectreDocument *document,
const char *filename,
- void *buffer,
- size_t size)
+ FILE *file)
{
- FILE *file;
-
_spectre_return_if_fail (document != NULL);
-#if _POSIX_C_SOURCE >= 200809L
- if(buffer == NULL) {
- _spectre_return_if_fail (filename != NULL);
- } else {
- _spectre_return_if_fail (buffer != NULL);
- }
-#else
- _spectre_return_if_fail (filename != NULL);
-#endif
-
-
if (document->doc && strcmp (filename, document->doc->filename) == 0) {
document->status = SPECTRE_STATUS_SUCCESS;
return;
@@ -81,16 +67,6 @@ document_load (SpectreDocument *document,
document->doc = NULL;
}
-#if _POSIX_C_SOURCE >= 200809L
- if(buffer == NULL) {
- file = fopen (filename, "rb");
- } else {
- file = fmemopen (buffer, size, "rb");
- }
-#else
- file = fopen (filename, "rb");
-#endif
-
if (!file) {
document->status = SPECTRE_STATUS_LOAD_ERROR;
return;
@@ -99,7 +75,6 @@ document_load (SpectreDocument *document,
document->doc = psscan (file, filename, SCANSTYLE_NORMAL);
if (!document->doc) {
document->status = SPECTRE_STATUS_LOAD_ERROR;
- fclose (file);
return;
}
@@ -107,7 +82,6 @@ document_load (SpectreDocument *document,
document->status = SPECTRE_STATUS_LOAD_ERROR;
psdocdestroy (document->doc);
document->doc = NULL;
- fclose (file);
return;
} else if (document->doc->numpages == 0 && !document->doc->format) {
@@ -122,7 +96,6 @@ document_load (SpectreDocument *document,
document->status = SPECTRE_STATUS_LOAD_ERROR;
psdocdestroy (document->doc);
document->doc = NULL;
- fclose (file);
return;
}
@@ -134,25 +107,27 @@ document_load (SpectreDocument *document,
if (document->status != SPECTRE_STATUS_SUCCESS)
document->status = SPECTRE_STATUS_SUCCESS;
- fclose (file);
}
void
spectre_document_load (SpectreDocument *document,
const char *filename)
{
- document_load (document, filename, NULL, 0);
+ FILE *file;
+
+ _spectre_return_if_fail (filename != NULL);
+
+ file = fopen (filename, "rb");
+ document_load (document, filename, file);
+ fclose (file);
}
-#if _POSIX_C_SOURCE >= 200809L
void
-spectre_document_load_from_data (SpectreDocument *document,
- void *data,
- size_t size)
+spectre_document_load_from_stream (SpectreDocument *document,
+ FILE *file)
{
- document_load (document, NULL, data, size);
+ document_load (document, "stream", file);
}
-#endif
void
spectre_document_free (SpectreDocument *document)