• Main Page
  • Modules
  • Classes
  • Files
  • File List
  • File Members

wvpushdir.h

00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Tunnel Vision Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * WvPushDir -- A simple class to check the existance of a dir 
00006  *  and to properly return the formatted path of the diir
00007  */
00008 #ifndef __WVPUSHDIR_H
00009 #define __WVPUSHDIR_H
00010 
00011 #include "wverror.h"
00012 
00013 #include <sys/types.h>
00014 #include <dirent.h>
00015 #include <errno.h>
00016 
00017 #include <unistd.h>
00018 
00019 class WvPushDir : public WvError
00020 {
00021     DIR *dir_handle;
00022     char *old_dir;
00023 
00024 public:
00025     void* operator new(size_t) 
00026         { abort(); }
00027 
00028     WvPushDir(WvStringParm new_dir)
00029     {
00030 #ifdef MACOS
00031        old_dir = static_cast<char *>(calloc(PATH_MAX, sizeof(char *)));
00032        getcwd(old_dir, PATH_MAX);;
00033 #else
00034        old_dir = get_current_dir_name();
00035 #endif
00036        dir_handle = opendir(old_dir);
00037        if (chdir(new_dir) == -1)
00038           errnum = errno;
00039     }
00040 
00041     ~WvPushDir()
00042     { 
00043         chdir(old_dir); 
00044         closedir(dir_handle);
00045         free(old_dir);
00046     }
00047 };
00048 
00049 #endif /// __WVPUSHDIR_H

Generated on Thu Aug 12 2010 11:33:11 for WvStreams by  doxygen 1.7.1