]>
git.saurik.com Git - apple/security.git/blob - OSX/utilities/src/fileIo.c
2 * Copyright (c) 2005-2007,2010,2012-2013 Apple Inc. All Rights Reserved.
10 #include <sys/types.h>
17 const unsigned char *bytes
,
21 return writeFileSizet(fileName
, bytes
, n
);
26 const unsigned char *bytes
,
34 fwrite(bytes
, 1, numBytes
, stdout
);
36 return ferror(stdout
);
39 fd
= open(fileName
, O_RDWR
| O_CREAT
| O_TRUNC
, 0600);
43 wrc
= write(fd
, bytes
, (size_t)numBytes
);
44 if(wrc
!= (ssize_t
) numBytes
) {
46 fprintf(stderr
, "writeFile: short write\n");
62 unsigned char **bytes
, // mallocd and returned
63 size_t *numBytes
) // returned
74 fd
= open(fileName
, O_RDONLY
);
82 if (sb
.st_size
> (off_t
) ((UINT32_MAX
>> 1)-1)) {
86 size
= (size_t)sb
.st_size
;
87 buf
= (char *)malloc(size
);
92 rrc
= read(fd
, buf
, size
);
93 if(rrc
!= (ssize_t
) size
) {
96 fprintf(stderr
, "readFile: short read\n");
102 *bytes
= (unsigned char *)buf
;