#include #include static getArrayValues (CFTypeRef subArray, int idx); int main (int argc, const char * argv[]) { const char *filename = "/Library/WebServer/Web/localhost", *keyName = "kMDItemKind"; int fileNameLen = strlen(filename), keyNameLen = strlen(keyName); CFIndex idx; // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &filename, &fileNameLen, &keyName, &keyNameLen) == FAILURE) // return; FILE *check = fopen(filename, "r"); if(check){ fclose(check); printf("fclose\n"); }else{ // zend_error(E_WARNING, "The path %s is not found", filename); // RETURN_NULL(); printf("RETURN_NULL\n"); } // DIR * check2 = opendir(filename); // if(check2){ // closedir(check2); // zend_error(E_WARNING, "The path %s is not found", filename); // RETURN_NULL(); // } CFStringRef file = CFStringCreateWithFileSystemRepresentation(NULL, filename); CFStringRef kMDItemAttrib = CFStringCreateWithCString(NULL, keyName, kCFStringEncodingUTF8); MDItemRef item = MDItemCreate(NULL, file); if(!item) { // RETURN_NULL(); printf("RETURN_NULL\n"); } CFTypeRef attribute = MDItemCopyAttribute(item, kMDItemAttrib); if(!attribute) { // RETURN_NULL(); printf("RETURN_NULL\n"); return 0; } CFTypeID type = CFGetTypeID(attribute); // array_init(return_attribute); if (CFArrayGetTypeID() == type) { // ALLOC_INIT_ZVAL(z_attribute); // array_init(z_attribute); idx = CFArrayGetCount((CFArrayRef)attribute); int i; for (i = 0; i < idx; i++) { CFTypeID type2 = CFGetTypeID(CFArrayGetValueAtIndex((CFArrayRef)attribute, i )); if (CFBooleanGetTypeID() == type2) { for (i = 0; i < idx; i++) { //add_next_index_bool(z_attribute, getArrayValues(attribute, i)); printf("%d \n", getArrayValues(attribute, i)); } //add_assoc_zval(return_attribute, keyStr, z_attribute); } if (CFDateGetTypeID() == type2) { for (i = 0; i < idx; i++) { //add_next_index_string(z_attribute, (char *)getArrayValues(attribute, i), 1); printf("%s \n", getArrayValues(attribute, i)); } //add_assoc_zval(return_attribute, keyStr, z_attribute); } if (CFNumberGetTypeID() == type2) { for (i = 0; i < idx; i++) { //add_next_index_long(z_attribute, getArrayValues(attribute, i)); printf("%d \n", getArrayValues(attribute, i)); } //add_assoc_zval(return_attribute, keyStr, z_attribute); } if (CFStringGetTypeID() == type2) { for (i = 0; i < idx; i++) { //add_next_index_string(z_attribute, (char *)getArrayValues(attribute, i), 1); printf("%s \n", getArrayValues(attribute, i)); } //add_assoc_zval(return_attribute, keyStr, z_attribute); } } } if (CFBooleanGetTypeID() == type) { //add_assoc_bool(return_attribute, keyStr, CFBooleanGetValue(attribute)); printf("%d \n", CFBooleanGetValue(attribute)); } if (CFDateGetTypeID() == type) { //add_assoc_string(return_attribute, keyStr, (char *)getArrayValues(attribute, 0), 1); printf("%s \n", getArrayValues(attribute, 0)); } if (CFNumberGetTypeID() == type) { //add_assoc_long(return_attribute, keyStr, getArrayValues(attribute, 0)); printf("%d \n", getArrayValues(attribute, 0)); } if (CFStringGetTypeID() == type) { //add_assoc_string(return_attribute, keyStr, (char *)getArrayValues(attribute, 0), 1); printf("%s \n", getArrayValues(attribute, 0)); } //} CFRelease(file); CFRelease(kMDItemAttrib); CFRelease(item); return 0; } static getArrayValues (CFTypeRef subArray, int idx) { CFTypeRef attribute; if (CFGetTypeID(subArray) == CFArrayGetTypeID()) { attribute = CFArrayGetValueAtIndex(subArray, idx); }else{ attribute = subArray; } CFTypeID type = CFGetTypeID(attribute); if (CFBooleanGetTypeID() == type) { Boolean num = CFBooleanGetValue(attribute); return num; } if (CFDateGetTypeID() == type) { CFStringEncoding strEnc = CFStringGetSystemEncoding(); CFDateFormatterRef format = CFDateFormatterCreate(NULL, NULL, kCFDateFormatterShortStyle, kCFDateFormatterShortStyle); CFDateFormatterSetFormat(format, CFSTR("yyyy-MM-dd HH:mm:ss Z")); CFStringRef date = CFDateFormatterCreateStringWithDate(NULL, format, attribute); unsigned int len = 1 + CFStringGetMaximumSizeForEncoding(CFStringGetLength(date), (CFStringEncoding)CFStringGetNameOfEncoding ((CFStringEncoding)date)); char *str = malloc(len); CFStringGetCString(date, str, len, strEnc); CFRelease(format); CFRelease(date); return (int)str; } if (CFNumberGetTypeID() == type) { long cfnum; Boolean val = CFNumberGetValue((CFNumberRef)attribute, kCFNumberLongType, &cfnum); return cfnum; } if (CFStringGetTypeID() == type) { unsigned int len = 1 + CFStringGetMaximumSizeForEncoding(CFStringGetLength(attribute), kCFStringEncodingUTF8); char *str = malloc(len); CFStringGetCString(attribute, str, len, kCFStringEncodingUTF8); return (int)str; } }