MCPcopy Create free account
hub / github.com/davisking/dlib / init

Method init

dlib/dir_nav/dir_nav_kernel_2.cpp:26–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24// ----------------------------------------------------------------------------------------
25
26 void file::
27 init (
28 const std::string& name
29 )
30 {
31 using namespace std;
32
33
34
35 char buf[PATH_MAX];
36 if (realpath(name.c_str(),buf) == 0)
37 {
38 // the file was not found
39 throw file_not_found("Unable to find file " + name);
40 }
41 state.full_name = buf;
42
43
44 string::size_type pos = state.full_name.find_last_of(directory::get_separator());
45 if (pos == string::npos)
46 {
47 // no valid full path has no separtor characters.
48 throw file_not_found("Unable to find file " + name);
49 }
50 state.name = state.full_name.substr(pos+1);
51
52
53 // now find the size of this file
54 struct stat64 buffer;
55 if (::stat64(state.full_name.c_str(), &buffer) ||
56 S_ISDIR(buffer.st_mode))
57 {
58 // there was an error during the call to stat64 or
59 // name is actually a directory
60 throw file_not_found("Unable to find file " + name);
61 }
62 else
63 {
64 state.file_size = static_cast<uint64>(buffer.st_size);
65
66
67 state.last_modified = std::chrono::system_clock::from_time_t(buffer.st_mtime);
68#ifdef _BSD_SOURCE
69 state.last_modified += std::chrono::duration_cast<std::chrono::system_clock::duration>(std::chrono::nanoseconds(buffer.st_atim.tv_nsec));
70#endif
71 }
72
73 }
74
75// ----------------------------------------------------------------------------------------
76

Callers

nothing calls this directly

Calls 5

eraseMethod · 0.80
file_not_foundClass · 0.70
stat64Class · 0.70
dir_not_foundClass · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected