Commit 66c3c8fdf7c60b34039bc9f70cd9bb00e0c0235d

Authored by Jay Berkenbilt
1 parent 6b929788

Use portable versions of some UNIX-specific calls

Remove needless calls to open, close, and fileno; call remove instead
of unlink.
examples/pdf-mod-info.cc
... ... @@ -8,6 +8,7 @@
8 8 #include <iostream>
9 9 #include <string.h>
10 10 #include <stdlib.h>
  11 +#include <stdio.h>
11 12 #ifdef _WIN32
12 13 #include <Windows.h>
13 14 #include <direct.h>
... ... @@ -219,7 +220,7 @@ int main(int argc, char* argv[])
219 220  
220 221 try
221 222 {
222   - (void) unlink(fl_out);
  223 + (void) remove(fl_out);
223 224 QUtil::os_wrapper("rename " + fl_tmp + " " + std::string(fl_out),
224 225 rename(fl_tmp.c_str(), fl_out));
225 226 }
... ...
libqpdf/Pl_StdioFile.cc
... ... @@ -37,11 +37,8 @@ Pl_StdioFile::write(unsigned char* buf, size_t len)
37 37 void
38 38 Pl_StdioFile::finish()
39 39 {
40   - if (fileno(this->file) != -1) // XXXX
41   - {
42   - fflush(this->file);
43   - }
44   - else
  40 + if ((fflush(this->file) == -1) &&
  41 + (errno == EBADF))
45 42 {
46 43 throw std::logic_error(
47 44 this->identifier +
... ...
libtests/qtest/qutil/qutil.out
... ... @@ -12,8 +12,8 @@ one
12 12 7
13 13 compare okay
14 14 ----
15   -before open
16   -exception: open file: No such file or directory
  15 +before remove
  16 +exception: remove file: No such file or directory
17 17 ----
18 18 before fopen
19 19 exception: fopen file: No such file or directory
... ...
libtests/qutil.cc
... ... @@ -44,14 +44,12 @@ void string_conversion_test()
44 44  
45 45 void os_wrapper_test()
46 46 {
47   - int fd = -1;
48 47 try
49 48 {
50   - std::cout << "before open" << std::endl;
51   - fd = QUtil::os_wrapper("open file",
52   - open("/this/file/does/not/exist", O_RDONLY));
53   - std::cout << "after open" << std::endl;
54   - (void) close(fd);
  49 + std::cout << "before remove" << std::endl;
  50 + QUtil::os_wrapper("remove file",
  51 + remove("/this/file/does/not/exist"));
  52 + std::cout << "after remove" << std::endl;
55 53 }
56 54 catch (std::runtime_error& s)
57 55 {
... ...