diff --git a/pwd.c.v b/pwd.c.v index 3dedd0c..6cc5bd6 100644 --- a/pwd.c.v +++ b/pwd.c.v @@ -10,15 +10,15 @@ $if windows { #include #include -__global pwd_mutex &sync.Mutex +__global pwd__mutex__ &sync.Mutex fn init() { - pwd_mutex = sync.new_mutex() + pwd__mutex__ = sync.new_mutex() } fn cleanup() { - pwd_mutex.destroy() - unsafe { free(pwd_mutex) } + pwd__mutex__.destroy() + unsafe { free(pwd__mutex__) } } struct C.passwd { @@ -74,40 +74,26 @@ fn make_error(name string, uid int) IError { return error_with_code(c_error_number_str(err), err) } -// 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() + pwd__mutex__.lock() defer { - pwd_mutex.unlock() + pwd__mutex__.unlock() } - pw := C.getpwuid(uid) + pw := C.getpwuid(i32(uid)) if isnil(pw) { return make_error('', uid) } return make_passwd(pw) } -// 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() + pwd__mutex__.lock() defer { - pwd_mutex.unlock() + pwd__mutex__.unlock() } pw := C.getpwnam(&char(name.str)) if isnil(pw) { @@ -116,20 +102,14 @@ pub fn user_by_name(name string) !Passwd { return make_passwd(pw) } -// 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() + pwd__mutex__.lock() C.setpwent() defer { C.endpwent() - pwd_mutex.unlock() + pwd__mutex__.unlock() } for { pw := C.getpwent() diff --git a/v.mod b/v.mod index 111ad85..3e1850e 100644 --- a/v.mod +++ b/v.mod @@ -1,7 +1,7 @@ Module { name: 'pwd' description: 'Access to the UNIX password database' - version: '0.2.0' + version: '0.3.0' license: 'Unlicense' dependencies: [] }