]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_cdsa_utils/lib/cuFileIo.c
Security-59306.61.1.tar.gz
[apple/security.git] / OSX / libsecurity_cdsa_utils / lib / cuFileIo.c
index b618154396d0bbcecceea37c1591de8357184dc4..214dca10f9866fa36607fdaa0babf1909ac16da2 100644 (file)
 #include "cuFileIo.h"
 
 int writeFile(
+              const char                       *fileName,
+              const unsigned char      *bytes,
+              unsigned              numBytes)
+{
+    size_t n = numBytes;
+    return writeFileSizet(fileName, bytes, n);
+}
+
+int writeFileSizet(
        const char                      *fileName,
        const unsigned char     *bytes,
-       unsigned                        numBytes)
+       size_t                  numBytes)
 {
        int             rtn;
        int     fd;
        
        fd = open(fileName, O_RDWR | O_CREAT | O_TRUNC, 0600);
-       if(fd < 0) {
-               return errno;
-       }
-       rtn = (int)lseek(fd, 0, SEEK_SET);
-       if(rtn < 0) {
+    if(fd == -1) {
                return errno;
        }
        rtn = (int)write(fd, bytes, (size_t)numBytes);
@@ -78,7 +83,7 @@ int readFile(
        *numBytes = 0;
        *bytes = NULL;
        fd = open(fileName, O_RDONLY, 0);
-       if(fd < 0) {
+    if(fd == -1) {
                return errno;
        }
        rtn = fstat(fd, &sb);