From 24666c209fcc217da2f3a18126f7f211ab07d2a2 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 16 Jan 2015 20:45:13 -0500 Subject: [PATCH] CreateResFile doesn't error out if the resource fork already exists. --- toolbox/rm.cpp | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/toolbox/rm.cpp b/toolbox/rm.cpp index f8799a2..d8425f4 100644 --- a/toolbox/rm.cpp +++ b/toolbox/rm.cpp @@ -462,13 +462,7 @@ namespace RM * result code. */ - // FSCreateResourceFile uses the parent FSRef + a file name. - - uint32_t fileName; - FSRef ref; - OSErr error; - int fd; StackFrame<4>(fileName); @@ -477,29 +471,10 @@ namespace RM if (!sname.length()) return SetResError(MacOS::paramErr); - // 1. if the file exists, call FSCreateResourceFork on the file. - // 2. if the file does not exist, create the file then call - // FSCreateResourceFork - error = ::FSPathMakeRef((const UInt8 *)sname.c_str(), &ref, NULL); - if (error != noErr) - { - return SetResError(error); - } + auto rv = CreateResFile(sname); - fd = ::open(sname.c_str(), O_CREAT | O_EXCL | O_RDWR, 0666); - if (fd < 0) - { - if (errno != EEXIST) return SetResError(macos_error_from_errno()); - } - if (fd >= 0) close(fd); - - HFSUniStr255 fork = {0,{0}}; - ::FSGetResourceForkName(&fork); - - error = ::FSCreateResourceFork(&ref, fork.length, fork.unicode, 0); - - return SetResError(error); + return SetResError(rv.error() == errFSForkExists ? 0 : rv.error()); }