メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

dir-ops.cc

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <cerrno>
00028 #include <cstdlib>
00029 #include <cstring>
00030 
00031 #include "sysdir.h"
00032 
00033 #include "dir-ops.h"
00034 #include "lo-error.h"
00035 #include "lo-sysdep.h"
00036 #include "str-vec.h"
00037 
00038 bool
00039 dir_entry::open (const std::string& n)
00040 {
00041   fail = true;
00042 
00043   if (! n.empty ())
00044     name = n;
00045 
00046   if (! name.empty ())
00047     {
00048       close ();
00049 
00050       dir = static_cast<void *> (opendir (name.c_str ()));
00051 
00052       if (dir)
00053         fail = false;
00054       else
00055         {
00056           using namespace std;
00057           errmsg = strerror (errno);
00058         }
00059     }
00060   else
00061     errmsg = "dir_entry::open: empty file name";
00062 
00063   return ! fail;
00064 }
00065 
00066 string_vector
00067 dir_entry::read (void)
00068 {
00069   string_vector dirlist;
00070 
00071   if (ok ())
00072     {
00073       int count = 0;
00074 
00075       struct dirent *dir_ent;
00076 
00077       while ((dir_ent = readdir (static_cast<DIR *> (dir))))
00078         count++;
00079 
00080       rewinddir (static_cast<DIR *> (dir));
00081 
00082       dirlist.resize (count);
00083 
00084       for (int i = 0; i < count; i++)
00085         {
00086           dir_ent = readdir (static_cast<DIR *> (dir));
00087 
00088           if (dir_ent)
00089             dirlist[i] = dir_ent->d_name;
00090           else
00091             break;
00092         }
00093     }
00094 
00095   return dirlist;
00096 }
00097 
00098 void
00099 dir_entry::close (void)
00100 {
00101   if (dir)
00102     closedir (static_cast<DIR *> (dir));
00103 
00104   dir = 0;
00105 }
00106 
00107 void
00108 dir_entry::copy (const dir_entry& de)
00109 {
00110   name = de.name;
00111   dir = de.dir;
00112   fail = de.fail;
00113   errmsg = de.errmsg;
00114 }
00115 
00116 /*
00117 ;;; Local Variables: ***
00118 ;;; mode: C++ ***
00119 ;;; End: ***
00120 */

Wed Dec 29 11:51:14 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送