diff --git a/pwd.c.v b/pwd.c.v index 8545ac4..3dedd0c 100644 --- a/pwd.c.v +++ b/pwd.c.v @@ -76,7 +76,14 @@ fn make_error(name string, uid int) IError { // get_by_uid returns the passwd database entry by user ID. // If the entry is not found, the EntryNotFoundError error will be returned. +@[deprecated: 'use user_by_uid() instead'] pub fn get_by_uid(uid int) !Passwd { + return user_by_uid(uid)! +} + +// user_by_uid returns the passwd database entry by user ID. +// If the entry is not found, the EntryNotFoundError error will be returned. +pub fn user_by_uid(uid int) !Passwd { pwd_mutex.lock() defer { pwd_mutex.unlock() @@ -88,9 +95,16 @@ pub fn get_by_uid(uid int) !Passwd { return make_passwd(pw) } -// get_by_uid returns the passwd database entry by user name. +// get_by_name returns the passwd database entry by user name. // If the entry is not found, the EntryNotFoundError error will be returned. +@[deprecated: 'use user_by_name() instead'] pub fn get_by_name(name string) !Passwd { + return user_by_name(name)! +} + +// user_by_name returns the passwd database entry by user name. +// If the entry is not found, the EntryNotFoundError error will be returned. +pub fn user_by_name(name string) !Passwd { pwd_mutex.lock() defer { pwd_mutex.unlock() @@ -103,7 +117,13 @@ pub fn get_by_name(name string) !Passwd { } // get_all returns all entries from passwd database in arbitrary order. +@[deprecated: 'use users() instead'] pub fn get_all() []Passwd { + return users() or { []Passwd{} } +} + +// users returns all entries from passwd database in arbitrary order. +pub fn users() ![]Passwd { mut pwds := []Passwd{} pwd_mutex.lock() C.setpwent() @@ -113,6 +133,10 @@ pub fn get_all() []Passwd { } for { pw := C.getpwent() + err := make_error('', -1) + if err.code() != 0 { + return err + } if isnil(pw) { break } diff --git a/pwd_test.v b/pwd_test.v index 376e0ef..42aa728 100644 --- a/pwd_test.v +++ b/pwd_test.v @@ -1,17 +1,17 @@ // vtest build: !windows import pwd -fn test_get_by_uid() { - pw := pwd.get_by_uid(0)! +fn test_user_by_uid() { + pw := pwd.user_by_uid(0)! assert pw.name == 'root' } -fn test_get_by_name() { - pw := pwd.get_by_name('root')! +fn test_user_by_name() { + pw := pwd.user_by_name('root')! assert pw.uid == 0 } -fn test_get_all() { - pws := pwd.get_all() +fn test_users() { + pws := pwd.users()! assert pws.len > 0 } diff --git a/v.mod b/v.mod index f90418f..111ad85 100644 --- a/v.mod +++ b/v.mod @@ -1,7 +1,7 @@ Module { name: 'pwd' description: 'Access to the UNIX password database' - version: '0.1.0' + version: '0.2.0' license: 'Unlicense' dependencies: [] }