int fl_createdirectory(const char *path) { int res; // If first call to library, initialise CHECK_FL_INIT(); FL_LOCK(&_fs); res =_create_directory((char*)path); FL_UNLOCK(&_fs); return res; }
QBStatus TapFile::open(const string &pipename, const QBioMode &mode) { static const char *method = "TapFile::open()"; QBStatus status; string full_filename = _root_dir + pipename; int oflags; switch(mode) { case QB_READ: oflags = O_RDONLY; break; case QB_WRITE: oflags = (O_CREAT | O_RDWR | O_TRUNC); _create_directory(pipename); break; case QB_APPEND: qb_logerr(QB_FAILURE, __FILE__, __LINE__, method, "Append not yet supported for Tap Files", mode); return(QB_FAILURE); break; default: qb_logerr(QB_FAILURE, __FILE__, __LINE__, method, "Bad mode: %d", mode); return(QB_FAILURE); } _fd = ::open(full_filename.c_str(), oflags, 0777); if (_fd < 0) { if (errno == ENOENT) status = QB_FILENOTFOUND; else status = QB_FAILURE; qb_logerr(status, __FILE__, __LINE__, method, "Error opening for File: %s, errno:%d", pipename.c_str(), errno); return(status); } _name = pipename; _mode = mode; switch(_mode) { // get a couple more file handles case QB_READ: _metaFd = ::open(full_filename.c_str(), oflags, 0777); if (_metaFd < 0) { if (errno == ENOENT) status = QB_FILENOTFOUND; else status = QB_FAILURE; qb_logerr(status, __FILE__, __LINE__, method, "Error opening for File:%s, errno:%d", pipename.c_str(), errno); return(status); } _indexFd = ::open(full_filename.c_str(), oflags, 0777); if (_indexFd < 0) { if (errno == ENOENT) status = QB_FILENOTFOUND; else status = QB_FAILURE; qb_logerr(status, __FILE__, __LINE__, method, "Error opening for File:%s, errno:%d", pipename.c_str(), errno); return(status); } _read_trailer(); break; case QB_WRITE: _first_write = true; _header.Clear(); _header.set_initial_pipe_name(pipename); _header.set_key_descriptor("<NEEDS CODING>"); _fileOStream = new google::protobuf::io::FileOutputStream(_fd); // header gets written on first write break; } return QB_SUCCESS; }