WvStreams
|
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 old_dir = get_current_dir_name(); 00031 dir_handle = opendir(old_dir); 00032 00033 if (chdir(new_dir) == -1) 00034 errnum = errno; 00035 } 00036 00037 ~WvPushDir() 00038 { 00039 chdir(old_dir); 00040 closedir(dir_handle); 00041 free(old_dir); 00042 } 00043 }; 00044 00045 #endif /// __WVPUSHDIR_H