From 60edc69d736a34817b56bb7e3c47348d1f26e227 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Mon, 15 Dec 2014 23:23:04 +0000 Subject: [PATCH] sdmc_open: implement O_EXCL and O_TRUNC --- libctru/source/sdmc_dev.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/libctru/source/sdmc_dev.c b/libctru/source/sdmc_dev.c index 27efc49..085c574 100644 --- a/libctru/source/sdmc_dev.c +++ b/libctru/source/sdmc_dev.c @@ -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;