aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorPeter Seebach <seebs@eee12.(none)>2010-03-26 14:48:36 -0500
committerPeter Seebach <seebs@eee12.(none)>2010-03-26 14:50:04 -0500
commit80259da816b82c5bdfbf9515935823a157f5d0e9 (patch)
treef5120633e788d0d36ea2133d436d52c563d08d98 /pseudo_util.c
parentcaeebc0dd6ff538629687b55a5ce72554a7c3f34 (diff)
downloadpseudo-80259da816b82c5bdfbf9515935823a157f5d0e9.tar.gz
pseudo-80259da816b82c5bdfbf9515935823a157f5d0e9.tar.bz2
pseudo-80259da816b82c5bdfbf9515935823a157f5d0e9.zip
Track file open flags
This patch adds support for checking whether a file was opened for reading, writing, or both, as well as tracking append flags. It is not very well tested. This is preparation for improved host contamination checking.
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index a57f8ac..55e0488 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -580,3 +580,33 @@ pseudo_sys_path_max(void) {
}
return pseudo_sys_max_pathlen;
}
+
+/* complicated because in theory you can have modes like * 'ab+'
+ * which is the same as 'a+' in POSIX. The first letter really does have
+ * to be one of r, w, a, though.
+ */
+int
+pseudo_access_fopen(const char *mode) {
+ int access = 0;
+ switch (*mode) {
+ case 'a':
+ access |= (PSA_APPEND | PSA_WRITE);
+ if (mode[1] == '+' || (mode[1] == 'b' && mode[2] == '+'))
+ access |= PSA_READ;
+ break;
+ case 'r':
+ access |= PSA_READ;
+ if (mode[1] == '+' || (mode[1] == 'b' && mode[2] == '+'))
+ access |= PSA_WRITE;
+ break;
+ case 'w':
+ access |= PSA_WRITE;
+ if (mode[1] == '+' || (mode[1] == 'b' && mode[2] == '+'))
+ access |= PSA_READ;
+ break;
+ default:
+ access = -1;
+ break;
+ }
+ return access;
+}