static int main_(int argc, char** argv) { { for(int i = 1; i < argc; ++i) { char const* const arg = argv[i]; }} winstl::temporary_directory dir; winstl::path path1(dir); winstl::path path2(dir); path1 /= "abc"; path2 /= "def"; stlsoft::scoped_handle<char const*> scoper3(path1.c_str(), ::remove); stlsoft::scoped_handle<char const*> scoper4(path2.c_str(), ::remove); HANDLE hFile = winstl::file_create_always(path1.c_str(), GENERIC_WRITE, 0, 0); if(INVALID_HANDLE_VALUE == hFile) { fprintf(stderr, "could not open %s: %s\n", path1.c_str(), winstl::error_desc().c_str()); return EXIT_FAILURE; } else { stlsoft::scoped_handle<HANDLE> scoper1(hFile, ::CloseHandle, INVALID_HANDLE_VALUE); ; } DWORD numLinks1; DWORD numLinks2; winstl::hard_link_count_links(path1.c_str(), &numLinks1); if(!winstl::hard_link_create(path2.c_str(), path1.c_str())) { fprintf(stderr, "failed: %s\n", winstl::error_desc().c_str()); } winstl::hard_link_count_links(path1.c_str(), &numLinks2); // tmpnam /* . */ return EXIT_SUCCESS; }
static int main_(int /* argc */, char ** /*argv*/) { platformstl::file_path_buffer path1; platformstl::file_path_buffer path2; stlsoft::scoped_handle<char const*> scoper1(::tmpnam(&path1[0]), ::remove); stlsoft::scoped_handle<char const*> scoper2(::tmpnam(&path2[0]), ::remove); // Define the data: // // "FastFormat can write to vectored file APIs" static char fragment0[] = " "; static char fragment1[] = "FastFormat"; static char fragment2[] = "can"; static char fragment3[] = "write"; static char fragment4[] = "to"; static char fragment5[] = "vectored"; static char fragment6[] = "file"; static char fragment7[] = "APIs"; fprintf(stdout, "writing to '%s' via raw API (writev())\n", path1.c_str()); { iovec vecs[] = { { &fragment1[0], STLSOFT_NUM_ELEMENTS(fragment1) - 1 } // "FastFormat" , { &fragment0[0], STLSOFT_NUM_ELEMENTS(fragment0) - 1 } // " " , { &fragment2[0], STLSOFT_NUM_ELEMENTS(fragment2) - 1 } // "can" , { &fragment0[0], STLSOFT_NUM_ELEMENTS(fragment0) - 1 } // " " , { &fragment3[0], STLSOFT_NUM_ELEMENTS(fragment3) - 1 } // "write" , { &fragment0[0], STLSOFT_NUM_ELEMENTS(fragment0) - 1 } // " " , { &fragment4[0], STLSOFT_NUM_ELEMENTS(fragment4) - 1 } // "to" , { &fragment0[0], STLSOFT_NUM_ELEMENTS(fragment0) - 1 } // " " , { &fragment5[0], STLSOFT_NUM_ELEMENTS(fragment5) - 1 } // "vectored" , { &fragment0[0], STLSOFT_NUM_ELEMENTS(fragment0) - 1 } // " " , { &fragment6[0], STLSOFT_NUM_ELEMENTS(fragment6) - 1 } // "file" , { &fragment0[0], STLSOFT_NUM_ELEMENTS(fragment0) - 1 } // " " , { &fragment7[0], STLSOFT_NUM_ELEMENTS(fragment7) - 1 } // "APIs" }; int fh = ::open(path1.c_str(), O_RDWR | O_CREAT, S_IWRITE | S_IREAD); ssize_t cb = ::writev(fh, &vecs[0], STLSOFT_NUM_ELEMENTS(vecs)); ::close(fh); STLSOFT_SUPPRESS_UNUSED(cb); } fprintf(stdout, "writing to '%s' via FastFormat's vectored_file sink\n", path2.c_str()); { int fh = ::open(path2.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IWRITE | S_IREAD); stlsoft::scoped_handle<int> fh_(fh, ::close, -1); fastformat::sinks::vectored_file_sink s(fh); fastformat::fmt(s, "{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}", fragment0, fragment1, fragment2, fragment3, fragment4, fragment5, fragment6, fragment7); } fprintf(stdout, "memory mapping '%s'\n", path1.c_str()); platformstl::file_lines lines1(path1.c_str()); fprintf(stdout, "memory mapping '%s'\n", path2.c_str()); platformstl::file_lines lines2(path2.c_str()); if(lines1 != lines2) { fprintf(stderr, "file contents differ!\n"); } else { fprintf(stdout, "file contents identical\n"); } return EXIT_SUCCESS; }