1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include "sys.h"
#include "debug.h"
#include <sys/stat.h>
#include <unistd.h>
std::ostream& operator<<(std::ostream& os, struct stat const buf)
{
os << "inode:" << buf.st_ino << "; " << "size:" << buf.st_size;
return os;
}
std::ostream& operator<<(std::ostream& os, struct stat const* bufp)
{
os << "{ " << *bufp << " }";
return os;
}
// We only use this function to show what happens with the debug output.
// You shouldn't do anything like this in a real program.
int stat_with_buf_alloc(char const* file_name, struct stat*& bufp)
{
bufp = new struct stat;
return stat(file_name, bufp);
}
int main(int argc, char* argv[])
{
Debug( libcw_do.on() );
Debug( dc::notice.on() );
Debug( dc::malloc.on() );
if (argc != 2)
{
std::cerr << "Usage: " << argv[0] << " <file_name>\n";
exit(-1);
}
char const* file_name = argv[1];
struct stat* bufp;
Dout(dc::notice|continued_cf,
"stat_with_buf_alloc(\"" << file_name << "\", ");
int ret = stat_with_buf_alloc(file_name, bufp);
Dout(dc::finish|cond_error_cf(ret != 0),
bufp << ") = " << ret);
Debug( dc::malloc.off() );
delete bufp;
return 0;
}
|