]>
git.saurik.com Git - apple/security.git/blob - security_utilities/fileIo.c
42fcb11c315f4a4fe974daf00cbfedd5abb94429
2 * Copyright (c) 2005-2007,2010 Apple Inc. All Rights Reserved.
10 #include <sys/types.h>
17 const unsigned char *bytes
,
24 fwrite(bytes
, 1, numBytes
, stdout
);
26 return ferror(stdout
);
29 fd
= open(fileName
, O_RDWR
| O_CREAT
| O_TRUNC
, 0600);
33 rtn
= write(fd
, bytes
, (size_t)numBytes
);
34 if(rtn
!= (int)numBytes
) {
36 fprintf(stderr
, "writeFile: short write\n");
52 unsigned char **bytes
, // mallocd and returned
53 size_t *numBytes
) // returned
63 fd
= open(fileName
, O_RDONLY
);
71 if (sb
.st_size
> SIZE_MAX
) {
75 size
= (size_t)sb
.st_size
;
76 buf
= (char *)malloc(size
);
81 rtn
= read(fd
, buf
, (size_t)size
);
82 if(rtn
!= (int)size
) {
84 fprintf(stderr
, "readFile: short read\n");
90 *bytes
= (unsigned char *)buf
;