Last change
on this file since 18 was
2,
checked in by Sam Hocevar, 17 years ago
|
- imported original 0.7.0 tarball
|
File size:
478 bytes
|
Rev | Line | |
---|
[2] | 1 | #ifdef __WATCOMC__ |
---|
| 2 | char *get_username() { return "DOS user"; } |
---|
| 3 | #elif (defined(__APPLE__) && !defined(__MACH__)) |
---|
| 4 | char *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 | |
---|
| 12 | char *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.