Use stdin for *NIX as well

We thought that we can use /dev/stdin for *NIX, but some variants,
like Android, does not have one or root permission is required.  Just
like we do for Windows build, we just use stdin if /dev/stdin is used.
pull/786/head
Tatsuhiro Tsujikawa 2016-11-26 22:17:01 +09:00
parent d0a0645836
commit e4f3d633c1
2 changed files with 12 additions and 11 deletions

View File

@ -44,15 +44,15 @@
namespace aria2 { namespace aria2 {
BufferedFile::BufferedFile(const char* filename, const char* mode) BufferedFile::BufferedFile(const char* filename, const char* mode)
: : fp_(strcmp(DEV_STDIN, filename) == 0
#ifdef __MINGW32__
fp_(strcmp(DEV_STDIN, filename) == 0
? stdin ? stdin
: a2fopen(utf8ToWChar(filename).c_str(), :
utf8ToWChar(mode).c_str())), #ifdef __MINGW32__
a2fopen(utf8ToWChar(filename).c_str(), utf8ToWChar(mode).c_str())
#else // !__MINGW32__ #else // !__MINGW32__
fp_(a2fopen(filename, mode)), a2fopen(filename, mode)
#endif // !__MINGW32__ #endif // !__MINGW32__
),
supportsColor_(fp_ ? isatty(fileno(fp_)) : false) supportsColor_(fp_ ? isatty(fileno(fp_)) : false)
{ {
} }

View File

@ -46,15 +46,16 @@ namespace aria2 {
GZipFile::GZipFile(const char* filename, const char* mode) GZipFile::GZipFile(const char* filename, const char* mode)
: fp_(nullptr), buflen_(1_k), buf_(reinterpret_cast<char*>(malloc(buflen_))) : fp_(nullptr), buflen_(1_k), buf_(reinterpret_cast<char*>(malloc(buflen_)))
{ {
FILE* fp = auto fp =
#ifdef __MINGW32__
strcmp(DEV_STDIN, filename) == 0 strcmp(DEV_STDIN, filename) == 0
? stdin ? stdin
: a2fopen(utf8ToWChar(filename).c_str(), utf8ToWChar(mode).c_str()); :
#ifdef __MINGW32__
a2fopen(utf8ToWChar(filename).c_str(), utf8ToWChar(mode).c_str())
#else // !__MINGW32__ #else // !__MINGW32__
a2fopen(filename, mode); a2fopen(filename, mode)
#endif // !__MINGW32__ #endif // !__MINGW32__
;
if (fp) { if (fp) {
int fd = dup(fileno(fp)); int fd = dup(fileno(fp));
if (fd != -1) { if (fd != -1) {