mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Cosmetic tweaks to match coding style
This commit is contained in:
parent
75850de0ff
commit
2425c42ace
8 changed files with 332 additions and 234 deletions
|
@ -553,7 +553,7 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
* Sets the Java Android asset manager.
|
||||
* The developer can call this method to enable asset loading via NSBundle.
|
||||
*/
|
||||
+ (void) setJavaAssetManager:(jobject)jassetManager withJNIEnv:(JNIEnv *)env;
|
||||
+ (void) setJavaAssetManager: (jobject)jassetManager withJNIEnv: (JNIEnv *)env;
|
||||
|
||||
/**
|
||||
* Returns the native Android asset manager.
|
||||
|
@ -566,7 +566,7 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
* Uses `AASSET_MODE_UNKNOWN` to open the asset if it exists.
|
||||
* The returned object must be released using AAsset_close().
|
||||
*/
|
||||
+ (AAsset *)assetForPath:(NSString *)path;
|
||||
+ (AAsset *) assetForPath: (NSString *)path;
|
||||
|
||||
/**
|
||||
* Returns the Android asset for the given path if path is in main bundle
|
||||
|
@ -574,14 +574,14 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
* Uses the given mode to open the AAsset if it exists.
|
||||
* The returned object must be released using AAsset_close().
|
||||
*/
|
||||
+ (AAsset *)assetForPath:(NSString *)path withMode:(int)mode;
|
||||
+ (AAsset *) assetForPath: (NSString *)path withMode: (int)mode;
|
||||
|
||||
/**
|
||||
* Returns the Android asset dir for the given path if path is in main bundle
|
||||
* resources and the asset directory exists.
|
||||
* The returned object must be released using AAssetDir_close().
|
||||
*/
|
||||
+ (AAssetDir *)assetDirForPath:(NSString *)path;
|
||||
+ (AAssetDir *) assetDirForPath: (NSString *)path;
|
||||
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
|
@ -648,7 +648,7 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
* </p>
|
||||
*/
|
||||
#define NSLocalizedString(key, comment) \
|
||||
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
|
||||
[[NSBundle mainBundle] localizedStringForKey: (key) value: @"" table: nil]
|
||||
|
||||
/**
|
||||
* This function (macro) does the same as
|
||||
|
@ -666,7 +666,7 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
* different table.
|
||||
*/
|
||||
#define NSLocalizedStringFromTable(key, tbl, comment) \
|
||||
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]
|
||||
[[NSBundle mainBundle] localizedStringForKey: (key) value: @"" table: (tbl)]
|
||||
|
||||
/**
|
||||
* This function is the full-blown localization function (it
|
||||
|
@ -682,7 +682,7 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
* use when translating the string.
|
||||
*/
|
||||
#define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
|
||||
[bundle localizedStringForKey:(key) value:@"" table:(tbl)]
|
||||
[bundle localizedStringForKey: (key) value: @"" table: (tbl)]
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
|
|
@ -287,9 +287,9 @@ static GSTcpTune *tune = nil;
|
|||
{
|
||||
#ifdef __ANDROID__
|
||||
if (asset)
|
||||
{
|
||||
result = AAsset_read(asset, buf, len);
|
||||
}
|
||||
{
|
||||
result = AAsset_read(asset, buf, len);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if USE_ZLIB
|
||||
|
@ -388,10 +388,10 @@ static GSTcpTune *tune = nil;
|
|||
|
||||
#ifdef __ANDROID__
|
||||
if (asset)
|
||||
{
|
||||
AAsset_close(asset);
|
||||
asset = NULL;
|
||||
}
|
||||
{
|
||||
AAsset_close(asset);
|
||||
asset = NULL;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (closeOnDealloc == YES && descriptor != -1)
|
||||
|
@ -1092,10 +1092,11 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
{
|
||||
#ifdef __ANDROID__
|
||||
asset = [NSBundle assetForPath:path withMode:AASSET_MODE_RANDOM];
|
||||
if (asset) {
|
||||
readOK = YES;
|
||||
return self;
|
||||
}
|
||||
if (asset)
|
||||
{
|
||||
readOK = YES;
|
||||
return self;
|
||||
}
|
||||
#endif
|
||||
|
||||
DESTROY(self);
|
||||
|
@ -1670,9 +1671,9 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
|
||||
#ifdef __ANDROID__
|
||||
if (asset)
|
||||
{
|
||||
result = AAsset_seek(asset, 0, SEEK_CUR);
|
||||
}
|
||||
{
|
||||
result = AAsset_seek(asset, 0, SEEK_CUR);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (isStandardFile && descriptor >= 0)
|
||||
|
@ -1701,9 +1702,9 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
|
||||
#ifdef __ANDROID__
|
||||
if (asset)
|
||||
{
|
||||
result = AAsset_seek(asset, 0, SEEK_END);
|
||||
}
|
||||
{
|
||||
result = AAsset_seek(asset, 0, SEEK_END);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (isStandardFile && descriptor >= 0)
|
||||
|
@ -1732,9 +1733,9 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
|
||||
#ifdef __ANDROID__
|
||||
if (asset)
|
||||
{
|
||||
result = AAsset_seek(asset, (off_t)pos, SEEK_SET);
|
||||
}
|
||||
{
|
||||
result = AAsset_seek(asset, (off_t)pos, SEEK_SET);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (isStandardFile && descriptor >= 0)
|
||||
|
@ -1773,10 +1774,10 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
|
||||
#ifdef __ANDROID__
|
||||
if (asset)
|
||||
{
|
||||
AAsset_close(asset);
|
||||
asset = NULL;
|
||||
}
|
||||
{
|
||||
AAsset_close(asset);
|
||||
asset = NULL;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if USE_ZLIB
|
||||
|
|
|
@ -627,15 +627,11 @@ descriptorOrComparator: (id)descriptorOrComparator
|
|||
while (stackSize > 1)
|
||||
{
|
||||
NSInteger n = stackSize -2;
|
||||
if ( (n >= 1
|
||||
&& runStack[n-1].length <= (runStack[n].length
|
||||
+ runStack[n+1].length)
|
||||
)
|
||||
|| (n >= 2
|
||||
&& runStack[n-2].length <= (runStack[n].length
|
||||
+ runStack[n-1].length)
|
||||
)
|
||||
)
|
||||
|
||||
if ((n >= 1 && runStack[n-1].length
|
||||
<= (runStack[n].length + runStack[n+1].length))
|
||||
|| (n >= 2 && runStack[n-2].length
|
||||
<= (runStack[n].length + runStack[n-1].length)))
|
||||
{
|
||||
if (runStack[n-1].length < runStack[n+1].length)
|
||||
{
|
||||
|
|
|
@ -269,17 +269,17 @@ AbsolutePathOfExecutable(NSString *path, BOOL atLaunch)
|
|||
NSString *result = nil;
|
||||
|
||||
env = [[NSProcessInfo processInfo] environment];
|
||||
pathlist = [env objectForKey:@"PATH"];
|
||||
pathlist = [env objectForKey: @"PATH"];
|
||||
|
||||
/* Windows 2000 and perhaps others have "Path" not "PATH" */
|
||||
if (pathlist == nil)
|
||||
{
|
||||
pathlist = [env objectForKey:@"Path"];
|
||||
pathlist = [env objectForKey: @"Path"];
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
patharr = [pathlist componentsSeparatedByString:@";"];
|
||||
patharr = [pathlist componentsSeparatedByString: @";"];
|
||||
#else
|
||||
patharr = [pathlist componentsSeparatedByString:@":"];
|
||||
patharr = [pathlist componentsSeparatedByString: @":"];
|
||||
#endif
|
||||
/* Add . if not already in path */
|
||||
if ([patharr indexOfObject: @"."] == NSNotFound)
|
||||
|
@ -290,7 +290,7 @@ AbsolutePathOfExecutable(NSString *path, BOOL atLaunch)
|
|||
patharr = [patharr objectEnumerator];
|
||||
while (nil != (prefix = [patharr nextObject]))
|
||||
{
|
||||
if ([prefix isEqual:@"."])
|
||||
if ([prefix isEqual: @"."])
|
||||
{
|
||||
if (atLaunch == YES)
|
||||
{
|
||||
|
@ -548,13 +548,14 @@ _find_framework(NSString *name)
|
|||
{
|
||||
NSArray *paths;
|
||||
NSFileManager *file_mgr = manager();
|
||||
NSString *file_name = [name stringByAppendingPathExtension:@"framework"];
|
||||
NSString *file_name;
|
||||
NSString *file_path;
|
||||
NSString *path;
|
||||
NSEnumerator *enumerator;
|
||||
|
||||
NSCParameterAssert(name != nil);
|
||||
|
||||
file_name = [name stringByAppendingPathExtension: @"framework"];
|
||||
paths = NSSearchPathForDirectoriesInDomains(GSFrameworksDirectory,
|
||||
NSAllDomainsMask,YES);
|
||||
|
||||
|
@ -927,9 +928,9 @@ _find_main_bundle_for_tool(NSString *toolName)
|
|||
for (j = 0; j < [l count]; j++)
|
||||
{
|
||||
if ([[l objectAtIndex: j] pointerValue]
|
||||
== [[b objectAtIndex:i] pointerValue])
|
||||
== [[b objectAtIndex: i] pointerValue])
|
||||
{
|
||||
[l removeObjectAtIndex:j];
|
||||
[l removeObjectAtIndex: j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2119,44 +2120,55 @@ IF_NO_GC(
|
|||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// Android: check subdir and localization directly, as AAssetDir and thereby
|
||||
// NSDirectoryEnumerator doesn't list directories
|
||||
/* Android: check subdir and localization directly, as AAssetDir and thereby
|
||||
* NSDirectoryEnumerator doesn't list directories
|
||||
*/
|
||||
NSString *originalPrimary = primary;
|
||||
if (subPath) {
|
||||
primary = [originalPrimary stringByAppendingPathComponent: subPath];
|
||||
contents = bundle_directory_readable(primary);
|
||||
addBundlePath(array, contents, primary, nil, nil);
|
||||
|
||||
if (localization) {
|
||||
primary = [primary stringByAppendingPathComponent:
|
||||
[localization stringByAppendingPathExtension:@"lproj"]];
|
||||
if (subPath)
|
||||
{
|
||||
primary = [originalPrimary stringByAppendingPathComponent: subPath];
|
||||
contents = bundle_directory_readable(primary);
|
||||
addBundlePath(array, contents, primary, nil, nil);
|
||||
} else {
|
||||
NSString *subPathPrimary = primary;
|
||||
enumerate = [languages objectEnumerator];
|
||||
while ((language = [enumerate nextObject])) {
|
||||
primary = [subPathPrimary stringByAppendingPathComponent:
|
||||
[language stringByAppendingPathExtension:@"lproj"]];
|
||||
contents = bundle_directory_readable(primary);
|
||||
addBundlePath(array, contents, primary, nil, nil);
|
||||
}
|
||||
|
||||
if (localization)
|
||||
{
|
||||
primary = [primary stringByAppendingPathComponent:
|
||||
[localization stringByAppendingPathExtension: @"lproj"]];
|
||||
contents = bundle_directory_readable(primary);
|
||||
addBundlePath(array, contents, primary, nil, nil);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *subPathPrimary = primary;
|
||||
|
||||
enumerate = [languages objectEnumerator];
|
||||
while ((language = [enumerate nextObject]))
|
||||
{
|
||||
primary = [subPathPrimary stringByAppendingPathComponent:
|
||||
[language stringByAppendingPathExtension: @"lproj"]];
|
||||
contents = bundle_directory_readable(primary);
|
||||
addBundlePath(array, contents, primary, nil, nil);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (localization) {
|
||||
primary = [originalPrimary stringByAppendingPathComponent:
|
||||
[localization stringByAppendingPathExtension:@"lproj"]];
|
||||
contents = bundle_directory_readable(primary);
|
||||
addBundlePath(array, contents, primary, nil, nil);
|
||||
} else {
|
||||
enumerate = [languages objectEnumerator];
|
||||
while ((language = [enumerate nextObject])) {
|
||||
if (localization)
|
||||
{
|
||||
primary = [originalPrimary stringByAppendingPathComponent:
|
||||
[language stringByAppendingPathExtension:@"lproj"]];
|
||||
[localization stringByAppendingPathExtension: @"lproj"]];
|
||||
contents = bundle_directory_readable(primary);
|
||||
addBundlePath(array, contents, primary, nil, nil);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
enumerate = [languages objectEnumerator];
|
||||
while ((language = [enumerate nextObject]))
|
||||
{
|
||||
primary = [originalPrimary stringByAppendingPathComponent:
|
||||
[language stringByAppendingPathExtension: @"lproj"]];
|
||||
contents = bundle_directory_readable(primary);
|
||||
addBundlePath(array, contents, primary, nil, nil);
|
||||
}
|
||||
}
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
primary = rootPath;
|
||||
|
@ -2269,7 +2281,7 @@ IF_NO_GC(
|
|||
|
||||
#if !defined(_WIN32)
|
||||
if (_frameworkVersion)
|
||||
rootPath = [NSString stringWithFormat:@"%@/Versions/%@", [self bundlePath],
|
||||
rootPath = [NSString stringWithFormat: @"%@/Versions/%@", [self bundlePath],
|
||||
_frameworkVersion];
|
||||
else
|
||||
#endif
|
||||
|
@ -2548,13 +2560,17 @@ IF_NO_GC(
|
|||
NSArray *languages = [[NSUserDefaults standardUserDefaults]
|
||||
stringArrayForKey: @"NSLanguages"];
|
||||
|
||||
for (locale in languages) {
|
||||
NSString *path = [self pathForResource:@"Localizable" ofType:@"strings"
|
||||
inDirectory:nil forLocalization:locale];
|
||||
if (path) {
|
||||
[array addObject: locale];
|
||||
for (locale in languages)
|
||||
{
|
||||
NSString *path = [self pathForResource: @"Localizable"
|
||||
ofType: @"strings"
|
||||
inDirectory: nil
|
||||
forLocalization: locale];
|
||||
if (path)
|
||||
{
|
||||
[array addObject: locale];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
return GS_IMMUTABLE(array);
|
||||
|
@ -2764,7 +2780,7 @@ IF_NO_GC(
|
|||
withString: @"_1"];
|
||||
|
||||
#if !defined(_WIN32)
|
||||
path = [_path stringByAppendingPathComponent:@"Versions/Current"];
|
||||
path = [_path stringByAppendingPathComponent: @"Versions/Current"];
|
||||
#else
|
||||
path = _path;
|
||||
#endif
|
||||
|
@ -2798,7 +2814,7 @@ IF_NO_GC(
|
|||
{
|
||||
#if !defined(_WIN32)
|
||||
return [_path stringByAppendingPathComponent:
|
||||
[NSString stringWithFormat:@"Versions/%@/%@",
|
||||
[NSString stringWithFormat: @"Versions/%@/%@",
|
||||
version, executableName]];
|
||||
#else
|
||||
return [_path stringByAppendingPathComponent: executableName];
|
||||
|
@ -2827,7 +2843,7 @@ IF_NO_GC(
|
|||
{
|
||||
#if !defined(_WIN32)
|
||||
return [_path stringByAppendingPathComponent:
|
||||
[NSString stringWithFormat:@"Versions/%@/Resources",
|
||||
[NSString stringWithFormat: @"Versions/%@/Resources",
|
||||
version]];
|
||||
#else
|
||||
/* No Versions (that require symlinks) on mswindows */
|
||||
|
@ -2884,7 +2900,7 @@ IF_NO_GC(
|
|||
{
|
||||
#if !defined(_WIN32)
|
||||
return [_path stringByAppendingPathComponent:
|
||||
[NSString stringWithFormat:@"Versions/%@/PlugIns",
|
||||
[NSString stringWithFormat: @"Versions/%@/PlugIns",
|
||||
version]];
|
||||
#else
|
||||
return [_path stringByAppendingPathComponent: @"PlugIns"];
|
||||
|
@ -2912,8 +2928,8 @@ IF_NO_GC(
|
|||
{
|
||||
#if !defined(_WIN32)
|
||||
return [_path stringByAppendingPathComponent:
|
||||
[NSString stringWithFormat:@"Versions/%@/PrivateFrameworks",
|
||||
version]];
|
||||
[NSString stringWithFormat: @"Versions/%@/PrivateFrameworks",
|
||||
version]];
|
||||
#else
|
||||
return [_path stringByAppendingPathComponent: @"PrivateFrameworks"];
|
||||
#endif
|
||||
|
@ -3282,13 +3298,14 @@ IF_NO_GC(
|
|||
|
||||
+ (AAssetManager *)assetManager
|
||||
{
|
||||
return _assetManager;
|
||||
return _assetManager;
|
||||
}
|
||||
|
||||
+ (void)setJavaAssetManager:(jobject)jassetManager withJNIEnv:(JNIEnv *)env
|
||||
+ (void) setJavaAssetManager: (jobject)jassetManager withJNIEnv: (JNIEnv *)env
|
||||
{
|
||||
// create global reference to Java asset manager to prevent garbage
|
||||
// collection
|
||||
/* create global reference to Java asset manager to prevent garbage
|
||||
* collection
|
||||
*/
|
||||
_jassetManager = (*env)->NewGlobalRef(env, jassetManager);
|
||||
|
||||
// get native asset manager (may be shared across multiple threads)
|
||||
|
@ -3298,62 +3315,72 @@ IF_NO_GC(
|
|||
[_mainBundle cleanPathCache];
|
||||
}
|
||||
|
||||
+ (AAsset *)assetForPath:(NSString *)path
|
||||
+ (AAsset *) assetForPath: (NSString *)path
|
||||
{
|
||||
return [self assetForPath:path withMode:AASSET_MODE_UNKNOWN];
|
||||
return [self assetForPath: path withMode: AASSET_MODE_UNKNOWN];
|
||||
}
|
||||
|
||||
+ (AAsset *)assetForPath:(NSString *)path withMode:(int)mode
|
||||
+ (AAsset *) assetForPath: (NSString *)path withMode: (int)mode
|
||||
{
|
||||
AAsset *asset = NULL;
|
||||
|
||||
if (_assetManager && _mainBundle)
|
||||
{
|
||||
NSString *resourcePath = [_mainBundle resourcePath];
|
||||
|
||||
if ([path hasPrefix:resourcePath] && [path length] > [resourcePath length])
|
||||
{
|
||||
NSString *assetPath = [path substringFromIndex:[resourcePath length]+1];
|
||||
NSString *resourcePath = [_mainBundle resourcePath];
|
||||
|
||||
asset = AAssetManager_open(_assetManager,
|
||||
[assetPath fileSystemRepresentation], mode);
|
||||
if ([path hasPrefix: resourcePath]
|
||||
&& [path length] > [resourcePath length])
|
||||
{
|
||||
NSString *assetPath;
|
||||
|
||||
assetPath = [path substringFromIndex: [resourcePath length] + 1];
|
||||
asset = AAssetManager_open(_assetManager,
|
||||
[assetPath fileSystemRepresentation], mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
+ (AAssetDir *)assetDirForPath:(NSString *)path
|
||||
+ (AAssetDir *) assetDirForPath: (NSString *)path
|
||||
{
|
||||
AAssetDir *assetDir = NULL;
|
||||
|
||||
if (_assetManager && _mainBundle)
|
||||
{
|
||||
NSString *resourcePath = [_mainBundle resourcePath];
|
||||
|
||||
if ([path hasPrefix:resourcePath])
|
||||
{
|
||||
NSString *assetPath = @"";
|
||||
if ([path length] > [resourcePath length]) {
|
||||
assetPath = [path substringFromIndex:[resourcePath length] + 1];
|
||||
}
|
||||
NSString *resourcePath = [_mainBundle resourcePath];
|
||||
|
||||
assetDir = AAssetManager_openDir(_assetManager,
|
||||
[assetPath fileSystemRepresentation]);
|
||||
|
||||
if (assetDir) {
|
||||
// AAssetManager_openDir() always returns an object, so we check if
|
||||
// the directory exists by ensuring it contains a file
|
||||
BOOL exists = AAssetDir_getNextFileName(assetDir) != NULL;
|
||||
if (exists) {
|
||||
AAssetDir_rewind(assetDir);
|
||||
} else {
|
||||
AAssetDir_close(assetDir);
|
||||
assetDir = NULL;
|
||||
}
|
||||
}
|
||||
if ([path hasPrefix: resourcePath])
|
||||
{
|
||||
NSString *assetPath = @"";
|
||||
|
||||
if ([path length] > [resourcePath length])
|
||||
{
|
||||
assetPath = [path substringFromIndex: [resourcePath length] + 1];
|
||||
}
|
||||
|
||||
assetDir = AAssetManager_openDir(_assetManager,
|
||||
[assetPath fileSystemRepresentation]);
|
||||
|
||||
if (assetDir)
|
||||
{
|
||||
/* AAssetManager_openDir() always returns an object,
|
||||
* so we check if the directory exists by ensuring
|
||||
* it contains a file
|
||||
*/
|
||||
BOOL exists = AAssetDir_getNextFileName(assetDir) != NULL;
|
||||
if (exists)
|
||||
{
|
||||
AAssetDir_rewind(assetDir);
|
||||
}
|
||||
else
|
||||
{
|
||||
AAssetDir_close(assetDir);
|
||||
assetDir = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return assetDir;
|
||||
}
|
||||
|
|
|
@ -245,31 +245,36 @@ readContentsOfFile(NSString *path, void **buf, off_t *len, NSZone *zone)
|
|||
|
||||
#ifdef __ANDROID__
|
||||
// Android: try using asset manager if path is in main bundle resources
|
||||
AAsset *asset = [NSBundle assetForPath:path withMode:AASSET_MODE_BUFFER];
|
||||
if (asset) {
|
||||
fileLength = AAsset_getLength(asset);
|
||||
AAsset *asset = [NSBundle assetForPath: path withMode: AASSET_MODE_BUFFER];
|
||||
if (asset)
|
||||
{
|
||||
fileLength = AAsset_getLength(asset);
|
||||
|
||||
tmp = NSZoneMalloc(zone, fileLength);
|
||||
if (tmp == 0) {
|
||||
NSLog(@"Malloc failed for file (%@) of length %jd - %@", path,
|
||||
(intmax_t)fileLength, [NSError _last]);
|
||||
tmp = NSZoneMalloc(zone, fileLength);
|
||||
if (tmp == 0)
|
||||
{
|
||||
NSLog(@"Malloc failed for file (%@) of length %jd - %@", path,
|
||||
(intmax_t)fileLength, [NSError _last]);
|
||||
AAsset_close(asset);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
int result = AAsset_read(asset, tmp, fileLength);
|
||||
AAsset_close(asset);
|
||||
goto failure;
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
NSWarnFLog(@"read of file (%@) contents failed - %@", path,
|
||||
[NSError errorWithDomain: NSPOSIXErrorDomain
|
||||
code: result
|
||||
userInfo: nil]);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
*buf = tmp;
|
||||
*len = fileLength;
|
||||
return YES;
|
||||
}
|
||||
|
||||
int result = AAsset_read(asset, tmp, fileLength);
|
||||
AAsset_close(asset);
|
||||
|
||||
if (result < 0) {
|
||||
NSWarnFLog(@"read of file (%@) contents failed - %@", path,
|
||||
[NSError errorWithDomain:NSPOSIXErrorDomain code:result userInfo:nil]);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
*buf = tmp;
|
||||
*len = fileLength;
|
||||
return YES;
|
||||
}
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
|
|
@ -738,7 +738,7 @@ static NSStringEncoding defaultEncoding;
|
|||
|
||||
nxtImp = [direnum methodForSelector: @selector(nextObject)];
|
||||
|
||||
urlArray = [NSMutableArray arrayWithCapacity:128];
|
||||
urlArray = [NSMutableArray arrayWithCapacity: 128];
|
||||
while ((tempPath = (*nxtImp)(direnum, @selector(nextObject))) != nil)
|
||||
{
|
||||
NSURL *tempURL;
|
||||
|
@ -749,7 +749,7 @@ static NSStringEncoding defaultEncoding;
|
|||
|
||||
/* we purge files beginning with . */
|
||||
if (!((mask & NSDirectoryEnumerationSkipsHiddenFiles)
|
||||
&& [lastComponent hasPrefix:@"."]))
|
||||
&& [lastComponent hasPrefix: @"."]))
|
||||
{
|
||||
[urlArray addObject: tempURL];
|
||||
}
|
||||
|
@ -1653,21 +1653,26 @@ static NSStringEncoding defaultEncoding;
|
|||
if (_STAT(lpath, &statbuf) != 0)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
// Android: try using asset manager if path is in main bundle resources
|
||||
AAsset *asset = [NSBundle assetForPath:path];
|
||||
if (asset) {
|
||||
AAsset_close(asset);
|
||||
return YES;
|
||||
}
|
||||
/* Android: try using asset manager if path is in
|
||||
* main bundle resources
|
||||
*/
|
||||
AAsset *asset = [NSBundle assetForPath: path];
|
||||
if (asset)
|
||||
{
|
||||
AAsset_close(asset);
|
||||
return YES;
|
||||
}
|
||||
|
||||
AAssetDir *assetDir = [NSBundle assetDirForPath:path];
|
||||
if (assetDir) {
|
||||
AAssetDir_close(assetDir);
|
||||
if (isDirectory) {
|
||||
*isDirectory = YES;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
AAssetDir *assetDir = [NSBundle assetDirForPath: path];
|
||||
if (assetDir)
|
||||
{
|
||||
AAssetDir_close(assetDir);
|
||||
if (isDirectory)
|
||||
{
|
||||
*isDirectory = YES;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
#endif
|
||||
|
||||
return NO;
|
||||
|
@ -1721,11 +1726,12 @@ static NSStringEncoding defaultEncoding;
|
|||
|
||||
#ifdef __ANDROID__
|
||||
// Android: try using asset manager if path is in main bundle resources
|
||||
AAsset *asset = [NSBundle assetForPath:path];
|
||||
if (asset) {
|
||||
AAsset_close(asset);
|
||||
return YES;
|
||||
}
|
||||
AAsset *asset = [NSBundle assetForPath: path];
|
||||
if (asset)
|
||||
{
|
||||
AAsset_close(asset);
|
||||
return YES;
|
||||
}
|
||||
#endif
|
||||
|
||||
return NO;
|
||||
|
@ -2203,8 +2209,8 @@ static NSStringEncoding defaultEncoding;
|
|||
*/
|
||||
- (NSDictionary*) fileSystemAttributesAtPath: (NSString*)path
|
||||
{
|
||||
return [self attributesOfFileSystemForPath:path
|
||||
error:NULL];
|
||||
return [self attributesOfFileSystemForPath: path
|
||||
error: NULL];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2416,9 +2422,10 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
DESTROY(X.path);
|
||||
_CLOSEDIR(X.pointer);
|
||||
#ifdef __ANDROID__
|
||||
if (X.assetDir) {
|
||||
AAssetDir_close(X.assetDir);
|
||||
}
|
||||
if (X.assetDir)
|
||||
{
|
||||
AAssetDir_close(X.assetDir);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -2480,10 +2487,13 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
|
||||
#ifdef __ANDROID__
|
||||
AAssetDir *assetDir = NULL;
|
||||
if (!dir_pointer) {
|
||||
// Android: try using asset manager if path is in main bundle resources
|
||||
assetDir = [NSBundle assetDirForPath:path];
|
||||
}
|
||||
if (!dir_pointer)
|
||||
{
|
||||
/* Android: try using asset manager if path is in
|
||||
* main bundle resources
|
||||
*/
|
||||
assetDir = [NSBundle assetDirForPath: path];
|
||||
}
|
||||
|
||||
if (dir_pointer || assetDir)
|
||||
#else
|
||||
|
@ -2592,19 +2602,21 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
|
||||
#ifdef __ANDROID__
|
||||
if (dir.assetDir)
|
||||
{
|
||||
// This will only return files and not directories, which means that
|
||||
// recursion is not supported.
|
||||
// See https://issuetracker.google.com/issues/37002833
|
||||
dirname = AAssetDir_getNextFileName(dir.assetDir);
|
||||
}
|
||||
{
|
||||
/* This will only return files and not directories, which means that
|
||||
* recursion is not supported.
|
||||
* See https://issuetracker.google.com/issues/37002833
|
||||
*/
|
||||
dirname = AAssetDir_getNextFileName(dir.assetDir);
|
||||
}
|
||||
else if (dir.pointer)
|
||||
#endif
|
||||
{
|
||||
struct _DIRENT *dirbuf = _READDIR(dir.pointer);
|
||||
if (dirbuf) {
|
||||
dirname = dirbuf->d_name;
|
||||
}
|
||||
if (dirbuf)
|
||||
{
|
||||
dirname = dirbuf->d_name;
|
||||
}
|
||||
}
|
||||
|
||||
if (dirname)
|
||||
|
@ -2930,10 +2942,11 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
sourceFd = open([self fileSystemRepresentationWithPath: source],
|
||||
GSBINIO|O_RDONLY);
|
||||
#ifdef __ANDROID__
|
||||
if (sourceFd < 0) {
|
||||
// Android: try using asset manager if path is in main bundle resources
|
||||
asset = [NSBundle assetForPath:source withMode:AASSET_MODE_STREAMING];
|
||||
}
|
||||
if (sourceFd < 0)
|
||||
{
|
||||
// Android: try using asset manager if path is in main bundle resources
|
||||
asset = [NSBundle assetForPath: source withMode: AASSET_MODE_STREAMING];
|
||||
}
|
||||
if (sourceFd < 0 && asset == NULL)
|
||||
#else
|
||||
if (sourceFd < 0)
|
||||
|
@ -2952,9 +2965,10 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
if (destFd < 0)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
if (asset) {
|
||||
AAsset_close(asset);
|
||||
}
|
||||
if (asset)
|
||||
{
|
||||
AAsset_close(asset);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
close (sourceFd);
|
||||
|
@ -2971,9 +2985,10 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
for (i = 0; i < fileSize; i += rbytes)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
if (asset) {
|
||||
rbytes = AAsset_read(asset, buffer, bufsize);
|
||||
}
|
||||
if (asset)
|
||||
{
|
||||
rbytes = AAsset_read(asset, buffer, bufsize);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
rbytes = read (sourceFd, buffer, bufsize);
|
||||
|
@ -2984,9 +2999,10 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
break; // End of input file
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
if (asset) {
|
||||
AAsset_close(asset);
|
||||
}
|
||||
if (asset)
|
||||
{
|
||||
AAsset_close(asset);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
close (sourceFd);
|
||||
|
@ -3003,9 +3019,10 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
if (wbytes != rbytes)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
if (asset) {
|
||||
AAsset_close(asset);
|
||||
}
|
||||
if (asset)
|
||||
{
|
||||
AAsset_close(asset);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
close (sourceFd);
|
||||
|
@ -3019,9 +3036,10 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
}
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
if (asset) {
|
||||
AAsset_close(asset);
|
||||
}
|
||||
if (asset)
|
||||
{
|
||||
AAsset_close(asset);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
close (sourceFd);
|
||||
|
@ -3388,8 +3406,10 @@ static NSSet *fileKeys = nil;
|
|||
if (lstat(lpath, &d->statbuf) != 0)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
// Android: try using asset manager if path is in main bundle resources
|
||||
asset = [NSBundle assetForPath:path];
|
||||
/* Android: try using asset manager if path is in
|
||||
* main bundle resources
|
||||
*/
|
||||
asset = [NSBundle assetForPath: path];
|
||||
if (asset == NULL)
|
||||
#endif
|
||||
DESTROY(d);
|
||||
|
@ -3401,7 +3421,7 @@ static NSSet *fileKeys = nil;
|
|||
{
|
||||
#ifdef __ANDROID__
|
||||
// Android: try using asset manager if path is in main bundle resources
|
||||
asset = [NSBundle assetForPath:path];
|
||||
asset = [NSBundle assetForPath: path];
|
||||
if (asset == NULL)
|
||||
#endif
|
||||
DESTROY(d);
|
||||
|
@ -3413,13 +3433,14 @@ static NSSet *fileKeys = nil;
|
|||
d->_path[i] = lpath[i];
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
if (asset) {
|
||||
// set some basic stat values for Android assets
|
||||
memset(&d->statbuf, 0, sizeof(d->statbuf));
|
||||
d->statbuf.st_mode = S_IRUSR;
|
||||
d->statbuf.st_size = AAsset_getLength(asset);
|
||||
AAsset_close(asset);
|
||||
}
|
||||
if (asset)
|
||||
{
|
||||
// set some basic stat values for Android assets
|
||||
memset(&d->statbuf, 0, sizeof(d->statbuf));
|
||||
d->statbuf.st_mode = S_IRUSR;
|
||||
d->statbuf.st_size = AAsset_getLength(asset);
|
||||
AAsset_close(asset);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return AUTORELEASE(d);
|
||||
|
|
|
@ -2580,12 +2580,56 @@ GSPrivateMemorySize(NSObject *self, NSHashTable *exclude)
|
|||
}
|
||||
|
||||
@implementation NSObject (MemoryFootprint)
|
||||
+ (NSUInteger) contentSizeInBytesOf: (NSObject*)instance
|
||||
excluding: (NSHashTable*)exclude
|
||||
{
|
||||
unsigned count;
|
||||
Ivar *vars;
|
||||
NSUInteger size = 0;
|
||||
|
||||
if (0 != (vars = class_copyIvarList(self, &count)))
|
||||
{
|
||||
while (count-- > 0)
|
||||
{
|
||||
const char *type = ivar_getTypeEncoding(vars[count]);
|
||||
|
||||
type = GSSkipTypeQualifierAndLayoutInfo(type);
|
||||
if ('@' == *type)
|
||||
{
|
||||
NSObject *obj = object_getIvar(instance, vars[count]);
|
||||
|
||||
if (obj != nil)
|
||||
{
|
||||
size += [obj sizeInBytesExcluding: exclude];
|
||||
}
|
||||
}
|
||||
}
|
||||
free(vars);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
+ (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
|
||||
{
|
||||
return GSPrivateMemorySize(self, exclude);
|
||||
if (0 == NSHashGet(exclude, self))
|
||||
{
|
||||
Class c = object_getClass(self);
|
||||
NSUInteger size = class_getInstanceSize(c);
|
||||
|
||||
NSHashInsert(exclude, self);
|
||||
if (size > 0)
|
||||
{
|
||||
while (c != Nil)
|
||||
{
|
||||
size += [c contentSizeInBytesOf: self excluding: exclude];
|
||||
}
|
||||
c = class_getSuperclass(c);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -952,20 +952,24 @@ extern char **__libc_argv;
|
|||
&& !_gnu_processName && !_gnu_arguments && !_gnu_environment)
|
||||
{
|
||||
FILE *f = fopen("/proc/self/cmdline", "r");
|
||||
if (f) {
|
||||
char identifier[BUFSIZ];
|
||||
fgets(identifier, sizeof(identifier), f);
|
||||
fclose(f);
|
||||
|
||||
// construct fake executable path
|
||||
char *arg0;
|
||||
asprintf(&arg0, "/data/data/%s/exe", identifier);
|
||||
|
||||
char *argv[] = { arg0 };
|
||||
_gnu_process_args(sizeof(argv)/sizeof(char *), argv, NULL);
|
||||
} else {
|
||||
fprintf(stderr, "Failed to read cmdline\n");
|
||||
}
|
||||
if (f)
|
||||
{
|
||||
char identifier[BUFSIZ];
|
||||
fgets(identifier, sizeof(identifier), f);
|
||||
fclose(f);
|
||||
|
||||
// construct fake executable path
|
||||
char *arg0;
|
||||
asprintf(&arg0, "/data/data/%s/exe", identifier);
|
||||
|
||||
char *argv[] = { arg0 };
|
||||
_gnu_process_args(sizeof(argv)/sizeof(char *), argv, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Failed to read cmdline\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue