/[debian]/mimetic/trunk/mimetic/os/fileop.cxx
ViewVC logotype

Contents of /mimetic/trunk/mimetic/os/fileop.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 511 - (show annotations)
Sun Jan 21 20:13:31 2007 UTC (14 years, 5 months ago) by gregoa
File size: 2405 byte(s)
* New upstream release.
1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: fileop.cxx,v 1.4 2007/01/21 14:08:57 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_TYPES_H
22 #include <sys/types.h>
23 #endif
24 #ifdef HAVE_SYS_STAT_H
25 #include <sys/stat.h>
26 #endif
27
28 using namespace std;
29
30 namespace mimetic
31 {
32
33 //static
34 bool FileOp::remove(const string& fqn)
35 {
36 return unlink(fqn.c_str()) == 0;
37 }
38
39 //static
40 bool FileOp::move(const string& oldf, const string& newf)
41 {
42 #if defined(CONFIG_UNIX)
43 if(link(oldf.c_str(), newf.c_str()) == 0)
44 {
45 unlink(oldf.c_str());
46 return true;
47 }
48 return false;
49 #elif defined(CONFIG_WIN32)
50 return(rename(oldf.c_str(), newf.c_str()) == 0);
51 #else
52 #error sys not supported
53 #endif
54 }
55 //static
56 bool FileOp::exists(const string& fqn)
57 {
58 struct stat st;
59 return ::stat(fqn.c_str(), &st) == 0;
60 }
61
62 //static
63 uint FileOp::size(const string& fqn)
64 {
65 struct stat st;
66 if(::stat(fqn.c_str(), &st) == 0)
67 return st.st_size;
68 else
69 return 0;
70 }
71
72 //static
73 uint FileOp::ctime(const string& fqn)
74 {
75 struct stat st;
76 if(::stat(fqn.c_str(), &st) == 0)
77 return st.st_ctime;
78 else
79 return 0;
80 }
81
82 //static
83 uint FileOp::atime(const string& fqn)
84 {
85 struct stat st;
86 if(::stat(fqn.c_str(), &st) == 0)
87 return st.st_atime;
88 else
89 return 0;
90 }
91
92 //static
93 uint FileOp::mtime(const string& fqn)
94 {
95 struct stat st;
96 if(::stat(fqn.c_str(), &st) == 0)
97 return st.st_mtime;
98 else
99 return 0;
100 }
101
102 }
103
104

  ViewVC Help
Powered by ViewVC 1.1.26