diff --git a/README.md b/README.md index ef0579d..fb8ed44 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Access to the UNIX Password Database -`pwd` module provides thread-safe access to the UNIX user account and password +`pwdb` module provides thread-safe access to the UNIX user account and password database. See [passwd(5)](https://man7.org/linux/man-pages/man5/passwd.5.html), diff --git a/pwd.c.v b/pwdb.c.v similarity index 89% rename from pwd.c.v rename to pwdb.c.v index 8545ac4..3b97e56 100644 --- a/pwd.c.v +++ b/pwdb.c.v @@ -1,24 +1,24 @@ @[has_globals] -module pwd +module pwdb import sync $if windows { - $compile_error('pwd: MS Windows is not supported') + $compile_error('pwdb: MS Windows is not supported') } #include #include -__global pwd_mutex &sync.Mutex +__global pwdb_mutex &sync.Mutex fn init() { - pwd_mutex = sync.new_mutex() + pwdb_mutex = sync.new_mutex() } fn cleanup() { - pwd_mutex.destroy() - unsafe { free(pwd_mutex) } + pwdb_mutex.destroy() + unsafe { free(pwdb_mutex) } } struct C.passwd { @@ -77,9 +77,9 @@ 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. pub fn get_by_uid(uid int) !Passwd { - pwd_mutex.lock() + pwdb_mutex.lock() defer { - pwd_mutex.unlock() + pwdb_mutex.unlock() } pw := C.getpwuid(uid) if isnil(pw) { @@ -91,9 +91,9 @@ pub fn get_by_uid(uid int) !Passwd { // get_by_uid returns the passwd database entry by user name. // If the entry is not found, the EntryNotFoundError error will be returned. pub fn get_by_name(name string) !Passwd { - pwd_mutex.lock() + pwdb_mutex.lock() defer { - pwd_mutex.unlock() + pwdb_mutex.unlock() } pw := C.getpwnam(&char(name.str)) if isnil(pw) { @@ -105,11 +105,11 @@ pub fn get_by_name(name string) !Passwd { // get_all returns all entries from passwd database in arbitrary order. pub fn get_all() []Passwd { mut pwds := []Passwd{} - pwd_mutex.lock() + pwdb_mutex.lock() C.setpwent() defer { C.endpwent() - pwd_mutex.unlock() + pwdb_mutex.unlock() } for { pw := C.getpwent() diff --git a/pwd_test.v b/pwdb_test.v similarity index 63% rename from pwd_test.v rename to pwdb_test.v index 376e0ef..c3cdab3 100644 --- a/pwd_test.v +++ b/pwdb_test.v @@ -1,17 +1,17 @@ // vtest build: !windows -import pwd +import pwdb fn test_get_by_uid() { - pw := pwd.get_by_uid(0)! + pw := pwdb.get_by_uid(0)! assert pw.name == 'root' } fn test_get_by_name() { - pw := pwd.get_by_name('root')! + pw := pwdb.get_by_name('root')! assert pw.uid == 0 } fn test_get_all() { - pws := pwd.get_all() + pws := pwdb.get_all() assert pws.len > 0 } diff --git a/v.mod b/v.mod index f90418f..acf8511 100644 --- a/v.mod +++ b/v.mod @@ -1,5 +1,5 @@ Module { - name: 'pwd' + name: 'pwdb' description: 'Access to the UNIX password database' version: '0.1.0' license: 'Unlicense'