]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cdsa_utils/lib/cuFileIo.c
2 * Copyright (c) 2001-2003,2011-2012,2014 Apple Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please
7 * obtain a copy of the License at http://www.apple.com/publicsource and
8 * read it before using this file.
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
12 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
13 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
15 * Please see the License for the specific language governing rights and
16 * limitations under the License.
22 Description: simple file read/write utilities
30 #include <sys/types.h>
36 const unsigned char *bytes
,
40 return writeFileSizet(fileName
, bytes
, n
);
45 const unsigned char *bytes
,
51 fd
= open(fileName
, O_RDWR
| O_CREAT
| O_TRUNC
, 0600);
55 rtn
= (int)lseek(fd
, 0, SEEK_SET
);
59 rtn
= (int)write(fd
, bytes
, (size_t)numBytes
);
60 if(rtn
!= (int)numBytes
) {
62 printf("writeFile: short write\n");
78 unsigned char **bytes
, // mallocd and returned
79 unsigned *numBytes
) // returned
89 fd
= open(fileName
, O_RDONLY
, 0);
97 size
= (unsigned)sb
.st_size
;
103 rtn
= (int)lseek(fd
, 0, SEEK_SET
);
108 rtn
= (int)read(fd
, buf
, (size_t)size
);
109 if(rtn
!= (int)size
) {
111 printf("readFile: short read\n");