0


I am trying to read file permissions in Cocoa of a file having rw-r--r-- (hence 0644).
The code I am using is the following:

NSUInteger permissions;
permissions=[[fileManager attributesOfItemAtPath:file error:nil] filePosixPermissions];
NSLog(@"Permissions:%lu",permissions);

And the result is 420 when the expected result should be 644.

Do I do a calculation error ? Thanks !

Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89

1 Answers1

2

When you see 0644, it's actually the octal (base 8) representation of the permissions.

420 is the base 10 equivalent of 0644 in octal.

NSLog can output octal with:

NSLog(@"Permissions:%o", permissions);
joerick
  • 16,078
  • 4
  • 53
  • 57