utgetuser.c

来自「程序涵盖了设计FIR滤器的各种方法」· C语言 代码 · 共 87 行

C
87
字号
/*-------------- Telecommunications & Signal Processing Lab ---------------                             McGill UniversityRoutine:  char *UTgetUser (void)Purpose:  Get the user nameDescription:  This routine returns the user name.  The user name is determined by using  the user id to find the name in the password database with this uid.  For  systems that do not support the password database, the user name is taken  from the environment variables USER, LOGNAME or USERNAME.Parameters:  <-  char UTgetUser[]      Pointer to a character string containing the user name.  This string is      null terminated.  This is a pointer to an internal static storage area;      each call to this routine overlays this storage.Author / revision:  P. Kabal  Copyright (C) 2000  $Revision: 1.17 $  $Date: 2000/07/20 22:33:37 $-------------------------------------------------------------------------*/static char rcsid[] = "$Id: UTgetUser.c 1.17 2000/07/20 FilterDesign-v4r0a $";#include <stdlib.h>	/* getenv */#include <libtsp.h>#include <libtsp/nucleus.h>#include <libtsp/sysOS.h>#include <libtsp/UTmsg.h>#if (SY_POSIX)#  include <unistd.h>		/* getuid definitions */#  include <pwd.h>		/* password entry definitions */#endif#define NELEM(array)	((sizeof array) / (sizeof array[0]))/* The user name is at most 8 characters long on many Unix systems */#define MAXLEN	16static const char *UserEnv[] = { "USER", "LOGNAME", "USERNAME" };#define NENV	NELEM(UserEnv)char *UTgetUser (void){  static char User[MAXLEN+1];  char *p;  int i;#if (SY_POSIX)  struct passwd *pwd;/*   Find the password entry associated with the uid.  Using environment   variables such as USER does not work consistently since not all shells set   these environment variables for the user.*/  pwd = getpwuid (getuid ());  if (pwd != NULL) {    STcopyMax (pwd->pw_name, User, MAXLEN);    return User;  }#endif  User[0] = '\0';  for (i = 0; i < NENV; ++i) {    p = getenv (UserEnv[i]);    if (p != NULL) {      STcopyMax (p, User, MAXLEN);      break;    }  }  return User;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?