]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
sandbox: add flags for open() call
authorSimon Glass <sjg@chromium.org>
Tue, 21 Feb 2012 04:56:58 +0000 (23:56 -0500)
committerMike Frysinger <vapier@gentoo.org>
Mon, 12 Mar 2012 15:03:42 +0000 (11:03 -0400)
This provides a way for callers to create files for writing. The flags
are translated at runtime, for the ones we support.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
arch/sandbox/cpu/os.c
include/os.h

index f6d0e8457d1651931a5403ba2e8fa3a04ee4eca6..cb469e05106ef561f22342e2dbacf7da1a1256f9 100644 (file)
@@ -58,9 +58,29 @@ off_t os_lseek(int fd, off_t offset, int whence)
        return lseek(fd, offset, whence);
 }
 
-int os_open(const char *pathname, int flags)
+int os_open(const char *pathname, int os_flags)
 {
-       return open(pathname, flags);
+       int flags;
+
+       switch (os_flags & OS_O_MASK) {
+       case OS_O_RDONLY:
+       default:
+               flags = O_RDONLY;
+               break;
+
+       case OS_O_WRONLY:
+               flags = O_WRONLY;
+               break;
+
+       case OS_O_RDWR:
+               flags = O_RDWR;
+               break;
+       }
+
+       if (os_flags & OS_O_CREAT)
+               flags |= O_CREAT;
+
+       return open(pathname, flags, 0777);
 }
 
 int os_close(int fd)
index f74766d16c61a422a5f21620f3d49a820478c637..6b7ee474f04ddee319694d03e1c73eca47460f6c 100644 (file)
@@ -1,4 +1,9 @@
 /*
+ * Operating System Interface
+ *
+ * This provides access to useful OS routines for the sandbox architecture.
+ * They are kept in a separate file so we can include system headers.
+ *
  * Copyright (c) 2011 The Chromium OS Authors.
  * See file CREDITS for list of people who contributed to this
  * project.
  * MA 02111-1307 USA
  */
 
-/*
- * Operating System Interface
- *
- * This provides access to useful OS routines from the sandbox architecture
- */
-
 #ifndef __OS_H__
 #define __OS_H__
 
@@ -72,6 +71,12 @@ off_t os_lseek(int fd, off_t offset, int whence);
  */
 int os_open(const char *pathname, int flags);
 
+#define OS_O_RDONLY    0
+#define OS_O_WRONLY    1
+#define OS_O_RDWR      2
+#define OS_O_MASK      3       /* Mask for read/write flags */
+#define OS_O_CREAT     0100
+
 /**
  * Access to the OS close() system call
  *