forked from wagyu298/libmagic-ios
-
Notifications
You must be signed in to change notification settings - Fork 1
yang2012/libmagic-ios
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
libmagic for iOS. Description *********** A library part of file(1) for iOS. (The library also known as libmagic.) Based file command (and magic file) was originally written by Ian Darwin (who still contributes occasionally) and is now maintained by a group of developers lead by Christos Zoulas. See http://darwinsys.com/file/ for more details about the file command. Usage ***** 1. Download source code from Github. 2. Open magic/magic.xcodeproj on Xcode. 3. Build static library libmagic.a. 4. Close the project. (Recommended, Xcode cause problem when drag and drop opened static library project) 5. Drag magic/magic.xcodeproj on Fineder and drop it to your iOS application project on Xcode. 6. Copy a magic file in libmagic.a to your project. You can find the magic file at magic/magic of libmagic-ios Xcode project. 7. Open your project file (root file of the project), select your application on TARGETS section, toggle Build Settings tab and add /YOUR-LIBMAGIC-IOS-PATH/magic/magic to the Header Search Paths of the Build Settings. 8. Open your project file, select your application on TARGETS section, toggle Summary tab and add libz.dblib and libmagic.a to the Linked Frameworks and Libraries. 9. Modify your application source. Add magic_ios_compile function call at didFinishLaunchingWithOptions of AppDelegate.m. magic_ios_compile function compiled magic file to ~/.magic-ARCH/magic.cnf if it is missing (ARCH is the CPU architecture, such as .magic-armv7). Be careful, magic_ios_compile function is multi-thread unsafe. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { static BOOL initialized = NO; @synchronized(self) { if (!initialized) { magic_ios_compile(); initialized = YES; } } // ... } 10. Use libmagic. magic_t magic = magic_open(MAGIC_NONE); magic_load(magic, NULL); const char *filetype = magic_file(magic, path_of_file); NSLog(@"file type is %s", filetype); magic_close(magic); Omit compiled magic =================== You can use libmagic-ios without the compiled magic file. In this case, you can omit the step 9 of the usage (magic_ios_compile function call at didFinishLaunchingWithOptions) and use the result of magic_ios_get_plain_magic function to the second argument of magic_load. magic_t magic = magic_open(MAGIC_NONE); magic_load(magic, magic_ios_get_plain_magic()); // ... magic_ios_get_plain_magic function returns the path of bundled plain magic file. See magicios.m for more details. Using patch *********** Github repository includes the patch file of libmagic-ios. You can generate libmagic-ios Xcode project from the patch file and original file utility tarball. 1. Download file-5.11.tar.gz from http://darwinsys.com/file/. 2. Extract tarball. 3. Apply file-5.11-ios.diff cd file-5.11 patch -p1 < ../libmagic-ios/file-5.11-ios.diff 4. Build with ios make target. configure make ios 5. Check ios subdirectory. License ******* libmagic-ios follows the license of file package, it licensed under modified BSD license. See http://darwinsys.com/file/ for more details.
About
libmagic for iOS
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- C 98.5%
- Objective-C 1.4%
- Shell 0.1%