X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/c38e3ce98599a410a47dc10253faa4d5830f13b2..427c49bcad63d042b29ada2ac27e3dfc4845c779:/security_utilities/fileIo.c diff --git a/security_utilities/fileIo.c b/security_utilities/fileIo.c deleted file mode 100644 index 42fcb11c..00000000 --- a/security_utilities/fileIo.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2005-2007,2010 Apple Inc. All Rights Reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "fileIo.h" - -int writeFile( - const char *fileName, - const unsigned char *bytes, - size_t numBytes) -{ - int rtn; - int fd; - - if (!fileName) { - fwrite(bytes, 1, numBytes, stdout); - fflush(stdout); - return ferror(stdout); - } - - fd = open(fileName, O_RDWR | O_CREAT | O_TRUNC, 0600); - if(fd <= 0) { - return errno; - } - rtn = write(fd, bytes, (size_t)numBytes); - if(rtn != (int)numBytes) { - if(rtn >= 0) { - fprintf(stderr, "writeFile: short write\n"); - } - rtn = EIO; - } - else { - rtn = 0; - } - close(fd); - return rtn; -} - -/* - * Read entire file. - */ -int readFile( - const char *fileName, - unsigned char **bytes, // mallocd and returned - size_t *numBytes) // returned -{ - int rtn; - int fd; - char *buf; - struct stat sb; - size_t size; - - *numBytes = 0; - *bytes = NULL; - fd = open(fileName, O_RDONLY); - if(fd <= 0) { - return errno; - } - rtn = fstat(fd, &sb); - if(rtn) { - goto errOut; - } - if (sb.st_size > SIZE_MAX) { - rtn = EFBIG; - goto errOut; - } - size = (size_t)sb.st_size; - buf = (char *)malloc(size); - if(buf == NULL) { - rtn = ENOMEM; - goto errOut; - } - rtn = read(fd, buf, (size_t)size); - if(rtn != (int)size) { - if(rtn >= 0) { - fprintf(stderr, "readFile: short read\n"); - } - rtn = EIO; - } - else { - rtn = 0; - *bytes = (unsigned char *)buf; - *numBytes = size; - } - -errOut: - close(fd); - return rtn; -}