本文整理汇总了C++中OutputFile::openStdout方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputFile::openStdout方法的具体用法?C++ OutputFile::openStdout怎么用?C++ OutputFile::openStdout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputFile
的用法示例。
在下文中一共展示了OutputFile::openStdout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_one_file
void do_one_file(const char *iname, char *oname)
{
int r;
struct stat st;
memset(&st, 0, sizeof(st));
#if (HAVE_LSTAT)
r = lstat(iname, &st);
#else
r = stat(iname, &st);
#endif
if (r != 0)
{
if (errno == ENOENT)
throw FileNotFoundException(iname, errno);
else
throwIOException(iname, errno);
}
if (!(S_ISREG(st.st_mode)))
throwIOException("not a regular file -- skipped");
#if defined(__unix__)
// no special bits may be set
if ((st.st_mode & (S_ISUID | S_ISGID | S_ISVTX)) != 0)
throwIOException("file has special permissions -- skipped");
#endif
if (st.st_size <= 0)
throwIOException("empty file -- skipped");
if (st.st_size < 512)
throwIOException("file is too small -- skipped");
if (!mem_size_valid_bytes(st.st_size))
throwIOException("file is too large -- skipped");
if ((st.st_mode & S_IWUSR) == 0)
{
bool skip = true;
if (opt->output_name)
skip = false;
else if (opt->to_stdout)
skip = false;
else if (opt->backup)
skip = false;
if (skip)
throwIOException("file is write protected -- skipped");
}
InputFile fi;
fi.st = st;
fi.sopen(iname, O_RDONLY | O_BINARY, SH_DENYWR);
#if (USE_FTIME)
struct ftime fi_ftime;
memset(&fi_ftime, 0, sizeof(fi_ftime));
if (opt->preserve_timestamp)
{
if (getftime(fi.getFd(), &fi_ftime) != 0)
throwIOException("cannot determine file timestamp");
}
#endif
// open output file
OutputFile fo;
if (opt->cmd == CMD_COMPRESS || opt->cmd == CMD_DECOMPRESS)
{
if (opt->to_stdout)
{
if (!fo.openStdout(1, opt->force ? true : false))
throwIOException("data not written to a terminal; Use '-f' to force.");
}
else
{
char tname[ACC_FN_PATH_MAX+1];
if (opt->output_name)
strcpy(tname,opt->output_name);
else
{
if (!maketempname(tname, sizeof(tname), iname, ".upx"))
throwIOException("could not create a temporary file name");
}
if (opt->force >= 2)
{
#if (HAVE_CHMOD)
r = chmod(tname, 0777);
IGNORE_ERROR(r);
#endif
r = unlink(tname);
IGNORE_ERROR(r);
}
int flags = O_CREAT | O_WRONLY | O_BINARY;
if (opt->force)
flags |= O_TRUNC;
else
flags |= O_EXCL;
int shmode = SH_DENYWR;
#if defined(__MINT__)
flags |= O_TRUNC;
shmode = O_DENYRW;
#endif
// cannot rely on open() because of umask
//int omode = st.st_mode | 0600;
int omode = 0600;
if (!opt->preserve_mode)
omode = 0666;
//.........这里部分代码省略.........