aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-php-shim/src/lib.rs')
-rw-r--r--crates/shirabe-php-shim/src/lib.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs
index 609d320..362e20f 100644
--- a/crates/shirabe-php-shim/src/lib.rs
+++ b/crates/shirabe-php-shim/src/lib.rs
@@ -1053,8 +1053,17 @@ pub fn json_encode<T: serde::Serialize + ?Sized>(_value: &T) -> Option<String> {
todo!()
}
-pub fn dirname(_path: &str) -> String {
- todo!()
+pub fn dirname(path: &str) -> String {
+ if path.is_empty() {
+ return String::new();
+ }
+ match std::path::Path::new(path).parent() {
+ // No parent: the root itself, or a path made up solely of slashes.
+ None => "/".to_string(),
+ // Path::parent yields an empty path where PHP's dirname returns ".".
+ Some(parent) if parent.as_os_str().is_empty() => ".".to_string(),
+ Some(parent) => parent.to_str().expect("input was valid UTF-8").to_string(),
+ }
}
pub fn stream_get_contents(_stream: PhpMixed) -> Option<String> {