Mercurial > hg > xemacs-beta
comparison src/editfns.c @ 294:4b85ae5eabfb r21-0b45
Import from CVS: tag r21-0b45
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:38:01 +0200 |
parents | e11d67e05968 |
children | 70ad99077275 |
comparison
equal
deleted
inserted
replaced
293:403535bfea94 | 294:4b85ae5eabfb |
---|---|
635 If the optional argument UID is present, then environment variables are | 635 If the optional argument UID is present, then environment variables are |
636 ignored and this function returns the login name for that UID, or nil. | 636 ignored and this function returns the login name for that UID, or nil. |
637 */ | 637 */ |
638 (uid)) | 638 (uid)) |
639 { | 639 { |
640 char *returned_name; | |
641 int local_uid; | |
642 | |
643 if (!NILP (uid)) | |
644 { | |
645 CHECK_INT (uid); | |
646 local_uid = XINT(uid); | |
647 returned_name = user_login_name(&local_uid); | |
648 } | |
649 else | |
650 { | |
651 returned_name = user_login_name(NULL); | |
652 } | |
653 /* #### - I believe this should return nil instead of "unknown" when pw==0 | |
654 pw=0 is indicated by a null return from user_login_name | |
655 */ | |
656 return returned_name ? build_string (returned_name) : Qnil; | |
657 } | |
658 | |
659 /* This function may be called from other C routines when a | |
660 character string representation of the user_login_name is | |
661 needed but a Lisp Object is not. The UID is passed by | |
662 reference. If UID == NULL, then the USER name | |
663 for the user running Xemacs will be returned. This | |
664 corresponds to a nil argument to Fuser_login_name. | |
665 */ | |
666 char* | |
667 user_login_name (uid) | |
668 int *uid; | |
669 { | |
640 struct passwd *pw = NULL; | 670 struct passwd *pw = NULL; |
641 | 671 |
642 if (!NILP (uid)) | 672 /* uid == NULL to return name of this user */ |
643 { | 673 if (uid != NULL) |
644 CHECK_INT (uid); | 674 { |
645 pw = getpwuid (XINT (uid)); | 675 pw = getpwuid (*uid); |
676 return pw ? pw->pw_name : NULL; | |
646 } | 677 } |
647 else | 678 else |
648 { | 679 { |
649 /* #### - when euid != uid, then LOGNAME and USER are leftovers from the | 680 /* #### - when euid != uid, then LOGNAME and USER are leftovers from the |
650 old environment (I site observed behavior on sunos and linux), so the | 681 old environment (I site observed behavior on sunos and linux), so the |
657 #else | 688 #else |
658 "USER" | 689 "USER" |
659 #endif | 690 #endif |
660 ); | 691 ); |
661 if (user_name) | 692 if (user_name) |
662 return build_string (user_name); | 693 return (user_name); |
663 else | 694 else |
664 pw = getpwuid (geteuid ()); | 695 { |
665 } | 696 pw = getpwuid (geteuid ()); |
666 /* #### - I believe this should return nil instead of "unknown" when pw==0 */ | 697 #ifdef __CYGWIN32__ |
667 return pw ? build_string (pw->pw_name) : Qnil; | 698 /* Since the Cygwin environment may not have an /etc/passwd, |
699 return "unknown" instead of the null if the username | |
700 cannot be determined. | |
701 */ | |
702 return pw ? pw->pw_name : "unknown"; | |
703 #else | |
704 /* For all but Cygwin return NULL (nil) */ | |
705 return pw ? pw->pw_name : NULL; | |
706 #endif | |
707 } | |
708 } | |
668 } | 709 } |
669 | 710 |
670 DEFUN ("user-real-login-name", Fuser_real_login_name, 0, 0, 0, /* | 711 DEFUN ("user-real-login-name", Fuser_real_login_name, 0, 0, 0, /* |
671 Return the name of the user's real uid, as a string. | 712 Return the name of the user's real uid, as a string. |
672 This ignores the environment variables LOGNAME and USER, so it differs from | 713 This ignores the environment variables LOGNAME and USER, so it differs from |