5 // Created by Richard Murphy on 1/22/16.
9 #include "secToolFileIO.h"
13 #include <utilities/SecCFWrappers.h>
18 void _printcfmsg(FILE *ff
, CFDictionaryRef formatOptions
, CFStringRef format
, ...)
21 va_start(args
, format
);
22 CFStringRef message
= CFStringCreateWithFormatAndArguments(kCFAllocatorDefault
, formatOptions
, format
, args
);
24 CFStringPerformWithCString(message
, ^(const char *utf8String
) { fprintf(ff
, utf8String
, ""); });
29 int setOutputTo(char *dir
, char *filename
) {
33 pathlen
= strlen(dir
) + strlen(filename
) + 2;
35 snprintf(path
, pathlen
, "%s/%s", dir
, filename
);
36 outFile
= fopen(path
, "a");
37 } else if(dir
|| filename
) {
47 void closeOutput(void) {
48 if(outFile
!= stdout
) {
54 int copyFileToOutputDir(char *dir
, char *toCopy
) {
55 char *bname
= basename(toCopy
);
58 copyfile_state_t cpfilestate
= copyfile_state_alloc();
60 status
= snprintf(destpath
, 256, "%s/%s", dir
, bname
);
61 if(status
< 0 || status
> 256) return -1;
63 int retval
= copyfile(toCopy
, destpath
, cpfilestate
, COPYFILE_ALL
);
65 copyfile_state_free(cpfilestate
);