bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
dodsutil.h
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
50class Stat {
51 public:
52 explicit Stat(const char *filename) {
53 _badstat = (stat(filename, &_sbuf) != 0);
54 // Stat(string(filename)); Stat is destroyed immediately. jhrg
55 }
56
57 explicit 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 }
127 private:
128 string _filename; // name of file
129 struct stat _sbuf; // buffer to hold stat() results
130 bool _badstat; // indicates whether stat() was successful
131};
132
133// return the last component of a full pathname
134inline string basename(const string & path)
135{
136 // If the filename has a # in it, it's probably been decompressed
137 // to <cachedir>/the#path#of#the#file#<filename> and all we want is
138 // <filename>. rph 06/14/01.
139
140 if (path.find("#") != string::npos)
141 return path.substr(path.find_last_of("#") + 1);
142 else
143 return path.substr(path.find_last_of("/") + 1);
144}
145
146inline string first_part_of_full_path(const string &path) {
147
148 string ret_value ="";
149 size_t first_fs_pos = 0;
150 if(path.front()=='/')
151 first_fs_pos = path.find('/',1);
152 else
153 first_fs_pos = path.find('/',0);
154
155 if (first_fs_pos == string::npos && path !="/")
156 ret_value = path;
157 else
158 ret_value = path.substr(0,first_fs_pos);
159
160 return ret_value;
161}
162