GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
stat-wrappers.c
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2016-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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  *blksize = 0;
84 #endif
85 
86 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
87  *blocks = buf->st_blocks;
88  *blksize = 0;
89 #endif
90 }
91 
92 int
93 octave_stat_wrapper (const char *fname, mode_t *mode, ino_t *ino,
94  dev_t *dev, nlink_t *nlink, uid_t *uid,
95  gid_t *gid, off_t *size, time_t *atime,
96  time_t *mtime, time_t *ctime, dev_t *rdev,
97  long *blksize, long *blocks)
98 {
99  struct stat buf;
100 
101  int status = stat (fname, &buf);
102 
103  assign_stat_fields (&buf, mode, ino, dev, nlink, uid, gid, size,
104  atime, mtime, ctime, rdev, blksize, blocks);
105 
106  return status;
107 }
108 
109 int
110 octave_lstat_wrapper (const char *lname, mode_t *mode, ino_t *ino,
111  dev_t *dev, nlink_t *nlink, uid_t *uid,
112  gid_t *gid, off_t *size, time_t *atime,
113  time_t *mtime, time_t *ctime, dev_t *rdev,
114  long *blksize, long *blocks)
115 {
116  struct stat buf;
117 
118  int status = lstat (lname, &buf);
119 
120  assign_stat_fields (&buf, mode, ino, dev, nlink, uid, gid, size,
121  atime, mtime, ctime, rdev, blksize, blocks);
122 
123  return status;
124 }
125 
126 int
127 octave_fstat_wrapper (int fid, mode_t *mode, ino_t *ino,
128  dev_t *dev, nlink_t *nlink, uid_t *uid,
129  gid_t *gid, off_t *size, time_t *atime,
130  time_t *mtime, time_t *ctime, dev_t *rdev,
131  long *blksize, long *blocks)
132 {
133  struct stat buf;
134 
135  int status = fstat (fid, &buf);
136 
137  assign_stat_fields (&buf, mode, ino, dev, nlink, uid, gid, size,
138  atime, mtime, ctime, rdev, blksize, blocks);
139 
140  return status;
141 }
142 
143 bool
145 {
146 #if defined (S_ISBLK)
147  return S_ISBLK (mode);
148 #else
149  return false;
150 #endif
151 }
152 
153 bool
155 {
156 #if defined (S_ISCHR)
157  return S_ISCHR (mode);
158 #else
159  return false;
160 #endif
161 }
162 
163 bool
165 {
166 #if defined (S_ISDIR)
167  return S_ISDIR (mode);
168 #else
169  return false;
170 #endif
171 }
172 
173 bool
175 {
176 #if defined (S_ISFIFO)
177  return S_ISFIFO (mode);
178 #else
179  return false;
180 #endif
181 }
182 
183 bool
185 {
186 #if defined (S_ISLNK)
187  return S_ISLNK (mode);
188 #else
189  return false;
190 #endif
191 }
192 
193 bool
195 {
196 #if defined (S_ISREG)
197  return S_ISREG (mode);
198 #else
199  return false;
200 #endif
201 }
202 
203 bool
205 {
206 #if defined (S_ISSOCK)
207  return S_ISSOCK (mode);
208 #else
209  return false;
210 #endif
211 }
212 
213 bool
215 {
216 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
217  return true;
218 #else
219  return false;
220 #endif
221 }
222 
223 bool
225 {
226 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
227  return true;
228 #else
229  return false;
230 #endif
231 }
232 
233 bool
235 {
236 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
237  return true;
238 #else
239  return false;
240 #endif
241 }
bool octave_is_fifo_wrapper(mode_t mode)
fname
Definition: load-save.cc:754
OCTAVE_EXPORT octave_value_list mkdir
Definition: dirfns.cc:158
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:6386
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:93
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)
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
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:642
bool octave_have_struct_stat_st_blksize(void)
subroutine stat(x, n, av, var, xmin, xmax)
Definition: tstgmn.for:111
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)
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable or any other valid Octave code The number of return their size
Definition: input.cc:871
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 mkfifo(const std::string &nm, mode_t md)
Definition: file-ops.cc:427