WvStreams
wvuid.cc
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * Portable standins for getuid() and friends. See wvuid.h.
6  */
7 #include "wvautoconf.h"
8 #include "wvuid.h"
9 #include <unistd.h>
10 #include <sys/types.h>
11 
12 #if WIN32
13 
14 
15 WvString wv_username_from_uid(wvuid_t uid)
16 {
17  // FIXME not implemented
18  return WvString::null;
19 }
20 
21 
22 wvuid_t wv_uid_from_username(WvString username)
23 {
24  // FIXME not implemented
25  return WVUID_INVALID;
26 }
27 
28 
29 wvuid_t wvgetuid()
30 {
31  // FIXME not implemented
32  return WVUID_INVALID;
33 }
34 
35 
36 #else // not WIN32
37 
38 
39 WvString wv_username_from_uid(wvuid_t uid)
40 {
41  char buf[1024];
42  struct passwd pwbuf, *userinfo;
43 
44  if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &userinfo) == 0)
45  return userinfo->pw_name;
46  else
47  return WvString::null;
48 }
49 
50 
51 wvuid_t wv_uid_from_username(WvString username)
52 {
53  char buf[1024];
54  struct passwd pwbuf, *userinfo;
55 
56  if (getpwnam_r(username, &pwbuf, buf, sizeof(buf), &userinfo) != 0)
57  return userinfo->pw_uid;
58  else
59  return WVUID_INVALID;
60 }
61 
62 
63 wvuid_t wvgetuid()
64 {
65  return getuid();
66 }
67 
68 
69 #endif
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329