2 * Copyright 2002-2009 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
7 * Ingo Weinhold, ingo_weinhold@gmx.de
15 #include <Directory.h>
21 #include "storage_support.h"
27 // Creates an uninitialized BSymLink object.
33 // Creates a copy of the supplied BSymLink object.
34 BSymLink::BSymLink(const BSymLink
& other
)
41 // Creates a BSymLink object and initializes it to the symbolic link referred
42 // to by the supplied entry_ref.
43 BSymLink::BSymLink(const entry_ref
* ref
)
50 // Creates a BSymLink object and initializes it to the symbolic link referred
51 // to by the supplied BEntry.
52 BSymLink::BSymLink(const BEntry
* entry
)
58 // Creates a BSymLink object and initializes it to the symbolic link referred
59 // to by the supplied path name.
60 BSymLink::BSymLink(const char* path
)
67 // Creates a BSymLink object and initializes it to the symbolic link referred
68 // to by the supplied path name relative to the specified BDirectory.
69 BSymLink::BSymLink(const BDirectory
* dir
, const char* path
)
76 // Destroys the object and frees all allocated resources.
82 // Reads the contents of the symbolic link into a buffer.
84 BSymLink::ReadLink(char* buffer
, size_t size
)
89 if (InitCheck() != B_OK
)
92 size_t linkLen
= size
;
93 status_t result
= _kern_read_link(get_fd(), NULL
, buffer
, &linkLen
);
99 return B_BUFFER_OVERFLOW
;
101 buffer
[linkLen
] = '\0';
107 // Combines a directory path and the contents of this symbolic link to form an
110 BSymLink::MakeLinkedPath(const char* dirPath
, BPath
* path
)
112 // BeOS seems to convert the dirPath to a BDirectory, which causes links
113 // to be resolved. This means that the dirPath must exist!
114 if (dirPath
== NULL
|| path
== NULL
)
117 BDirectory
dir(dirPath
);
118 ssize_t result
= dir
.InitCheck();
120 result
= MakeLinkedPath(&dir
, path
);
126 // Combines a directory path and the contents of this symbolic link to form an
129 BSymLink::MakeLinkedPath(const BDirectory
* dir
, BPath
* path
)
131 if (dir
== NULL
|| path
== NULL
)
134 char contents
[B_PATH_NAME_LENGTH
];
135 ssize_t result
= ReadLink(contents
, sizeof(contents
));
137 if (BPrivate::Storage::is_absolute_path(contents
))
138 result
= path
->SetTo(contents
);
140 result
= path
->SetTo(dir
, contents
);
143 result
= strlen(path
->Path());
150 // Returns whether or not the object refers to an absolute path.
152 BSymLink::IsAbsolute()
154 char contents
[B_PATH_NAME_LENGTH
];
155 bool result
= (ReadLink(contents
, sizeof(contents
)) >= 0);
157 result
= BPrivate::Storage::is_absolute_path(contents
);
163 void BSymLink::_MissingSymLink1() {}
164 void BSymLink::_MissingSymLink2() {}
165 void BSymLink::_MissingSymLink3() {}
166 void BSymLink::_MissingSymLink4() {}
167 void BSymLink::_MissingSymLink5() {}
168 void BSymLink::_MissingSymLink6() {}
171 /*! Returns the file descriptor of the BSymLink.
173 This method should be used instead of accessing the private \c fFd member
174 of the BNode directly.
176 \return The object's file descriptor, or -1 if not properly initialized.
179 BSymLink::get_fd() const