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
10#if WIN32
11
12
13WvString wv_username_from_uid(wvuid_t uid)
14{
15 // FIXME not implemented
16 return WvString::null;
17}
18
19
20wvuid_t wv_uid_from_username(WvString username)
21{
22 // FIXME not implemented
23 return WVUID_INVALID;
24}
25
26
27wvuid_t wvgetuid()
28{
29 // FIXME not implemented
30 return WVUID_INVALID;
31}
32
33
34#else // not WIN32
35
36#include <unistd.h>
37
38WvString wv_username_from_uid(wvuid_t uid)
39{
40 char buf[1024];
41 struct passwd pwbuf, *userinfo;
42
43 if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &userinfo) == 0)
44 return userinfo->pw_name;
45 else
46 return WvString::null;
47}
48
49
50wvuid_t wv_uid_from_username(WvString username)
51{
52 char buf[1024];
53 struct passwd pwbuf, *userinfo;
54
55 if (getpwnam_r(username, &pwbuf, buf, sizeof(buf), &userinfo) != 0)
56 return userinfo->pw_uid;
57 else
58 return WVUID_INVALID;
59}
60
61
62wvuid_t wvgetuid()
63{
64 return getuid();
65}
66
67
68#endif
WvString is an implementation of a simple and efficient printable-string class.
Definition wvstring.h:330