Commit 66c3c8fdf7c60b34039bc9f70cd9bb00e0c0235d
1 parent
6b929788
Use portable versions of some UNIX-specific calls
Remove needless calls to open, close, and fileno; call remove instead of unlink.
Showing
4 changed files
with
10 additions
and
14 deletions
examples/pdf-mod-info.cc
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | #include <iostream> | 8 | #include <iostream> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| 10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 11 | +#include <stdio.h> | ||
| 11 | #ifdef _WIN32 | 12 | #ifdef _WIN32 |
| 12 | #include <Windows.h> | 13 | #include <Windows.h> |
| 13 | #include <direct.h> | 14 | #include <direct.h> |
| @@ -219,7 +220,7 @@ int main(int argc, char* argv[]) | @@ -219,7 +220,7 @@ int main(int argc, char* argv[]) | ||
| 219 | 220 | ||
| 220 | try | 221 | try |
| 221 | { | 222 | { |
| 222 | - (void) unlink(fl_out); | 223 | + (void) remove(fl_out); |
| 223 | QUtil::os_wrapper("rename " + fl_tmp + " " + std::string(fl_out), | 224 | QUtil::os_wrapper("rename " + fl_tmp + " " + std::string(fl_out), |
| 224 | rename(fl_tmp.c_str(), fl_out)); | 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,11 +37,8 @@ Pl_StdioFile::write(unsigned char* buf, size_t len) | ||
| 37 | void | 37 | void |
| 38 | Pl_StdioFile::finish() | 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 | throw std::logic_error( | 43 | throw std::logic_error( |
| 47 | this->identifier + | 44 | this->identifier + |
libtests/qtest/qutil/qutil.out
| @@ -12,8 +12,8 @@ one | @@ -12,8 +12,8 @@ one | ||
| 12 | 7 | 12 | 7 |
| 13 | compare okay | 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 | before fopen | 18 | before fopen |
| 19 | exception: fopen file: No such file or directory | 19 | exception: fopen file: No such file or directory |
libtests/qutil.cc
| @@ -44,14 +44,12 @@ void string_conversion_test() | @@ -44,14 +44,12 @@ void string_conversion_test() | ||
| 44 | 44 | ||
| 45 | void os_wrapper_test() | 45 | void os_wrapper_test() |
| 46 | { | 46 | { |
| 47 | - int fd = -1; | ||
| 48 | try | 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 | catch (std::runtime_error& s) | 54 | catch (std::runtime_error& s) |
| 57 | { | 55 | { |