remove deprecations, minor changes

This commit is contained in:
ge committed 2026-10-30 02:48:41 +03:00
1 parent bdaaaaae58
commit 5fc58acaef
2 files changed
+12 -32

No files matched your search

+11 -31
View File
@@ -10,15 +10,15 @@ $if windows {
#include <errno.h>
#include <pwd.h>
__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()