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

Last change on this file since 48 was 39, checked in by Sam Hocevar, 14 years ago
  • Fix almost 2,000 warnings by using proper "const" keywords where needed.
File size: 499 bytes
RevLine 
[2]1#ifdef __WATCOMC__
[39]2char const *get_username() { return "DOS user"; }
[2]3#elif (defined(__APPLE__) && !defined(__MACH__))
[39]4char const *get_username() { return "Mac user"; }
[2]5#else
6 
7#include        <stdio.h>
8#include        <pwd.h>
9#include        <sys/types.h>
10#include        <unistd.h>
11
[39]12char const *get_username()
[2]13{
[39]14  struct passwd *pw;
15  char const *name;
[2]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.