source: abuse/trunk/src/username.cpp @ 11

Last change on this file since 11 was 2, checked in by Sam Hocevar, 17 years ago
  • imported original 0.7.0 tarball
File size: 478 bytes
Line 
1#ifdef __WATCOMC__
2char *get_username() { return "DOS user"; }
3#elif (defined(__APPLE__) && !defined(__MACH__))
4char *get_username() { return "Mac user"; }
5#else
6 
7#include        <stdio.h>
8#include        <pwd.h>
9#include        <sys/types.h>
10#include        <unistd.h>
11
12char *get_username()
13{
14  struct passwd         *pw;
15  char                  *name;
16
17  if (!(name = getlogin()))
18  {
19    if ((pw = getpwuid (getuid())))
20      return pw->pw_name;
21    else
22      return "UNIX user";
23  } else return name;
24}
25
26#endif
27
28
Note: See TracBrowser for help on using the repository browser.