diff --git a/basis/unix/users/users-docs.factor b/basis/unix/users/users-docs.factor index 83e7e99481..0740561cc1 100644 --- a/basis/unix/users/users-docs.factor +++ b/basis/unix/users/users-docs.factor @@ -50,7 +50,7 @@ HELP: set-real-user HELP: user-passwd { $values { "obj" object } - { "passwd" passwd } } + { "passwd/f" "passwd or f" } } { $description "Returns the passwd tuple given a username string or user id." } ; HELP: username diff --git a/basis/unix/users/users-tests.factor b/basis/unix/users/users-tests.factor index 1113383635..5a4639c856 100644 --- a/basis/unix/users/users-tests.factor +++ b/basis/unix/users/users-tests.factor @@ -24,3 +24,7 @@ IN: unix.users.tests [ ] [ effective-user-id [ ] with-effective-user ] unit-test [ ] [ [ ] with-user-cache ] unit-test + +[ "9999999999999999999" ] [ 9999999999999999999 username ] unit-test + +[ f ] [ 89898989898989898989898989898 user-passwd ] unit-test diff --git a/basis/unix/users/users.factor b/basis/unix/users/users.factor index 78417c66bf..21538080c9 100644 --- a/basis/unix/users/users.factor +++ b/basis/unix/users/users.factor @@ -47,17 +47,18 @@ SYMBOL: user-cache : with-user-cache ( quot -- ) [ user-cache ] dip with-variable ; inline -GENERIC: user-passwd ( obj -- passwd ) +GENERIC: user-passwd ( obj -- passwd/f ) M: integer user-passwd ( id -- passwd/f ) user-cache get - [ at ] [ getpwuid passwd>new-passwd ] if* ; + [ at ] [ getpwuid [ passwd>new-passwd ] [ f ] if* ] if* ; M: string user-passwd ( string -- passwd/f ) getpwnam dup [ passwd>new-passwd ] when ; : username ( id -- string ) - user-passwd username>> ; + dup user-passwd + [ nip username>> ] [ number>string ] if* ; : user-id ( string -- id ) user-passwd uid>> ;