From 0c111e2b51cac7eead56494b30c5977e4ec9a8ea Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 Mar 1998 13:40:57 +0000 Subject: Import cvs-1.9.26 onto vendor branch --- contrib/cvs/src/subr.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'contrib/cvs/src/subr.c') diff --git a/contrib/cvs/src/subr.c b/contrib/cvs/src/subr.c index 61b3103..07d516f 100644 --- a/contrib/cvs/src/subr.c +++ b/contrib/cvs/src/subr.c @@ -288,18 +288,13 @@ increment_revnum (rev) /* Return the username by which the caller should be identified in CVS, in contexts such as the author field of RCS files, various - logs, etc. - - Returns a pointer to storage that we manage; it is good until the - next call to getcaller () (provided that the caller doesn't call - getlogin () or some such themself). */ + logs, etc. */ char * getcaller () { #ifndef SYSTEM_GETCALLER - static char uidname[20]; + static char *cache; struct passwd *pw; - char *name; uid_t uid; #endif @@ -316,20 +311,32 @@ getcaller () try LOGNAME USER or getlogin(). If getlogin() and getpwuid() both fail, return the uid as a string. */ + if (cache != NULL) + return cache; + uid = getuid (); if (uid == (uid_t) 0) { + char *name; + /* super-user; try getlogin() to distinguish */ if (((name = getlogin ()) || (name = getenv("LOGNAME")) || (name = getenv("USER"))) && *name) - return (name); + { + cache = xstrdup (name); + return cache; + } } if ((pw = (struct passwd *) getpwuid (uid)) == NULL) { + char uidname[20]; + (void) sprintf (uidname, "uid%lu", (unsigned long) uid); - return (uidname); + cache = xstrdup (uidname); + return cache; } - return (pw->pw_name); + cache = xstrdup (pw->pw_name); + return cache; #endif } @@ -608,8 +615,16 @@ get_file (name, fullname, mode, buf, bufsize, len) } else { - if (CVS_STAT (name, &s) < 0) + if (CVS_LSTAT (name, &s) < 0) error (1, errno, "can't stat %s", fullname); + + /* Don't attempt to read special files or symlinks. */ + if (!S_ISREG (s.st_mode)) + { + *len = 0; + return; + } + /* Convert from signed to unsigned. */ filesize = s.st_size; -- cgit v1.1