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

Last change on this file since 57 was 56, checked in by Sam Hocevar, 14 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 777 bytes
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *
5 *  This software was released into the Public Domain. As with most public
6 *  domain software, no warranty is made or implied by Crack dot Com or
7 *  Jonathan Clark.
8 */
9
10#include "config.h"
11
12#include <stdio.h>
13#include <pwd.h>
14#include <sys/types.h>
15#include <unistd.h>
16
17#ifdef __WATCOMC__
18char const *get_username() { return "DOS user"; }
19#elif (defined(__APPLE__) && !defined(__MACH__))
20char const *get_username() { return "Mac user"; }
21#else
22 
23char const *get_username()
24{
25  struct passwd *pw;
26  char const *name;
27
28  if (!(name = getlogin()))
29  {
30    if ((pw = getpwuid (getuid())))
31      return pw->pw_name;
32    else
33      return "UNIX user";
34  } else return name;
35}
36
37#endif
38
39
Note: See TracBrowser for help on using the repository browser.