1*434716ceSJohn Scipione/* 2*434716ceSJohn Scipione * Copyright 2002-2013 Haiku Inc. All rights reserved. 3*434716ceSJohn Scipione * Distributed under the terms of the MIT License. 4*434716ceSJohn Scipione * 5*434716ceSJohn Scipione * Authors: 6*434716ceSJohn Scipione * Tyler Dauwalder 7*434716ceSJohn Scipione * John Scipione, jscipione@gmail.com 8*434716ceSJohn Scipione * Ingo Weinhold, bonefish@users.sf.net 9*434716ceSJohn Scipione * 10*434716ceSJohn Scipione * Corresponds to: 11*434716ceSJohn Scipione * headers/os/storage/Symlink.h hrev45306 12*434716ceSJohn Scipione * src/kits/storage/Symlink.cpp hrev45306 13*434716ceSJohn Scipione */ 14*434716ceSJohn Scipione 15*434716ceSJohn Scipione 16*434716ceSJohn Scipione/*! 17*434716ceSJohn Scipione \file Symlink.h 18*434716ceSJohn Scipione \ingroup storage 19*434716ceSJohn Scipione \ingroup libbe 20*434716ceSJohn Scipione \brief Provides the BSymLink class. 21*434716ceSJohn Scipione*/ 22*434716ceSJohn Scipione 23*434716ceSJohn Scipione 24*434716ceSJohn Scipione/*! 25*434716ceSJohn Scipione \class BSymLink 26*434716ceSJohn Scipione \ingroup storage 27*434716ceSJohn Scipione \ingroup libbe 28*434716ceSJohn Scipione \brief Provides an interface for creating, manipulating, and accessing 29*434716ceSJohn Scipione the contents of symbolic links. 30*434716ceSJohn Scipione*/ 31*434716ceSJohn Scipione 32*434716ceSJohn Scipione 33*434716ceSJohn Scipione/*! 34*434716ceSJohn Scipione \fn BSymLink::BSymLink() 35*434716ceSJohn Scipione \brief Creates an uninitialized BSymLink object. 36*434716ceSJohn Scipione*/ 37*434716ceSJohn Scipione 38*434716ceSJohn Scipione 39*434716ceSJohn Scipione/*! 40*434716ceSJohn Scipione \fn BSymLink::BSymLink(const BSymLink &link) 41*434716ceSJohn Scipione \brief Creates a copy of the supplied BSymLink object. 42*434716ceSJohn Scipione 43*434716ceSJohn Scipione \param link The BSymLink object to be copied. 44*434716ceSJohn Scipione*/ 45*434716ceSJohn Scipione 46*434716ceSJohn Scipione 47*434716ceSJohn Scipione/*! 48*434716ceSJohn Scipione \fn BSymLink::BSymLink(const entry_ref *ref) 49*434716ceSJohn Scipione \brief Creates a BSymLink object and initializes it to the symbolic link 50*434716ceSJohn Scipione referred to by the supplied entry_ref. 51*434716ceSJohn Scipione 52*434716ceSJohn Scipione \param ref the entry_ref referring to the symbolic link. 53*434716ceSJohn Scipione*/ 54*434716ceSJohn Scipione 55*434716ceSJohn Scipione 56*434716ceSJohn Scipione/*! 57*434716ceSJohn Scipione \fn BSymLink::BSymLink(const BEntry *entry) 58*434716ceSJohn Scipione \brief Creates a BSymLink object and initializes it to the symbolic link 59*434716ceSJohn Scipione referred to by the supplied BEntry. 60*434716ceSJohn Scipione 61*434716ceSJohn Scipione \param entry The BEntry referring to the symbolic link. 62*434716ceSJohn Scipione*/ 63*434716ceSJohn Scipione 64*434716ceSJohn Scipione 65*434716ceSJohn Scipione/*! 66*434716ceSJohn Scipione \fn BSymLink::BSymLink(const char *path) 67*434716ceSJohn Scipione \brief Creates a BSymLink object and initializes it to the symbolic link 68*434716ceSJohn Scipione referred to by the supplied path name. 69*434716ceSJohn Scipione 70*434716ceSJohn Scipione \param path The path of the symbolic link. 71*434716ceSJohn Scipione*/ 72*434716ceSJohn Scipione 73*434716ceSJohn Scipione 74*434716ceSJohn Scipione/*! 75*434716ceSJohn Scipione \fn BSymLink::BSymLink(const BDirectory *dir, const char *path) 76*434716ceSJohn Scipione \brief Creates a BSymLink object and initializes it to the symbolic link 77*434716ceSJohn Scipione referred to by the supplied path name relative to the specified 78*434716ceSJohn Scipione BDirectory. 79*434716ceSJohn Scipione 80*434716ceSJohn Scipione \param dir The base BDirectory. 81*434716ceSJohn Scipione \param path The path of the symbolic link relative to \a dir. 82*434716ceSJohn Scipione*/ 83*434716ceSJohn Scipione 84*434716ceSJohn Scipione 85*434716ceSJohn Scipione/*! 86*434716ceSJohn Scipione \fn BSymLink::~BSymLink() 87*434716ceSJohn Scipione \brief Destroys the object and frees all allocated resources. 88*434716ceSJohn Scipione 89*434716ceSJohn Scipione If the BSymLink was properly initialized, the file descriptor of the 90*434716ceSJohn Scipione symbolic link is also closed. 91*434716ceSJohn Scipione*/ 92*434716ceSJohn Scipione 93*434716ceSJohn Scipione 94*434716ceSJohn Scipione/*! 95*434716ceSJohn Scipione \fn ssize_t BSymLink::ReadLink(char *buffer, size_t size) 96*434716ceSJohn Scipione \brief Reads the contents of the symbolic link into \a buffer. 97*434716ceSJohn Scipione 98*434716ceSJohn Scipione The string written to the buffer is guaranteed to be \c NULL terminated. 99*434716ceSJohn Scipione 100*434716ceSJohn Scipione \param buffer The buffer to read the symlink's contents into. 101*434716ceSJohn Scipione \param size The size of \a buffer. 102*434716ceSJohn Scipione 103*434716ceSJohn Scipione \return The number of bytes written into the buffer or an error code. 104*434716ceSJohn Scipione \retval B_BAD_VALUE \a buf was \c NULL or the object didn't refer to a 105*434716ceSJohn Scipione symbolic link. 106*434716ceSJohn Scipione \retval B_FILE_ERROR The object was not initialized. 107*434716ceSJohn Scipione*/ 108*434716ceSJohn Scipione 109*434716ceSJohn Scipione 110*434716ceSJohn Scipione/*! 111*434716ceSJohn Scipione \fn ssize_t BSymLink::MakeLinkedPath(const char *dirPath, BPath *path) 112*434716ceSJohn Scipione \brief Combines a directory path and the contents of this symbolic link to 113*434716ceSJohn Scipione form an absolute path. 114*434716ceSJohn Scipione 115*434716ceSJohn Scipione \param dirPath The base directory path to combine with the symbolic link. 116*434716ceSJohn Scipione \param path The BPath object to be set to the resulting absolute path. 117*434716ceSJohn Scipione 118*434716ceSJohn Scipione \return The length of the resulting path name or an error code. 119*434716ceSJohn Scipione \retval B_BAD_VALUE \a dirPath or \a path was \c NULL or the object didn't 120*434716ceSJohn Scipione refer to a symbolic link. 121*434716ceSJohn Scipione \retval B_FILE_ERROR The object was not initialized. 122*434716ceSJohn Scipione \retval B_NAME_TOO_LONG The resulting path name was too long to fit. 123*434716ceSJohn Scipione*/ 124*434716ceSJohn Scipione 125*434716ceSJohn Scipione 126*434716ceSJohn Scipione/*! 127*434716ceSJohn Scipione \fn ssize_t BSymLink::MakeLinkedPath(const BDirectory *dir, BPath *path) 128*434716ceSJohn Scipione \brief Combines a directory path and the contents of this symbolic link to 129*434716ceSJohn Scipione form an absolute path. 130*434716ceSJohn Scipione 131*434716ceSJohn Scipione \param dir The base BDirectory object to combine with the symbolic link. 132*434716ceSJohn Scipione \param path the BPath object to be set to the resulting absolute path. 133*434716ceSJohn Scipione 134*434716ceSJohn Scipione \return The length of the resulting path name or an error code. 135*434716ceSJohn Scipione \retval B_BAD_VALUE \a dir or \a path was \c NULL or the object didn't 136*434716ceSJohn Scipione refer to a symbolic link. 137*434716ceSJohn Scipione \retval B_FILE_ERROR The object was not initialized. 138*434716ceSJohn Scipione \retval B_NAME_TOO_LONG The resulting path name was too long to fit. 139*434716ceSJohn Scipione*/ 140*434716ceSJohn Scipione 141*434716ceSJohn Scipione 142*434716ceSJohn Scipione/*! 143*434716ceSJohn Scipione \fn bool BSymLink::IsAbsolute() 144*434716ceSJohn Scipione \brief Returns whether or not the object refers to an absolute path. 145*434716ceSJohn Scipione 146*434716ceSJohn Scipione /return \c true if the object is properly initialized and the symbolic 147*434716ceSJohn Scipione link refers to an absolute path, \c false otherwise. 148*434716ceSJohn Scipione*/ 149*434716ceSJohn Scipione 150*434716ceSJohn Scipione 151*434716ceSJohn Scipione/*! 152*434716ceSJohn Scipione \fn int BSymLink::get_fd() const 153*434716ceSJohn Scipione \brief Returns the file descriptor of the BSymLink. 154*434716ceSJohn Scipione 155*434716ceSJohn Scipione This method should be used instead of accessing the private \c fFd member 156*434716ceSJohn Scipione of the BNode directly. 157*434716ceSJohn Scipione 158*434716ceSJohn Scipione \return The object's file descriptor, or -1 if not properly initialized. 159*434716ceSJohn Scipione*/ 160