]> Chaos Git - corbenik/ctrulib.git/commitdiff
sdmc_open: implement O_EXCL and O_TRUNC
authorDave Murphy <davem@devkitpro.org>
Mon, 15 Dec 2014 23:23:04 +0000 (23:23 +0000)
committerDave Murphy <davem@devkitpro.org>
Mon, 15 Dec 2014 23:23:04 +0000 (23:23 +0000)
libctru/source/sdmc_dev.c

index 27efc49554503d701d2c00de98edfe365c1750d6..085c5743e505504ae89c91f75f3979d78c4d6029 100644 (file)
@@ -244,7 +244,18 @@ sdmc_open(struct _reent *r,
   if(flags & O_CREAT)
     sdmc_flags |= FS_OPEN_CREATE;
 
-  /* TODO: Test O_EXCL. */
+  /* Test O_EXCL. */
+  if((flags & O_CREAT) && (flags & O_EXCL))
+  {
+    rc = FSUSER_CreateFile(NULL, sdmcArchive, FS_makePath(PATH_CHAR, pathptr), 0);
+    if(rc != 0)
+    {
+      r->_errno = rc;
+      if(rc == 0x82044BE)
+        r->_errno = EEXIST;
+      return -1;
+    }
+  }
 
   /* set attributes */
   /*if(!(mode & S_IWUSR))
@@ -255,6 +266,16 @@ sdmc_open(struct _reent *r,
                        sdmc_flags, attributes);
   if(rc == 0)
   {
+    if((flags & O_ACCMODE) != O_RDONLY && (flags & O_TRUNC))
+    {
+      rc = FSFILE_SetSize(fd, 0);
+      if(rc != 0)
+      {
+        FSFILE_Close(fd);
+        r->_errno = rc;
+        return -1;
+      }
+    }
     file->fd     = fd;
     file->flags  = (flags & (O_ACCMODE|O_APPEND|O_SYNC));
     file->offset = 0;