Add a few OSX compatibility methods

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33929 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-10-02 11:17:49 +00:00
parent 377a757e54
commit cbf54ac301
8 changed files with 111 additions and 27 deletions

View file

@ -10,8 +10,12 @@ int main()
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *dir = @"NSFileManagerTestDir";
NSString *dirInDir = [@"TestDirectory" stringByAppendingPathComponent: @"WithinDirectory"];
NSString *dirInDir;
NSString *str1,*str2;
dirInDir
= [@"TestDirectory" stringByAppendingPathComponent: @"WithinDirectory"];
PASS(mgr != nil && [mgr isKindOfClass: [NSFileManager class]],
"NSFileManager understands +defaultManager");
@ -63,6 +67,14 @@ NSLog(@"'%@', '%@'", NSUserName(), [attr fileOwnerAccountName]);
"NSFileManager creates a file");
PASS([mgr fileExistsAtPath: @"NSFMFile"],"-fileExistsAtPath: agrees");
{
NSArray *a;
a = [mgr contentsOfDirectoryAtPath: @"." error: 0];
PASS(1 == [a count] && [[a lastObject] isEqual: @"NSFMFile"],
"-contentsOfDirectoryAtPath: agrees");
}
{
NSData *dat1 = [mgr contentsAtPath: @"NSFMFile"];
str2 = [[NSString alloc] initWithData: dat1 encoding: 1];

View file

@ -10,31 +10,32 @@ copyright 2004 Alexander Malmberg <alexander@malmberg.org>
int main(int argc, char **argv)
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSFileManager *fm=[NSFileManager defaultManager];
NSArray *files;
int i;
BOOL e,d;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *files;
int i;
BOOL e, d;
files=[fm directoryContentsAtPath: @"."];
printf("%lu files\n", (unsigned long)[files count]);
for (i=0;i<[files count];i++)
{
int j;
NSString *f=[files objectAtIndex: i];
e=[fm fileExistsAtPath: f
isDirectory: &d];
printf("%5i: %i %i %s\n",i,e,d, [f lossyCString]);
for (j=0;j<[f length];j++)
printf(" %3i: %04x\n",j,[f characterAtIndex: j]);
}
files = [fm directoryContentsAtPath: @"."];
printf("%lu files\n", (unsigned long)[files count]);
for (i = 0; i < [files count]; i++)
{
int j;
NSString *f = [files objectAtIndex: i];
/* const char *test="hallå.txt";
NSString *s=[NSString stringWithCString: test];
printf("s=%s\n", [s lossyCString]);*/
e = [fm fileExistsAtPath: f
isDirectory: &d];
printf("%5i: %i %i %s\n",i,e,d, [f lossyCString]);
for (j = 0; j < [f length]; j++)
printf(" %3i: %04x\n",j,[f characterAtIndex: j]);
}
[arp release]; arp = nil;
/* const char *test="hallå.txt";
NSString *s=[NSString stringWithCString: test];
printf("s=%s\n", [s lossyCString]);*/
return 0;
[arp release]; arp = nil;
return 0;
}