-
Notifications
You must be signed in to change notification settings - Fork 0
/
portab.c
42 lines (38 loc) · 1 KB
/
portab.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Glue code - Things that have to be done differently on certain OSs
* vim:set cin sm ts=8 sw=4 sts=4: - Sec <[email protected]>
* $Id: portab.c,v 1.2 2004/06/22 21:30:43 sec Exp $
*/
#include "brillion.h"
#ifdef __WIN32__
#include <windows.h>
#else
#include <pwd.h>
#endif
/* Get (short) Name of the logged in User */
#ifdef __WIN32__
/* This uses a static buffer - NOT Reentrant */
char * getuser(void){
static char acUserName[100];
DWORD nUserName = sizeof(acUserName);
if (GetUserName(acUserName, &nUserName)) {
return(acUserName);
} else {
fprintf(stderr,"Failed to lookup user name, error code %lu.\n", GetLastError());
}
return("<fail>");
}
#else
/* I found no doc if I have to free the (struct passwd*) - peeking in FreeBSDs
* libc makes me think it is static, and thus not to be freed.
*/
char * getuser(void){
struct passwd* pw;
pw=getpwuid(getuid());
if(pw){
return(pw->pw_name);
}else{
fprintf(stderr,"Failed to get login name.\n");
return("<fail>");
};
};
#endif