GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
stat-wrappers.c
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2016-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 // These functions may be provided by gnulib. We don't include gnulib
24 // headers directly in Octave's C++ source files to avoid problems that
25 // may be caused by the way that gnulib overrides standard library
26 // functions.
27 
28 #if defined (HAVE_CONFIG_H)
29 # include "config.h"
30 #endif
31 
32 #include <time.h>
33 
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 
37 #include "stat-wrappers.h"
38 
39 int
40 octave_mkdir_wrapper (const char *name, mode_t mode)
41 {
42  return mkdir (name, mode);
43 }
44 
45 int
46 octave_mkfifo_wrapper (const char *name, mode_t mode)
47 {
48  return mkfifo (name, mode);
49 }
50 
51 int
53 {
54  return umask (mode);
55 }
56 
57 static inline void
58 assign_stat_fields (struct stat *buf, mode_t *mode, ino_t *ino,
59  dev_t *dev, nlink_t *nlink, uid_t *uid,
60  gid_t *gid, off_t *size, time_t *atime,
61  time_t *mtime, time_t *ctime, dev_t *rdev,
62  long *blksize, long *blocks)
63 {
64  *mode = buf->st_mode;
65  *ino = buf->st_ino;
66  *dev = buf->st_dev;
67  *nlink = buf->st_nlink;
68  *uid = buf->st_uid;
69  *gid = buf->st_gid;
70  *size = buf->st_size;
71  *atime = buf->st_atime;
72  *mtime = buf->st_mtime;
73  *ctime = buf->st_ctime;
74 
75 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
76  *rdev = buf->st_rdev;
77 #else
78  *rdev = 0;
79 #endif
80 
81 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
82  *blksize = buf->st_blksize;
83 #else
84  *blksize = 0;
85 #endif
86 
87 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
88  *blocks = buf->st_blocks;
89 #else
90  *blocks = 0;
91 #endif
92 }
93 
94 int
95 octave_stat_wrapper (const char *fname, mode_t *mode, ino_t *ino,
96  dev_t *dev, nlink_t *nlink, uid_t *uid,
97  gid_t *gid, off_t *size, time_t *atime,
98  time_t *mtime, time_t *ctime, dev_t *rdev,
99  long *blksize, long *blocks)
100 {
101  struct stat buf;
102 
103  int status = stat (fname, &buf);
104 
105  assign_stat_fields (&buf, mode, ino, dev, nlink, uid, gid, size,
106  atime, mtime, ctime, rdev, blksize, blocks);
107 
108  return status;
109 }
110 
111 int
112 octave_lstat_wrapper (const char *lname, mode_t *mode, ino_t *ino,
113  dev_t *dev, nlink_t *nlink, uid_t *uid,
114  gid_t *gid, off_t *size, time_t *atime,
115  time_t *mtime, time_t *ctime, dev_t *rdev,
116  long *blksize, long *blocks)
117 {
118  struct stat buf;
119 
120  int status = lstat (lname, &buf);
121 
122  assign_stat_fields (&buf, mode, ino, dev, nlink, uid, gid, size,
123  atime, mtime, ctime, rdev, blksize, blocks);
124 
125  return status;
126 }
127 
128 int
129 octave_fstat_wrapper (int fid, mode_t *mode, ino_t *ino,
130  dev_t *dev, nlink_t *nlink, uid_t *uid,
131  gid_t *gid, off_t *size, time_t *atime,
132  time_t *mtime, time_t *ctime, dev_t *rdev,
133  long *blksize, long *blocks)
134 {
135  struct stat buf;
136 
137  int status = fstat (fid, &buf);
138 
139  assign_stat_fields (&buf, mode, ino, dev, nlink, uid, gid, size,
140  atime, mtime, ctime, rdev, blksize, blocks);
141 
142  return status;
143 }
144 
145 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
146 // Disable the unused parameter warning for the following wrapper functions.
147 // The <sys/stat.h> header provided by gnulib may define some of the S_IS*
148 // macros to expand to a constant and ignore the parameter.
149 #pragma GCC diagnostic push
150 #pragma GCC diagnostic ignored "-Wunused-parameter"
151 #endif
152 
153 bool
155 {
156 #if defined (S_ISBLK)
157  return S_ISBLK (mode);
158 #else
159  return false;
160 #endif
161 }
162 
163 bool
165 {
166 #if defined (S_ISCHR)
167  return S_ISCHR (mode);
168 #else
169  return false;
170 #endif
171 }
172 
173 bool
175 {
176 #if defined (S_ISDIR)
177  return S_ISDIR (mode);
178 #else
179  return false;
180 #endif
181 }
182 
183 bool
185 {
186 #if defined (S_ISFIFO)
187  return S_ISFIFO (mode);
188 #else
189  return false;
190 #endif
191 }
192 
193 bool
195 {
196 #if defined (S_ISLNK)
197  return S_ISLNK (mode);
198 #else
199  return false;
200 #endif
201 }
202 
203 bool
205 {
206 #if defined (S_ISREG)
207  return S_ISREG (mode);
208 #else
209  return false;
210 #endif
211 }
212 
213 bool
215 {
216 #if defined (S_ISSOCK)
217  return S_ISSOCK (mode);
218 #else
219  return false;
220 #endif
221 }
222 
223 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
224 // Restore prevailing warning state for remainder of the file.
225 #pragma GCC diagnostic pop
226 #endif
227 
228 bool
230 {
231 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
232  return true;
233 #else
234  return false;
235 #endif
236 }
237 
238 bool
240 {
241 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
242  return true;
243 #else
244  return false;
245 #endif
246 }
247 
248 bool
250 {
251 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
252  return true;
253 #else
254  return false;
255 #endif
256 }
bool octave_is_fifo_wrapper(mode_t mode)
fname
Definition: load-save.cc:767
OCTAVE_EXPORT octave_value_list mkdir
Definition: dirfns.cc:162
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
int octave_stat_wrapper(const char *fname, mode_t *mode, ino_t *ino, dev_t *dev, nlink_t *nlink, uid_t *uid, gid_t *gid, off_t *size, time_t *atime, time_t *mtime, time_t *ctime, dev_t *rdev, long *blksize, long *blocks)
Definition: stat-wrappers.c:95
static void assign_stat_fields(struct stat *buf, mode_t *mode, ino_t *ino, dev_t *dev, nlink_t *nlink, uid_t *uid, gid_t *gid, off_t *size, time_t *atime, time_t *mtime, time_t *ctime, dev_t *rdev, long *blksize, long *blocks)
Definition: stat-wrappers.c:58
bool octave_have_struct_stat_st_blocks(void)
int octave_fstat_wrapper(int fid, mode_t *mode, ino_t *ino, dev_t *dev, nlink_t *nlink, uid_t *uid, gid_t *gid, off_t *size, time_t *atime, time_t *mtime, time_t *ctime, dev_t *rdev, long *blksize, long *blocks)
bool octave_is_dir_wrapper(mode_t mode)
bool octave_is_lnk_wrapper(mode_t mode)
bool octave_is_reg_wrapper(mode_t mode)
nd deftypefn *std::string name
Definition: sysdep.cc:647
bool octave_is_chr_wrapper(mode_t mode)
bool octave_is_blk_wrapper(mode_t mode)
int octave_umask_wrapper(mode_t mode)
Definition: stat-wrappers.c:52
int umask(mode_t mode)
Definition: file-ops.cc:613
bool octave_have_struct_stat_st_blksize(void)
subroutine stat(x, n, av, var, xmin, xmax)
Definition: tstgmn.for:112
bool octave_is_sock_wrapper(mode_t mode)
int octave_mkfifo_wrapper(const char *name, mode_t mode)
Definition: stat-wrappers.c:46
bool octave_have_struct_stat_st_rdev(void)
int octave_lstat_wrapper(const char *lname, mode_t *mode, ino_t *ino, dev_t *dev, nlink_t *nlink, uid_t *uid, gid_t *gid, off_t *size, time_t *atime, time_t *mtime, time_t *ctime, dev_t *rdev, long *blksize, long *blocks)
int octave_mkdir_wrapper(const char *name, mode_t mode)
Definition: stat-wrappers.c:40
int fid
Definition: file-io.cc:625
int mkfifo(const std::string &nm, mode_t md)
Definition: file-ops.cc:412