]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/cspxutils/utilLib/fileIo.c
12 const unsigned char *bytes
,
18 fd
= open(fileName
, O_RDWR
| O_CREAT
| O_TRUNC
, 0600);
22 rtn
= lseek(fd
, 0, SEEK_SET
);
26 rtn
= write(fd
, bytes
, (size_t)numBytes
);
27 if(rtn
!= (int)numBytes
) {
29 printf("writeFile: short write\n");
45 unsigned char **bytes
, // mallocd and returned
46 unsigned *numBytes
) // returned
61 fd
= open(fileName
, O_RDONLY
, 0);
66 irtn
= fstat(fd
, &sb
);
70 fprintf(stderr
, "***Bogus zero error on fstat\n");
79 buf
= thisBuf
= (char *)malloc(size
);
84 lrtn
= lseek(fd
, 0, SEEK_SET
);
88 fprintf(stderr
, "***Bogus zero error on lseek\n");
99 * On ppc this read ALWAYS returns the entire file. On i386, not so.
102 thisMoved
= read(fd
, thisBuf
, toMove
);
104 /* reading empty file: done */
107 else if(thisMoved
< 0) {
112 size_t uThisMoved
= (size_t)thisMoved
;
113 if(uThisMoved
!= toMove
) {
114 fprintf(stderr
, "===Short read: asked for %ld, got %lu\n",
118 thisBuf
+= thisMoved
;
122 *bytes
= (unsigned char *)buf
;