/*! \brief Reinitializes the object as a copy of the \a node. \param node the BNode to be copied \return a reference to this BNode object. */ BNode& BNode::operator=(const BNode &node) { // No need to do any assignment if already equal if (*this == node) return *this; // Close down out current state Unset(); // We have to manually dup the node, because R5::BNode::Dup() // is not declared to be const (which IMO is retarded). fFd = _kern_dup(node.fFd); fCStatus = (fFd < 0) ? B_NO_INIT : B_OK ; return *this; }
/*! \brief Assigns another BFile to this BFile. If the other BFile is uninitialized, this one will be too. Otherwise it will refer to the same file using the same mode, unless an error occurs. \param file the original BFile \return a reference to this BFile */ BFile & BFile::operator=(const BFile &file) { if (&file != this) { // no need to assign us to ourselves Unset(); if (file.InitCheck() == B_OK) { // duplicate the file descriptor int fd = _kern_dup(file.get_fd()); // set it if (fd >= 0) { fFd = fd; fMode = file.fMode; fCStatus = B_OK; } else fCStatus = fd; } } return *this; }
int dup(int fd) { RETURN_AND_SET_ERRNO(_kern_dup(fd)); }
/*! \brief Returns a POSIX file descriptor to the node this object refers to. Remember to call close() on the file descriptor when you're through with it. \return a valid file descriptor, or -1, if something went wrong. */ int BNode::Dup() { int fd = _kern_dup(fFd); return (fd >= 0 ? fd : -1); // comply with R5 return value }