Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TestOS.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 
00003 // This file is part of Vesta.
00004 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Tue Nov 16 01:40:37 EST 2004 by ken@xorian.net
00020 //      modified on Mon May  3 15:54:28 PDT 1999 by heydon 
00021 //      modified on Fri May 19 09:15:40 PDT 1995 by levin 
00022 
00023 // TestOS -- tests the OS interface utility routines
00024 
00025 #include <netdb.h>
00026 #include <Basics.H>
00027 #include "OS.H"
00028 #include "FS.H"
00029 
00030 using std::cout;
00031 using std::endl;
00032 
00033 int main()
00034 {
00035   static struct hostent *hp;
00036   char hostname[MAXHOSTNAMELEN+1];
00037   sockaddr_in hostsock;
00038 
00039   if (gethostname(hostname, sizeof(hostname)-1) == SYSERROR)
00040     return errno;
00041 
00042   cout << "My hostname is " << hostname << "\n";
00043 
00044   if ((hp = gethostbyname(hostname)) == NULL)
00045     return errno;
00046 
00047   bzero((char *)&hostsock, sizeof(hostsock));
00048   memcpy((char *)&(hostsock.sin_addr.s_addr), hp->h_addr, hp->h_length);
00049   endhostent();
00050 
00051   cout << "My IP address is " << inet_ntoa_r(hostsock.sin_addr) << "\n";
00052 
00053   // Note: The tests of FS::Exists/IsDirectory/IsFile are a little
00054   // UNIX-specific
00055 
00056   if(FS::IsDirectory("/"))
00057     {
00058       cout << "FS::IsDirectory seems to work" << endl;
00059     }
00060   else
00061     {
00062       cout << "FS::IsDirectory(\"/\") returned false" << endl;
00063       return errno || 1;
00064     }
00065 
00066   if(FS::IsFile("/etc/passwd"))
00067     {
00068       cout << "FS::IsFile seems to work" << endl;
00069     }
00070   else
00071     {
00072       cout << "FS::IsFile(\"/etc/passwd\") returned false" << endl;
00073       return errno || 1;
00074     }
00075 
00076   if(FS::Exists("/dev/null") && !FS::IsDirectory("/dev/null") && !FS::IsFile("/dev/null"))
00077     {
00078       cout << "FS::Exists seems to work" << endl;
00079     }
00080   else
00081     {
00082       cout << "Problem with FS::Exists/IsDirectory/IsFile test on /dev/null" << endl;
00083       return errno || 1;
00084     }
00085 
00086   unsigned long total, resident;
00087   OS::GetProcessSize(total, resident);
00088   cout << "Total process size:    " << total << endl
00089        << "Resident process size: " << resident << endl;
00090 
00091   return 0;
00092 }
00093 
00094   

Generated on Mon May 8 00:48:30 2006 for Vesta by  doxygen 1.4.2