1434716ceSJohn Scipione/* 2b885e90eSJohn Scipione * Copyright 2002-2014 Haiku, Inc. All rights reserved. 3434716ceSJohn Scipione * Distributed under the terms of the MIT License. 4434716ceSJohn Scipione * 5434716ceSJohn Scipione * Authors: 6434716ceSJohn Scipione * Tyler Dauwalder 7434716ceSJohn Scipione * John Scipione, jscipione@gmail.com 8434716ceSJohn Scipione * Ingo Weinhold, bonefish@users.sf.net 9434716ceSJohn Scipione * 10434716ceSJohn Scipione * Corresponds to: 11b885e90eSJohn Scipione * headers/os/storage/SymLink.h hrev47402 12b885e90eSJohn Scipione * src/kits/storage/SymLink.cpp hrev47402 13434716ceSJohn Scipione */ 14434716ceSJohn Scipione 15434716ceSJohn Scipione 16434716ceSJohn Scipione/*! 177635a303SJohn Scipione \file SymLink.h 18434716ceSJohn Scipione \ingroup storage 19434716ceSJohn Scipione \ingroup libbe 20434716ceSJohn Scipione \brief Provides the BSymLink class. 21434716ceSJohn Scipione*/ 22434716ceSJohn Scipione 23434716ceSJohn Scipione 24434716ceSJohn Scipione/*! 25434716ceSJohn Scipione \class BSymLink 26434716ceSJohn Scipione \ingroup storage 27434716ceSJohn Scipione \ingroup libbe 28434716ceSJohn Scipione \brief Provides an interface for creating, manipulating, and accessing 29434716ceSJohn Scipione the contents of symbolic links. 30b885e90eSJohn Scipione 31b885e90eSJohn Scipione \since BeOS R3 32434716ceSJohn Scipione*/ 33434716ceSJohn Scipione 34434716ceSJohn Scipione 35434716ceSJohn Scipione/*! 36434716ceSJohn Scipione \fn BSymLink::BSymLink() 37434716ceSJohn Scipione \brief Creates an uninitialized BSymLink object. 38b885e90eSJohn Scipione 39b885e90eSJohn Scipione \since BeOS R3 40434716ceSJohn Scipione*/ 41434716ceSJohn Scipione 42434716ceSJohn Scipione 43434716ceSJohn Scipione/*! 44b885e90eSJohn Scipione \fn BSymLink::BSymLink(const BSymLink& other) 45434716ceSJohn Scipione \brief Creates a copy of the supplied BSymLink object. 46434716ceSJohn Scipione 47b885e90eSJohn Scipione \param other The BSymLink object to be copied. 48b885e90eSJohn Scipione 49b885e90eSJohn Scipione \since BeOS R3 50434716ceSJohn Scipione*/ 51434716ceSJohn Scipione 52434716ceSJohn Scipione 53434716ceSJohn Scipione/*! 54434716ceSJohn Scipione \fn BSymLink::BSymLink(const entry_ref* ref) 55434716ceSJohn Scipione \brief Creates a BSymLink object and initializes it to the symbolic link 56434716ceSJohn Scipione referred to by the supplied entry_ref. 57434716ceSJohn Scipione 58434716ceSJohn Scipione \param ref the entry_ref referring to the symbolic link. 59b885e90eSJohn Scipione 60b885e90eSJohn Scipione \since BeOS R3 61434716ceSJohn Scipione*/ 62434716ceSJohn Scipione 63434716ceSJohn Scipione 64434716ceSJohn Scipione/*! 65434716ceSJohn Scipione \fn BSymLink::BSymLink(const BEntry* entry) 66434716ceSJohn Scipione \brief Creates a BSymLink object and initializes it to the symbolic link 67434716ceSJohn Scipione referred to by the supplied BEntry. 68434716ceSJohn Scipione 69434716ceSJohn Scipione \param entry The BEntry referring to the symbolic link. 70b885e90eSJohn Scipione 71b885e90eSJohn Scipione \since BeOS R3 72434716ceSJohn Scipione*/ 73434716ceSJohn Scipione 74434716ceSJohn Scipione 75434716ceSJohn Scipione/*! 76434716ceSJohn Scipione \fn BSymLink::BSymLink(const char* path) 77434716ceSJohn Scipione \brief Creates a BSymLink object and initializes it to the symbolic link 78434716ceSJohn Scipione referred to by the supplied path name. 79434716ceSJohn Scipione 80434716ceSJohn Scipione \param path The path of the symbolic link. 81b885e90eSJohn Scipione 82b885e90eSJohn Scipione \since BeOS R3 83434716ceSJohn Scipione*/ 84434716ceSJohn Scipione 85434716ceSJohn Scipione 86434716ceSJohn Scipione/*! 87434716ceSJohn Scipione \fn BSymLink::BSymLink(const BDirectory* dir, const char* path) 88434716ceSJohn Scipione \brief Creates a BSymLink object and initializes it to the symbolic link 89434716ceSJohn Scipione referred to by the supplied path name relative to the specified 90434716ceSJohn Scipione BDirectory. 91434716ceSJohn Scipione 92434716ceSJohn Scipione \param dir The base BDirectory. 93434716ceSJohn Scipione \param path The path of the symbolic link relative to \a dir. 94b885e90eSJohn Scipione 95b885e90eSJohn Scipione \since BeOS R3 96434716ceSJohn Scipione*/ 97434716ceSJohn Scipione 98434716ceSJohn Scipione 99434716ceSJohn Scipione/*! 100434716ceSJohn Scipione \fn BSymLink::~BSymLink() 101434716ceSJohn Scipione \brief Destroys the object and frees all allocated resources. 102434716ceSJohn Scipione 103434716ceSJohn Scipione If the BSymLink was properly initialized, the file descriptor of the 104434716ceSJohn Scipione symbolic link is also closed. 105b885e90eSJohn Scipione 106b885e90eSJohn Scipione \since BeOS R3 107434716ceSJohn Scipione*/ 108434716ceSJohn Scipione 109434716ceSJohn Scipione 110434716ceSJohn Scipione/*! 111434716ceSJohn Scipione \fn ssize_t BSymLink::ReadLink(char* buffer, size_t size) 112434716ceSJohn Scipione \brief Reads the contents of the symbolic link into \a buffer. 113434716ceSJohn Scipione 114434716ceSJohn Scipione The string written to the buffer is guaranteed to be \c NULL terminated. 115434716ceSJohn Scipione 116*e1b7c1c7SKyle Ambroff-Kao This function does not return the number of bytes written into 117*e1b7c1c7SKyle Ambroff-Kao the provided buffer. It returns the length of the symlink's 118*e1b7c1c7SKyle Ambroff-Kao contents, even if that contents does not fit within the 119*e1b7c1c7SKyle Ambroff-Kao provided buffer. If the buffer cannot contain the entire 120*e1b7c1c7SKyle Ambroff-Kao contents then it will be truncated to \a size. 121*e1b7c1c7SKyle Ambroff-Kao 122434716ceSJohn Scipione \param buffer The buffer to read the symlink's contents into. 123434716ceSJohn Scipione \param size The size of \a buffer. 124434716ceSJohn Scipione 125*e1b7c1c7SKyle Ambroff-Kao \return The length of the symlink's contents or an error code. 126434716ceSJohn Scipione \retval B_BAD_VALUE \a buf was \c NULL or the object didn't refer to a 127434716ceSJohn Scipione symbolic link. 128434716ceSJohn Scipione \retval B_FILE_ERROR The object was not initialized. 129b885e90eSJohn Scipione 130b885e90eSJohn Scipione \since BeOS R3 131434716ceSJohn Scipione*/ 132434716ceSJohn Scipione 133434716ceSJohn Scipione 134434716ceSJohn Scipione/*! 135434716ceSJohn Scipione \fn ssize_t BSymLink::MakeLinkedPath(const char* dirPath, BPath* path) 136434716ceSJohn Scipione \brief Combines a directory path and the contents of this symbolic link to 137434716ceSJohn Scipione form an absolute path. 138434716ceSJohn Scipione 139434716ceSJohn Scipione \param dirPath The base directory path to combine with the symbolic link. 140434716ceSJohn Scipione \param path The BPath object to be set to the resulting absolute path. 141434716ceSJohn Scipione 142434716ceSJohn Scipione \return The length of the resulting path name or an error code. 143434716ceSJohn Scipione \retval B_BAD_VALUE \a dirPath or \a path was \c NULL or the object didn't 144434716ceSJohn Scipione refer to a symbolic link. 145434716ceSJohn Scipione \retval B_FILE_ERROR The object was not initialized. 146434716ceSJohn Scipione \retval B_NAME_TOO_LONG The resulting path name was too long to fit. 147b885e90eSJohn Scipione 148b885e90eSJohn Scipione \since BeOS R3 149434716ceSJohn Scipione*/ 150434716ceSJohn Scipione 151434716ceSJohn Scipione 152434716ceSJohn Scipione/*! 153434716ceSJohn Scipione \fn ssize_t BSymLink::MakeLinkedPath(const BDirectory* dir, BPath* path) 154434716ceSJohn Scipione \brief Combines a directory path and the contents of this symbolic link to 155434716ceSJohn Scipione form an absolute path. 156434716ceSJohn Scipione 157434716ceSJohn Scipione \param dir The base BDirectory object to combine with the symbolic link. 158434716ceSJohn Scipione \param path the BPath object to be set to the resulting absolute path. 159434716ceSJohn Scipione 160434716ceSJohn Scipione \return The length of the resulting path name or an error code. 161434716ceSJohn Scipione \retval B_BAD_VALUE \a dir or \a path was \c NULL or the object didn't 162434716ceSJohn Scipione refer to a symbolic link. 163434716ceSJohn Scipione \retval B_FILE_ERROR The object was not initialized. 164434716ceSJohn Scipione \retval B_NAME_TOO_LONG The resulting path name was too long to fit. 165b885e90eSJohn Scipione 166b885e90eSJohn Scipione \since BeOS R3 167434716ceSJohn Scipione*/ 168434716ceSJohn Scipione 169434716ceSJohn Scipione 170434716ceSJohn Scipione/*! 171434716ceSJohn Scipione \fn bool BSymLink::IsAbsolute() 172434716ceSJohn Scipione \brief Returns whether or not the object refers to an absolute path. 173434716ceSJohn Scipione 174434716ceSJohn Scipione /return \c true if the object is properly initialized and the symbolic 175434716ceSJohn Scipione link refers to an absolute path, \c false otherwise. 176434716ceSJohn Scipione 177b885e90eSJohn Scipione \since BeOS R3 178434716ceSJohn Scipione*/ 179