/[debian]/mimetic/branches/upstream/current/mimetic/os/fileop.cxx
ViewVC logotype

Contents of /mimetic/branches/upstream/current/mimetic/os/fileop.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (show annotations)
Sat Feb 25 16:49:20 2006 UTC (15 years, 5 months ago) by gregoa
File size: 2352 byte(s)
[svn-inject] Installing original source of mimetic
1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: fileop.cxx,v 1.2 2005/02/23 10:26:15 tat Exp $
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16 #include <mimetic/os/fileop.h>
17 #include <mimetic/libconfig.h>
18 #ifdef HAVE_UNISTD_H
19 #include <unistd.h>
20 #endif
21 #ifdef HAVE_SYS_STAT_H
22 #include <sys/stat.h>
23 #endif
24
25 using namespace std;
26
27
28 namespace mimetic
29 {
30
31 //static
32 bool FileOp::remove(const string& fqn)
33 {
34 return unlink(fqn.c_str()) == 0;
35 }
36
37 //static
38 bool FileOp::move(const string& oldf, const string& newf)
39 {
40 #if defined(CONFIG_UNIX)
41 if(link(oldf.c_str(), newf.c_str()) == 0)
42 {
43 unlink(oldf.c_str());
44 return true;
45 }
46 return false;
47 #elif defined(CONFIG_WIN32)
48 return(rename(oldf.c_str(), newf.c_str()) == 0);
49 #else
50 #error sys not supported
51 #endif
52 }
53 //static
54 bool FileOp::exists(const string& fqn)
55 {
56 struct stat st;
57 return ::stat(fqn.c_str(), &st) == 0;
58 }
59
60 //static
61 uint FileOp::size(const string& fqn)
62 {
63 struct stat st;
64 if(::stat(fqn.c_str(), &st) == 0)
65 return st.st_size;
66 else
67 return 0;
68 }
69
70 //static
71 uint FileOp::ctime(const string& fqn)
72 {
73 struct stat st;
74 if(::stat(fqn.c_str(), &st) == 0)
75 return st.st_ctime;
76 else
77 return 0;
78 }
79
80 //static
81 uint FileOp::atime(const string& fqn)
82 {
83 struct stat st;
84 if(::stat(fqn.c_str(), &st) == 0)
85 return st.st_atime;
86 else
87 return 0;
88 }
89
90 //static
91 uint FileOp::mtime(const string& fqn)
92 {
93 struct stat st;
94 if(::stat(fqn.c_str(), &st) == 0)
95 return st.st_mtime;
96 else
97 return 0;
98 }
99
100 }
101
102

  ViewVC Help
Powered by ViewVC 1.1.26