OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
dodsutil.h
Go to the documentation of this file.
1 // This file is part of the hdf4 data handler for the OPeNDAP data server.
2 
3 // Copyright (c) 2005 OPeNDAP, Inc.
4 // Author: James Gallagher <jgallagher@opendap.org>
5 //
6 // This is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your
9 // option) any later version.
10 //
11 // This software is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this software; if not, write to the Free Software Foundation,
18 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
21 
23 // Copyright 1996, by the California Institute of Technology.
24 // ALL RIGHTS RESERVED. United States Government Sponsorship
25 // acknowledged. Any commercial use must be negotiated with the
26 // Office of Technology Transfer at the California Institute of
27 // Technology. This software may be subject to U.S. export control
28 // laws and regulations. By accepting this software, the user
29 // agrees to comply with all applicable U.S. export laws and
30 // regulations. User has the responsibility to obtain export
31 // licenses, or other export authority as may be required before
32 // exporting such information to foreign countries or providing
33 // access to foreign persons.
34 
35 // Author: Todd Karakashian, NASA/Jet Propulsion Laboratory
36 // Todd.K.Karakashian@jpl.nasa.gov
37 //
38 
39 
40 #include <string>
41 #include <ctype.h>
42 
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <sys/time.h>
46 
47 #include "HDFStructure.h"
48 #include "HDFArray.h"
49 
50 class Stat {
51  public:
52  Stat(const char *filename) {
53  _badstat = (stat(filename, &_sbuf) != 0);
54  // Stat(string(filename)); Stat is destroyed immediately. jhrg
55  }
56 
57  Stat(const string & filename):_filename(filename) {
58  _badstat = (stat(filename.c_str(), &_sbuf) != 0);
59  }
60 
61  // File mode [see mknod(2)]
62  mode_t mode() const {
63  return _sbuf.st_mode;
64  }
65  // Inode number
66  ino_t ino() const {
67  return _sbuf.st_ino;
68  }
69  // ID of device containing a directory entry for this file
70  dev_t dev() const {
71  return _sbuf.st_dev;
72  }
73  // ID of device -- this entry is defined only for char special or block
74  // special files
75  dev_t rdev() const {
76  return _sbuf.st_rdev;
77  }
78  // Number of links
79  nlink_t nlink() const {
80  return _sbuf.st_nlink;
81  }
82  // User ID of the file's owner
83  uid_t uid() const {
84  return _sbuf.st_uid;
85  }
86  // Group ID of the file's group
87  gid_t gid() const {
88  return _sbuf.st_gid;
89  }
90  // File size in bytes
91  off_t size() const {
92  return _sbuf.st_size;
93  }
94  // Time of last access (Times measured in seconds since
95  // 00:00:00 UTC, Jan. 1, 1970)
96  time_t atime() const {
97  return _sbuf.st_atime;
98  }
99  // Time of last data modification
100  time_t mtime() const {
101  return _sbuf.st_mtime;
102  }
103  // Time of last status change
104  time_t ctime() const {
105  return _sbuf.st_ctime;
106  }
107  // Preferred I/O block size
108  long blksize() const {
109  return _sbuf.st_blksize;
110  }
111  // Number st_blksize blocks allocated
112  long blocks() const {
113  return _sbuf.st_blocks;
114  }
115  // flag indicating constructor was not successful
116  bool bad() const {
117  return _badstat;
118  }
119  // convenience mfunction: return filename
120  const char *filename() const {
121  return _filename.c_str();
122  }
123  // convenience operator: return badstat
124  bool operator!() const {
125  return bad();
126  } protected:
127  string _filename; // name of file
128  struct stat _sbuf; // buffer to hold stat() results
129  bool _badstat; // indicates whether stat() was successful
130 };
131 
132 // return the last component of a full pathname
133 inline string basename(const string & path)
134 {
135  // If the filename has a # in it, it's probably been decompressed
136  // to <cachedir>/the#path#of#the#file#<filename> and all we want is
137  // <filename>. rph 06/14/01.
138 
139  if (path.find("#") != string::npos)
140  return path.substr(path.find_last_of("#") + 1);
141  else
142  return path.substr(path.find_last_of("/") + 1);
143 }
144 
long blksize() const
Definition: dodsutil.h:108
uid_t uid() const
Definition: dodsutil.h:83
string basename(const string &path)
Definition: dodsutil.h:133
off_t size() const
Definition: dodsutil.h:91
dev_t dev() const
Definition: dodsutil.h:70
Definition: dodsutil.h:50
gid_t gid() const
Definition: dodsutil.h:87
bool _badstat
Definition: dodsutil.h:129
ino_t ino() const
Definition: dodsutil.h:66
bool operator!() const
Definition: dodsutil.h:124
nlink_t nlink() const
Definition: dodsutil.h:79
Stat(const string &filename)
Definition: dodsutil.h:57
time_t atime() const
Definition: dodsutil.h:96
dev_t rdev() const
Definition: dodsutil.h:75
long blocks() const
Definition: dodsutil.h:112
mode_t mode() const
Definition: dodsutil.h:62
string _filename
Definition: dodsutil.h:127
const char * filename() const
Definition: dodsutil.h:120
time_t ctime() const
Definition: dodsutil.h:104
time_t mtime() const
Definition: dodsutil.h:100
struct stat _sbuf
Definition: dodsutil.h:128
bool bad() const
Definition: dodsutil.h:116
Stat(const char *filename)
Definition: dodsutil.h:52