WvStreams
|
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * Portable standins for getuid() and friends. See wvuid.h. 00006 */ 00007 #include "wvautoconf.h" 00008 #include "wvuid.h" 00009 00010 #if WIN32 00011 00012 00013 WvString wv_username_from_uid(wvuid_t uid) 00014 { 00015 // FIXME not implemented 00016 return WvString::null; 00017 } 00018 00019 00020 wvuid_t wv_uid_from_username(WvString username) 00021 { 00022 // FIXME not implemented 00023 return WVUID_INVALID; 00024 } 00025 00026 00027 wvuid_t wvgetuid() 00028 { 00029 // FIXME not implemented 00030 return WVUID_INVALID; 00031 } 00032 00033 00034 #else // not WIN32 00035 00036 #include <unistd.h> 00037 00038 WvString wv_username_from_uid(wvuid_t uid) 00039 { 00040 char buf[1024]; 00041 struct passwd pwbuf, *userinfo; 00042 00043 if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &userinfo) == 0) 00044 return userinfo->pw_name; 00045 else 00046 return WvString::null; 00047 } 00048 00049 00050 wvuid_t wv_uid_from_username(WvString username) 00051 { 00052 char buf[1024]; 00053 struct passwd pwbuf, *userinfo; 00054 00055 if (getpwnam_r(username, &pwbuf, buf, sizeof(buf), &userinfo) != 0) 00056 return userinfo->pw_uid; 00057 else 00058 return WVUID_INVALID; 00059 } 00060 00061 00062 wvuid_t wvgetuid() 00063 { 00064 return getuid(); 00065 } 00066 00067 00068 #endif