posix/ostream: protect win32 against missing stat members

This commit is contained in:
Danny Robson 2019-05-05 09:30:00 +10:00
parent 82aef3e207
commit c3c36a662b

View File

@ -1,8 +1,12 @@
#include "ostream.hpp"
#include "../platform.hpp"
#include <ostream>
#include <iomanip>
#include <sys/stat.h>
///////////////////////////////////////////////////////////////////////////////
struct type_printer {
@ -18,9 +22,11 @@ struct type_printer {
std::ostream& operator<< (std::ostream &os, type_printer const &val)
{
os << "[ ";
#ifndef PLATFORM_WIN32
if (val.data.st_mode & S_ISUID) os << "SUID, ";
if (val.data.st_mode & S_ISGID) os << "SGID, ";
if (val.data.st_mode & S_ISVTX) os << "STICKY, ";
#endif
os << "{ user: " << (val.data.st_mode & S_IRUSR ? 'r' : '_')
<< (val.data.st_mode & S_IWUSR ? 'w' : '_')
@ -53,13 +59,15 @@ struct mode_printer {
std::ostream& operator<< (std::ostream &os, mode_printer const &val)
{
return S_ISREG (val.data.st_mode) ? os << "REGULAR"
: S_ISDIR (val.data.st_mode) ? os << "DIRECTORY"
: S_ISCHR (val.data.st_mode) ? os << "CHARACTER"
: S_ISBLK (val.data.st_mode) ? os << "BLOCK"
: S_ISFIFO (val.data.st_mode) ? os << "FIFO"
: S_ISLNK (val.data.st_mode) ? os << "SYMLINK"
: S_ISSOCK (val.data.st_mode) ? os << "SOCKET"
: (throw std::invalid_argument ("Unhandled mode_t"), os << "_error");
: S_ISDIR (val.data.st_mode) ? os << "DIRECTORY"
: S_ISCHR (val.data.st_mode) ? os << "CHARACTER"
: S_ISBLK (val.data.st_mode) ? os << "BLOCK"
: S_ISFIFO (val.data.st_mode) ? os << "FIFO"
#ifndef PLATFORM_WIN32
: S_ISLNK (val.data.st_mode) ? os << "SYMLINK"
: S_ISSOCK (val.data.st_mode) ? os << "SOCKET"
#endif
: (throw std::invalid_argument ("Unhandled mode_t"), os << "_error");
}
@ -73,6 +81,8 @@ std::ostream& operator<< (std::ostream &os, struct stat const &val)
<< ", uid: " << val.st_uid
<< ", gid: " << val.st_gid
<< ", size: " << val.st_size
#ifndef PLATFORM_WIN32
<< ", blocksize: " << val.st_blksize
#endif
<< " }";
}