Contents | Prev | Next

4.2.61.1 The permission constants

Irie Pascal supports ten built-in integer constants which can be used with the built-in procedures mkdir and getfilemode to specify or identify read, write, and execute/search permissions, as well as to find out whether a file is a directory/folder.

The permission constants are listed below:

Example

For example the simple program below asks for a filename and then displays the all the file permissions for the file.

program AllPermissions(input, output);
var
   s : filename;
   mode : integer;
   isdir : boolean;
begin
   write('Enter filename:');
   readln(s);
   s := fexpand(s);
   getfilemode(s, mode);
   isdir := (mode and dir_bit) <> 0;
   if isdir then
      writeln(s, ' is a directory')
   else
      writeln(s, ' is not a directory');
   write('Owner permissions :');
   if (mode and usr_r) <> 0 then
      write(' Read');
   if (mode and usr_w) <> 0 then
      write(' Write');
   if (mode and usr_x) <> 0 then
      if isdir then
         write(' Search')
      else
         write(' Execute');
   writeln;
   write('Group permissions :');
   if (mode and grp_r) <> 0 then
      write(' Read');
   if (mode and grp_w) <> 0 then
      write(' Write');
   if (mode and grp_x) <> 0 then
      if isdir then
         write(' Search')
      else
         write(' Execute');
   writeln;
   write('Other permissions :');
   if (mode and oth_r) <> 0 then
      write(' Read');
   if (mode and oth_w) <> 0 then
      write(' Write');
   if (mode and oth_x) <> 0 then
      if isdir then
         write(' Search')
      else
         write(' Execute');
   writeln;
end.

Contents | Prev | Next