Fix last change
* src/editfns.c (Fgroup_name): Fix the doc string. Move closer to the "group" functions. * src/w32.c (getgrgid): Return NULL if GID is not the group ID of the user of this Emacs session * test/src/editfns-tests.el (test-group-name): Rename from 'group-name'. Add tests for non-Posix hosts. Test error when the argument to group-name is invalid. * etc/NEWS: Fix wording of last added entry.
This commit is contained in:
parent
ffb4c76d99
commit
d6b7b60cd0
4 changed files with 35 additions and 23 deletions
2
etc/NEWS
2
etc/NEWS
|
@ -1264,7 +1264,7 @@ uses of this function all but disappeared by now, so we are
|
|||
un-obsoleting it.
|
||||
|
||||
+++
|
||||
** New function 'group-name' returns a group name based on a group-GID
|
||||
** New function 'group-name' returns a group name corresponding to GID.
|
||||
|
||||
|
||||
* Changes in Emacs 27.1 on Non-Free Operating Systems
|
||||
|
|
|
@ -1143,21 +1143,6 @@ of the user with that uid, or nil if there is no such user. */)
|
|||
return (pw ? build_string (pw->pw_name) : Qnil);
|
||||
}
|
||||
|
||||
DEFUN ("group-name", Fgroup_name, Sgroup_name, 1, 1, 0,
|
||||
doc: /* If argument GID is an integer or a float, return the login name
|
||||
of the group with that gid, or nil if there is no such GID. */)
|
||||
(Lisp_Object gid)
|
||||
{
|
||||
struct group *gr;
|
||||
gid_t id;
|
||||
|
||||
CONS_TO_INTEGER (gid, gid_t, id);
|
||||
block_input ();
|
||||
gr = getgrgid (id);
|
||||
unblock_input ();
|
||||
return (gr ? build_string (gr->gr_name) : Qnil);
|
||||
}
|
||||
|
||||
DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name,
|
||||
0, 0, 0,
|
||||
doc: /* Return the name of the user's real uid, as a string.
|
||||
|
@ -1191,6 +1176,24 @@ Value is a fixnum, if it's small enough, otherwise a bignum. */)
|
|||
return INT_TO_INTEGER (uid);
|
||||
}
|
||||
|
||||
DEFUN ("group-name", Fgroup_name, Sgroup_name, 1, 1, 0,
|
||||
doc: /* Return the name of the group whose numeric group ID is GID.
|
||||
The argument GID should be an integer or a float.
|
||||
Return nil if a group with such GID does not exists or is not known. */)
|
||||
(Lisp_Object gid)
|
||||
{
|
||||
struct group *gr;
|
||||
gid_t id;
|
||||
|
||||
if (!NUMBERP (gid) && !CONSP (gid))
|
||||
error ("Invalid GID specification");
|
||||
CONS_TO_INTEGER (gid, gid_t, id);
|
||||
block_input ();
|
||||
gr = getgrgid (id);
|
||||
unblock_input ();
|
||||
return gr ? build_string (gr->gr_name) : Qnil;
|
||||
}
|
||||
|
||||
DEFUN ("group-gid", Fgroup_gid, Sgroup_gid, 0, 0, 0,
|
||||
doc: /* Return the effective gid of Emacs.
|
||||
Value is a fixnum, if it's small enough, otherwise a bignum. */)
|
||||
|
|
|
@ -2043,7 +2043,9 @@ getpwuid (unsigned uid)
|
|||
struct group *
|
||||
getgrgid (gid_t gid)
|
||||
{
|
||||
return &dflt_group;
|
||||
if (gid == dflt_passwd.pw_gid)
|
||||
return &dflt_group;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct passwd *
|
||||
|
|
|
@ -351,11 +351,18 @@
|
|||
(should (equal (format "%-#50.40x" v3)
|
||||
"-0x000000003ffffffffffffffe000000000000000 "))))
|
||||
|
||||
(ert-deftest group-name ()
|
||||
(let ((list `((0 . "root")
|
||||
(1000 . ,(user-login-name 1000))
|
||||
(1212345 . nil))))
|
||||
(dolist (test list)
|
||||
(should (equal (group-name (car test)) (cdr test))))))
|
||||
(ert-deftest test-group-name ()
|
||||
(cond
|
||||
((memq system-type '(windows-nt ms-dos))
|
||||
(should (stringp (group-name (group-gid))))
|
||||
(should-not (group-name 123456789))
|
||||
(should-error (group-name 'foo)))
|
||||
(t
|
||||
(let ((list `((0 . "root")
|
||||
(1000 . ,(user-login-name 1000))
|
||||
(1212345 . nil))))
|
||||
(dolist (test list)
|
||||
(should (equal (group-name (car test)) (cdr test)))))
|
||||
(should-error (group-name 'foo)))))
|
||||
|
||||
;;; editfns-tests.el ends here
|
||||
|
|
Loading…
Add table
Reference in a new issue