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
11#if WIN32
12
13
14WvString wv_username_from_uid(wvuid_t uid)
15{
16 // FIXME not implemented
17 return WvString::null;
18}
19
20
21wvuid_t wv_uid_from_username(WvString username)
22{
23 // FIXME not implemented
24 return WVUID_INVALID;
25}
26
27
28wvuid_t wvgetuid()
29{
30 // FIXME not implemented
31 return WVUID_INVALID;
32}
33
34
35#else // not WIN32
36
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