.Sh SYNOPSIS
.In libgen.h
.Ft char *
-.Fn dirname "const char *path"
+.Fo dirname
+.Fa "char *path"
+.Fc
+.Ft char *
+.Fo dirname_r
+.Fa "const char *path" "char *dname"
+.Fc
.Sh DESCRIPTION
The
.Fn dirname
returns a pointer to internal storage space allocated on the first call
that will be overwritten
by subsequent calls.
+.Fn dirname_r
+is therefore preferred for threaded applications.
.Pp
Other vendor implementations of
.Fn dirname
may modify the contents of the string passed to
.Fn dirname ;
-this should be taken into account when writing code which calls this function
-if portability is desired.
+if portability is desired,
+this should be taken into account when writing code which calls this function.
+.Sh LEGACY SYNOPSIS
+.Fd #include <libgen.h>
+.Pp
+.Ft char *
+.br
+.Fo dirname
+.Fa "const char *path"
+.Fc ;
+.Pp
+In legacy mode,
+.Fa path
+will not be changed.
.Sh RETURN VALUES
On successful completion,
.Fn dirname
.It Bq Er ENAMETOOLONG
The path component to be returned was larger than
.Dv MAXPATHLEN .
+.It Bq Er ENOMEM
+The static buffer used for storing the path in
+.Fn dirname
+could not be allocated.
.El
.Sh SEE ALSO
.Xr basename 1 ,
.Xr dirname 1 ,
-.Xr basename 3
+.Xr basename 3 ,
+.Xr compat 5
.Sh STANDARDS
The
.Fn dirname
.Ox 2.2
and
.Fx 4.2 .
+The
+.Fn dirname_r
+function first appeared in OS X 10.12.
.Sh AUTHORS
.An "Todd C. Miller"