©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ux/uxsystem.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00003     May be copied only for purposes and under conditions described
00004     on the Web page www.basepath.com/aup/copyright.htm.
00005 
00006     The Example Files are provided "as is," without any warranty;
00007     without even the implied warranty of merchantability or fitness
00008     for a particular purpose. The author and his publisher are not
00009     responsible for any damages, direct or incidental, resulting
00010     from the use or non-use of these Example Files.
00011 
00012     The Example Files may contain defects, and some contain deliberate
00013     coding mistakes that were included for educational reasons.
00014     You are responsible for determining if and how the Example Files
00015     are to be used.
00016 
00017 */
00018 #include "ux.hpp"
00019 
00020 using namespace Ux;
00021 
00022 /**
00023     Calls confstr.
00024 */
00025 /* static */ size_t System::confstr(int name, char *buf, size_t len, long default_val)
00026 {
00027     size_t r;
00028 
00029     errno = 0;
00030     r = ::confstr(name, buf, len);
00031     if (r == 0) {
00032         if (errno != 0)
00033             throw Error(errno);
00034         else
00035             r = default_val;
00036     }
00037     return r;
00038 }
00039 
00040 /**
00041     Calls gethostname.
00042 */
00043 /* static */ void System::gethostname(char *name, size_t namelen)
00044 {
00045     if (::gethostname(name, namelen) == -1)
00046         throw Error(errno);
00047 }
00048 
00049 /**
00050     Calls sysconf.
00051 */
00052 /* static */ long System::sysconf(int name, long default_val)
00053 {
00054     long r;
00055 
00056     errno = 0;
00057     r = ::sysconf(name);
00058     if (r == -1) {
00059         if (errno != 0)
00060             throw Error(errno);
00061         else
00062             r = default_val;
00063     }
00064     return r;
00065 }
00066 
00067 /**
00068     Calls uname.
00069 */
00070 /* static */ void System::uname(struct utsname *name)
00071 {
00072     if (::uname(name) == -1)
00073         throw Error(errno);
00074 }
00075 
00076 /**
00077     Calls getgrgid.
00078 */
00079 /* static */ struct group *System::getgrgid(gid_t gid)
00080 {
00081     struct group *p;
00082 
00083     if ((p = ::getgrgid(gid)) == NULL)
00084         throw Error(errno);
00085     return p;
00086 }
00087 
00088 /**
00089     Calls getlogin.
00090 */
00091 /* static */ char *System::getlogin(void)
00092 {
00093     char *p;
00094 
00095     if ((p = ::getlogin()) == NULL)
00096         throw Error(errno);
00097     return p;
00098 }
00099 
00100 /**
00101     Calls getpwuid.
00102 */
00103 /* static */ struct passwd *System::getpwuid(uid_t uid)
00104 {
00105     struct passwd *p;
00106 
00107     if ((p = ::getpwuid(uid)) == NULL)
00108         throw Error(errno);
00109     return p;
00110 }

Generated on Fri Apr 23 10:57:06 2004 for AUP2 Example Source by doxygen 1.3.1