2021-03-13 | Paul Boddie | raw annotate files changeset graph | Renamed file_open to file_context_open, providing file_open as a convenience function that creates a context, sets the filename, opens the file, and closes the context. Changed the string-setting function to be more immediately useful, if more complicated in operation, for this application. |
1 #include <sys/stat.h> 2 3 #include "host_file_accessor.h" 4 #include "host_file_opener.h" 5 6 /* Return a file identifier for the given 'path'. */ 7 8 fileid_t HostFileOpener::get_fileid(const char *path) 9 { 10 struct stat statbuf; 11 12 /* Obtain the inode number. 13 NOTE: This does not handle errors! */ 14 15 stat(path, &statbuf); 16 17 _paths.insert(FilePathEntry(statbuf.st_ino, path)); 18 19 return statbuf.st_ino; 20 } 21 22 /* Return a new accessor for 'fileid'. */ 23 24 Accessor *HostFileOpener::make_accessor(fileid_t fileid) 25 { 26 FilePaths::iterator found = _paths.find(fileid); 27 28 if (found != _paths.end()) 29 return new HostFileAccessor(found->second, fileid); 30 else 31 return NULL; 32 } 33 34 // vim: tabstop=4 expandtab shiftwidth=4