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

file-stat.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 <cstring>
00029 
00030 #ifdef HAVE_UNISTD_H
00031 #ifdef HAVE_SYS_TYPES_H
00032 #include <sys/types.h>
00033 #endif
00034 #include <unistd.h>
00035 #endif
00036 
00037 #include "file-stat.h"
00038 #include "statdefs.h"
00039 
00040 #if !defined (HAVE_LSTAT)
00041 static inline int
00042 lstat (const char *name, struct stat *buf)
00043 {
00044   return stat (name, buf);
00045 }
00046 #endif
00047 
00048 // XXX FIXME XXX -- the is_* and mode_as_string functions are only valid
00049 // for initialized objects.  If called for an object that is not
00050 // initialized, they should throw an exception.
00051 
00052 bool
00053 file_stat::is_blk (void) const
00054 {
00055 #ifdef S_ISBLK
00056   return S_ISBLK (fs_mode);
00057 #else
00058   return false;
00059 #endif
00060 }
00061 
00062 bool
00063 file_stat::is_chr (void) const
00064 {
00065 #ifdef S_ISCHR
00066   return S_ISCHR (fs_mode);
00067 #else
00068   return false;
00069 #endif
00070 }
00071 
00072 bool
00073 file_stat::is_dir (void) const
00074 { 
00075 #ifdef S_ISDIR
00076   return S_ISDIR (fs_mode);
00077 #else
00078   return false;
00079 #endif
00080 }
00081 
00082 bool
00083 file_stat::is_fifo (void) const
00084 { 
00085 #ifdef S_ISFIFO
00086   return S_ISFIFO (fs_mode);
00087 #else
00088   return false;
00089 #endif
00090 }
00091 
00092 bool
00093 file_stat::is_lnk (void) const
00094 { 
00095 #ifdef S_ISLNK
00096   return S_ISLNK (fs_mode);
00097 #else
00098   return false;
00099 #endif
00100 }
00101 
00102 bool
00103 file_stat::is_reg (void) const
00104 { 
00105 #ifdef S_ISREG
00106   return S_ISREG (fs_mode);
00107 #else
00108   return false;
00109 #endif
00110 }
00111 
00112 bool
00113 file_stat::is_sock (void) const
00114 { 
00115 #ifdef S_ISSOCK
00116   return S_ISSOCK (fs_mode);
00117 #else
00118   return false;
00119 #endif
00120 }
00121 
00122 extern "C" void mode_string (unsigned short, char *);
00123 
00124 std::string
00125 file_stat::mode_as_string (void) const
00126 {
00127   char buf[11];
00128 
00129   mode_string (fs_mode, buf);
00130 
00131   buf[10] = '\0';
00132 
00133   return std::string (buf);
00134 }
00135 
00136 // Has FILE been modified since TIME?  Returns 1 for yes, 0 for no,
00137 // and -1 for any error.
00138 
00139 int
00140 file_stat::is_newer (const std::string& file, const octave_time& time)
00141 {
00142   file_stat fs (file);
00143 
00144   return fs ? fs.is_newer (time) : -1;
00145 }
00146 
00147 // Private stuff:
00148 
00149 void
00150 file_stat::update_internal (bool force)
00151 {
00152   if (! initialized || force)
00153     {
00154       initialized = false;
00155       fail = false;
00156 
00157       const char *cname = file_name.c_str ();
00158 
00159       struct stat buf;
00160 
00161       int status = follow_links ? stat (cname, &buf) : lstat (cname, &buf);
00162 
00163       if (status < 0)
00164         {
00165           using namespace std;
00166 
00167           fail = true;
00168           errmsg = strerror (errno);
00169         }
00170       else
00171         {
00172           fs_mode = buf.st_mode;
00173           fs_ino = buf.st_ino;
00174           fs_dev = buf.st_dev;
00175           fs_nlink = buf.st_nlink;
00176           fs_uid = buf.st_uid;
00177           fs_gid = buf.st_gid;
00178           fs_size = buf.st_size;
00179           fs_atime = buf.st_atime;
00180           fs_mtime = buf.st_mtime;
00181           fs_ctime = buf.st_ctime;
00182 
00183 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
00184           fs_rdev = buf.st_rdev;
00185 #endif
00186 
00187 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
00188           fs_blksize = buf.st_blksize;
00189 #endif
00190 
00191 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
00192           fs_blocks = buf.st_blocks;
00193 #endif
00194         }
00195 
00196       initialized = true;
00197     }
00198 }
00199 
00200 void
00201 file_stat::copy (const file_stat& fs)
00202 {
00203   file_name = fs.file_name;
00204   follow_links = fs.follow_links;
00205   initialized = fs.initialized;
00206   fail = fs.fail;
00207   errmsg = fs.errmsg;
00208   fs_mode = fs.fs_mode;
00209   fs_ino = fs.fs_ino;
00210   fs_dev = fs.fs_dev;
00211   fs_nlink = fs.fs_nlink;
00212   fs_uid = fs.fs_uid;
00213   fs_gid = fs.fs_gid;
00214   fs_size = fs.fs_size;
00215   fs_atime = fs.fs_atime;
00216   fs_mtime = fs.fs_mtime;
00217   fs_ctime = fs.fs_ctime;
00218 
00219 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
00220   fs_rdev = fs.fs_rdev;
00221 #endif
00222 
00223 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
00224   fs_blksize = fs.fs_blksize;
00225 #endif
00226 
00227 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
00228   fs_blocks = fs.fs_blocks;
00229 #endif
00230 }
00231 
00232 /*
00233 ;;; Local Variables: ***
00234 ;;; mode: C++ ***
00235 ;;; End: ***
00236 */

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