コード:
MyPrintDirectoryListing(CFDictionaryRef dictionary) //このdictionaryには何が入っているのか
{
CFDateRef cfModDate;
CFNumberRef cfType, cfMode, cfSize;
CFStringRef cfOwner, cfName, cfLink, cfGroup;
char owner[256], group[256], name[256];
char permString[12], link[1024];
SInt64 size;
SInt32 mode, type;
assert(dictionary != NULL);
/* You should not assume that the directory entry dictionary will contain all the possible keys.
Most of the time it will, however, depending on the FTP server, some of the keys may be missing. */
cfType = CFDictionaryGetValue(dictionary, kCFFTPResourceType);
if (cfType) {
assert(CFGetTypeID(cfType) == CFNumberGetTypeID());
CFNumberGetValue(cfType, kCFNumberSInt32Type, &type);
cfMode = CFDictionaryGetValue(dictionary, kCFFTPResourceMode);
if (cfMode) {
assert(CFGetTypeID(cfMode) == CFNumberGetTypeID());
CFNumberGetValue(cfMode, kCFNumberSInt32Type, &mode);
/* Converts inode status information into a symbolic string */
strmode(mode + DTTOIF(type), permString);
fprintf(stderr, "%s ", permString);
}
}
cfOwner = CFDictionaryGetValue(dictionary, kCFFTPResourceOwner);
if (cfOwner) {
assert(CFGetTypeID(cfOwner) == CFStringGetTypeID());
CFStringGetCString(cfOwner, owner, sizeof(owner), kCFStringEncodingASCII);
fprintf(stderr, "%9s", owner);
}
cfGroup = CFDictionaryGetValue(dictionary, kCFFTPResourceGroup);
if (cfGroup) {
assert(CFGetTypeID(cfGroup) == CFStringGetTypeID());
CFStringGetCString(cfGroup, group, sizeof(group), kCFStringEncodingASCII);
fprintf(stderr, "%9s", group);
}
cfSize = CFDictionaryGetValue(dictionary, kCFFTPResourceSize);
if (cfSize) {
assert(CFGetTypeID(cfSize) == CFNumberGetTypeID());
CFNumberGetValue(cfSize, kCFNumberSInt64Type, &size);
fprintf(stderr, "%9lld ", size);
}
cfModDate = CFDictionaryGetValue(dictionary, kCFFTPResourceModDate); //ここがおそらく欲しい情報?
if (cfModDate) {
CFLocaleRef locale;
CFDateFormatterRef formatDate;
CFDateFormatterRef formatTime;
CFStringRef cfDate;
CFStringRef cfTime;
char date[256];
char time[256];
assert(CFGetTypeID(cfModDate) == CFDateGetTypeID());
locale = CFLocaleCopyCurrent();
assert(locale != NULL);
formatDate = CFDateFormatterCreate(kCFAllocatorDefault, locale, kCFDateFormatterShortStyle, kCFDateFormatterNoStyle );
assert(formatDate != NULL);
formatTime = CFDateFormatterCreate(kCFAllocatorDefault, locale, kCFDateFormatterNoStyle, kCFDateFormatterShortStyle);
assert(formatTime != NULL);
cfDate = CFDateFormatterCreateStringWithDate(kCFAllocatorDefault, formatDate, cfModDate);
assert(cfDate != NULL);
cfTime = CFDateFormatterCreateStringWithDate(kCFAllocatorDefault, formatTime, cfModDate);
assert(cfTime != NULL);
CFStringGetCString(cfDate, date, sizeof(date), kCFStringEncodingUTF8);
CFStringGetCString(cfTime, time, sizeof(time), kCFStringEncodingUTF8);
fprintf(stderr, "%10s %5s ", date, time);
CFRelease(cfTime);
CFRelease(cfDate);
CFRelease(formatTime);
CFRelease(formatDate);
CFRelease(locale);
}
/* Note that this sample assumes UTF-8 since that's what the Mac OS X
FTP server returns, however, some servers may use a different encoding. */
cfName = CFDictionaryGetValue(dictionary, kCFFTPResourceName);
if (cfName) {
assert(CFGetTypeID(cfName) == CFStringGetTypeID());
CFStringGetCString(cfName, name, sizeof(name), kCFStringEncodingUTF8);
fprintf(stderr, "%s", name);
cfLink = CFDictionaryGetValue(dictionary, kCFFTPResourceLink);
if (cfLink) {
assert(CFGetTypeID(cfLink) == CFStringGetTypeID());
CFStringGetCString(cfLink, link, sizeof(link), kCFStringEncodingUTF8);
if (strlen(link) > 0) fprintf(stderr, " -> %s", link);
}
}
fprintf(stderr, "\n");
}