X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5c19dc3ae3bd8e40a9c028b0deddd50ff337692c..7e6b461318c8a779d91381531435a68ee4e8b6ed:/OSX/libsecurity_cdsa_utils/lib/cuFileIo.c diff --git a/OSX/libsecurity_cdsa_utils/lib/cuFileIo.c b/OSX/libsecurity_cdsa_utils/lib/cuFileIo.c index bb1403e0..214dca10 100644 --- a/OSX/libsecurity_cdsa_utils/lib/cuFileIo.c +++ b/OSX/libsecurity_cdsa_utils/lib/cuFileIo.c @@ -32,19 +32,24 @@ #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); @@ -93,6 +98,7 @@ int readFile( } rtn = (int)lseek(fd, 0, SEEK_SET); if(rtn < 0) { + free(buf); goto errOut; } rtn = (int)read(fd, buf, (size_t)size); @@ -100,6 +106,7 @@ int readFile( if(rtn >= 0) { printf("readFile: short read\n"); } + free(buf); rtn = EIO; } else {