PERFORCE change 165408 for review
Jonathan Anderson
jona at FreeBSD.org
Mon Jun 29 16:13:49 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=165408
Change 165408 by jona at jona-trustedbsd-belle-vmware on 2009/06/29 16:12:49
ua_fopen(), a wrapper around fopen()
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#7 edit
.. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#7 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#7 (text+ko) ====
@@ -237,6 +237,60 @@
+FILE* ua_fopen(const char *path, const char *mode)
+{
+ if(angel < 0) angel = ua_find();
+ if(angel < 0) return NULL;
+
+ int flags = 0;
+ cap_rights_t rights = CAP_SEEK | CAP_FSYNC;
+
+ if(strstr(mode, "r+"))
+ {
+ flags |= O_RDWR;
+ rights |= CAP_READ | CAP_WRITE | CAP_FTRUNCATE;
+ }
+ else if(strstr(mode, "r"))
+ {
+ flags |= O_RDONLY;
+ rights |= CAP_READ;
+ }
+ else if(strstr(mode, "w+"))
+ {
+ flags |= O_RDWR | O_CREAT | O_TRUNC;
+ rights |= CAP_READ | CAP_WRITE | CAP_FTRUNCATE;
+ }
+ else if(strstr(mode, "w"))
+ {
+ flags |= O_WRONLY | O_CREAT | O_TRUNC;
+ rights |= CAP_WRITE | CAP_FTRUNCATE;
+ }
+ else if(strstr(mode, "a+"))
+ {
+ flags |= O_RDWR | O_CREAT | O_APPEND;
+ rights |= CAP_READ | CAP_WRITE | CAP_FTRUNCATE;
+ }
+ else if(strstr(mode, "a"))
+ {
+ flags |= O_WRONLY | O_CREAT | O_APPEND;
+ rights |= CAP_WRITE | CAP_FTRUNCATE;
+ }
+
+ int fd = ua_open(path, flags);
+ if(flags & O_APPEND)
+ if(lseek(fd, 0, SEEK_END) < 0)
+ {
+ sprintf(errmsg, "Error seeking to end of %s: %i (%s)",
+ path, errno, strerror(errno));
+ close(fd);
+ return NULL;
+ }
+
+ return fdopen(fd, mode);
+}
+
+
+
int ua_send(int sock, datum *d, int32_t fds[], int32_t fdlen)
{
// the datum is the I/O vector
==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#7 (text+ko) ====
@@ -35,6 +35,8 @@
#define _LIBUSERANGEL_H_
#include <sys/cdefs.h>
+#include <stdio.h>
+
#include <libuserangel-powerbox.h>
__BEGIN_DECLS
@@ -57,6 +59,9 @@
/** Open a file via the User Angel */
int ua_open(const char *path, int flags);
+/** Open a file stream via the User Angel */
+FILE* ua_fopen(const char *path, const char *mode);
+
/* Low-level API */
More information about the p4-projects
mailing list