aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-02-28 21:49:08 +0100
committerJay Berkenbilt <ejb@ql.org>2013-03-05 19:35:46 +0100
commit66c3c8fdf7c60b34039bc9f70cd9bb00e0c0235d (patch)
tree503703336ef242487024d13c257e25d4fff3ae59
parent6b9297882e0106b5c0af53320673d6341b9bea91 (diff)
downloadqpdf-66c3c8fdf7c60b34039bc9f70cd9bb00e0c0235d.tar.zst
Use portable versions of some UNIX-specific calls
Remove needless calls to open, close, and fileno; call remove instead of unlink.
-rw-r--r--examples/pdf-mod-info.cc3
-rw-r--r--libqpdf/Pl_StdioFile.cc7
-rw-r--r--libtests/qtest/qutil/qutil.out4
-rw-r--r--libtests/qutil.cc10
4 files changed, 10 insertions, 14 deletions
diff --git a/examples/pdf-mod-info.cc b/examples/pdf-mod-info.cc
index e8defa32..8bd9f5d6 100644
--- a/examples/pdf-mod-info.cc
+++ b/examples/pdf-mod-info.cc
@@ -8,6 +8,7 @@
#include <iostream>
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
#ifdef _WIN32
#include <Windows.h>
#include <direct.h>
@@ -219,7 +220,7 @@ int main(int argc, char* argv[])
try
{
- (void) unlink(fl_out);
+ (void) remove(fl_out);
QUtil::os_wrapper("rename " + fl_tmp + " " + std::string(fl_out),
rename(fl_tmp.c_str(), fl_out));
}
diff --git a/libqpdf/Pl_StdioFile.cc b/libqpdf/Pl_StdioFile.cc
index 808177d0..4d3cba60 100644
--- a/libqpdf/Pl_StdioFile.cc
+++ b/libqpdf/Pl_StdioFile.cc
@@ -37,11 +37,8 @@ Pl_StdioFile::write(unsigned char* buf, size_t len)
void
Pl_StdioFile::finish()
{
- if (fileno(this->file) != -1) // XXXX
- {
- fflush(this->file);
- }
- else
+ if ((fflush(this->file) == -1) &&
+ (errno == EBADF))
{
throw std::logic_error(
this->identifier +
diff --git a/libtests/qtest/qutil/qutil.out b/libtests/qtest/qutil/qutil.out
index c855e98e..737e4c72 100644
--- a/libtests/qtest/qutil/qutil.out
+++ b/libtests/qtest/qutil/qutil.out
@@ -12,8 +12,8 @@ one
7
compare okay
----
-before open
-exception: open file: No such file or directory
+before remove
+exception: remove file: No such file or directory
----
before fopen
exception: fopen file: No such file or directory
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index e293c374..8d9c2383 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -44,14 +44,12 @@ void string_conversion_test()
void os_wrapper_test()
{
- int fd = -1;
try
{
- std::cout << "before open" << std::endl;
- fd = QUtil::os_wrapper("open file",
- open("/this/file/does/not/exist", O_RDONLY));
- std::cout << "after open" << std::endl;
- (void) close(fd);
+ std::cout << "before remove" << std::endl;
+ QUtil::os_wrapper("remove file",
+ remove("/this/file/does/not/exist"));
+ std::cout << "after remove" << std::endl;
}
catch (std::runtime_error& s)
{