summaryrefslogtreecommitdiff
path: root/libjava/classpath/native/jni/native-lib/cpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/native/jni/native-lib/cpio.c')
-rw-r--r--libjava/classpath/native/jni/native-lib/cpio.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/libjava/classpath/native/jni/native-lib/cpio.c b/libjava/classpath/native/jni/native-lib/cpio.c
index 2777a31b221..ac3c0b5e79c 100644
--- a/libjava/classpath/native/jni/native-lib/cpio.c
+++ b/libjava/classpath/native/jni/native-lib/cpio.c
@@ -352,6 +352,76 @@ int cpio_setFileReadonly (const char *filename)
return 0;
}
+int cpio_chmod (const char *filename, int permissions)
+{
+ struct stat statbuf;
+ int perms = 0;
+
+ if (stat(filename, &statbuf) < 0)
+ return errno;
+
+ /* check for permission flags */
+ if (permissions & CPFILE_FLAG_USR)
+ {
+ if (permissions & CPFILE_FLAG_READ)
+ perms |= S_IRUSR;
+
+ if (permissions & CPFILE_FLAG_WRITE)
+ perms |= S_IWUSR;
+
+ if (permissions & CPFILE_FLAG_EXEC)
+ perms |= S_IXUSR;
+ }
+ else
+ {
+ if (permissions & CPFILE_FLAG_READ)
+ perms |= (S_IRUSR | S_IRGRP | S_IROTH);
+
+ if (permissions & CPFILE_FLAG_WRITE)
+ perms |= (S_IWUSR | S_IWGRP | S_IWOTH);
+
+ if (permissions & CPFILE_FLAG_EXEC)
+ perms |= (S_IXUSR | S_IXGRP | S_IXOTH);
+ }
+
+ if (permissions & CPFILE_FLAG_OFF)
+ perms = statbuf.st_mode & ~perms;
+ else
+ perms = statbuf.st_mode | perms;
+
+ if (chmod(filename, perms) < 0)
+ return errno;
+
+ return 0;
+}
+
+int cpio_checkAccess (const char *filename, unsigned int flag)
+{
+ struct stat statbuf;
+ unsigned int perms = 0;
+
+ if (stat(filename, &statbuf) < 0)
+ return errno;
+
+ switch (flag)
+ {
+ case CPFILE_FLAG_READ:
+ perms = R_OK;
+ break;
+
+ case CPFILE_FLAG_WRITE:
+ perms = W_OK;
+ break;
+
+ case CPFILE_FLAG_EXEC:
+ default:
+ perms = X_OK;
+ break;
+ }
+
+ return (access (filename, perms));
+}
+
int cpio_isFileExists (const char *filename)
{
struct stat statbuf;