[comp.mail.elm] Minor Patch to from.c

mack@inco.UUCP (Dave Mack) (01/05/89)

Enclosed is a minor patch to from.c which makes frm use the
current username instead of the loginname when checking for
mail. This is convenient when you spend a lot of time su to
other usernames and makes the behavior of frm correspond to
elm's behavior. The patch also eliminates a redundant call
to getlogin.

CAVEATS: testing on this has been marginal. It relies on
USER being present in the environment. If USER is not
available, the behavior should duplicate the current
behavior. getenv("USER") is not the right way to do this;
it should use getpwname(geteuid) or some such thing, but
I have no idea how portable that would be. I leave it to
the developers to do it portably.

*** from.c~	Sat Dec 17 16:07:24 1988
--- from.c	Wed Jan  4 14:00:25 1989
***************
*** 59,64 ****
--- 59,65 ----
  {
  	char infile[LONG_SLEN], username[SLEN];
  	int  multiple_files = 0, output_files = 0, c;
+ 	char *usernameptr;
  
  	extern int opt_index;
  
***************
*** 75,84 ****
  
  	infile[0] = '\0';
  	if (opt_index == argc) {
! 	  if (getlogin())
! 	    strcpy(username, getlogin());
! 	  if (strlen(username) == 0)
! 	    cuserid(username);
  	  sprintf(infile,"%s%s",mailhome, username);
  	  opt_index -= 1;	/* ensure one pass through loop */
  	}
--- 76,90 ----
  
  	infile[0] = '\0';
  	if (opt_index == argc) {
! 	  if ((usernameptr = getenv("USER")) != NULL) {
! 	    strcpy(username,usernameptr);
! 	  }
! 	  else {
! 	    if ((usernameptr = getlogin()) && strlen(usernameptr) > 0)
! 	      strcpy(username, usernameptr);
! 	    else 
! 	      cuserid(username);
! 	  }
  	  sprintf(infile,"%s%s",mailhome, username);
  	  opt_index -= 1;	/* ensure one pass through loop */
  	}