remove deprecations, minor changes
This commit is contained in:
1 parent
bdaaaaae58
commit
5fc58acaef
2 files changed
+12
-32
No files matched your search
@@ -10,15 +10,15 @@ $if windows {
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
__global pwd_mutex &sync.Mutex
|
__global pwd__mutex__ &sync.Mutex
|
||||||
|
|
||||||
fn init() {
|
fn init() {
|
||||||
pwd_mutex = sync.new_mutex()
|
pwd__mutex__ = sync.new_mutex()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup() {
|
fn cleanup() {
|
||||||
pwd_mutex.destroy()
|
pwd__mutex__.destroy()
|
||||||
unsafe { free(pwd_mutex) }
|
unsafe { free(pwd__mutex__) }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct C.passwd {
|
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)
|
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.
|
// user_by_uid returns the passwd database entry by user ID.
|
||||||
// If the entry is not found, the EntryNotFoundError error will be returned.
|
// If the entry is not found, the EntryNotFoundError error will be returned.
|
||||||
pub fn user_by_uid(uid int) !Passwd {
|
pub fn user_by_uid(uid int) !Passwd {
|
||||||
pwd_mutex.lock()
|
pwd__mutex__.lock()
|
||||||
defer {
|
defer {
|
||||||
pwd_mutex.unlock()
|
pwd__mutex__.unlock()
|
||||||
}
|
}
|
||||||
pw := C.getpwuid(uid)
|
pw := C.getpwuid(i32(uid))
|
||||||
if isnil(pw) {
|
if isnil(pw) {
|
||||||
return make_error('', uid)
|
return make_error('', uid)
|
||||||
}
|
}
|
||||||
return make_passwd(pw)
|
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.
|
// user_by_name returns the passwd database entry by user name.
|
||||||
// If the entry is not found, the EntryNotFoundError error will be returned.
|
// If the entry is not found, the EntryNotFoundError error will be returned.
|
||||||
pub fn user_by_name(name string) !Passwd {
|
pub fn user_by_name(name string) !Passwd {
|
||||||
pwd_mutex.lock()
|
pwd__mutex__.lock()
|
||||||
defer {
|
defer {
|
||||||
pwd_mutex.unlock()
|
pwd__mutex__.unlock()
|
||||||
}
|
}
|
||||||
pw := C.getpwnam(&char(name.str))
|
pw := C.getpwnam(&char(name.str))
|
||||||
if isnil(pw) {
|
if isnil(pw) {
|
||||||
@@ -116,20 +102,14 @@ pub fn user_by_name(name string) !Passwd {
|
|||||||
return make_passwd(pw)
|
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.
|
// users returns all entries from passwd database in arbitrary order.
|
||||||
pub fn users() ![]Passwd {
|
pub fn users() ![]Passwd {
|
||||||
mut pwds := []Passwd{}
|
mut pwds := []Passwd{}
|
||||||
pwd_mutex.lock()
|
pwd__mutex__.lock()
|
||||||
C.setpwent()
|
C.setpwent()
|
||||||
defer {
|
defer {
|
||||||
C.endpwent()
|
C.endpwent()
|
||||||
pwd_mutex.unlock()
|
pwd__mutex__.unlock()
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
pw := C.getpwent()
|
pw := C.getpwent()
|
||||||
|
|||||||
Reference in new issue
Block a user