#include <stdio.h>
#include <stdlib.h>
#include <rsbac/types.h>
#include <rsbac/getname.h>
#include <rsbac/syscalls.h>
#include <rsbac/error.h>

int main(int argc, char ** argv)
{
  char tmp1[80];
  int res = 0;
  int i,mode;
  rsbac_pm_object_class_id_t class;
  
  if (argc > 3)
    {
      class = strtol(argv[1],0,0);
      mode  = strtol(argv[2],0,8);
      printf("%s: %i files of class %i, mode %o to be created\n\n",
             argv[0], argc - 3, class, mode);
      for (i=1;i < (argc-2);i++)
        {
          printf("Processing %s (No. %i)\n",
                 argv[i+2], i);
          res = rsbac_pm_create_file(argv[i+2],mode,class);
          if(res)
            {
              if((res > -RSBAC_EPERM) || (res < -RSBAC_EDECISIONMISMATCH))
                printf("%s: error: %s\n", argv[0], strerror(-res));
              else
                {
                  get_error_name(tmp1,res);
                  printf("%s: error: %s\n", argv[0], tmp1);
                }
            }
        }
    }
  else
    {
      printf("%s (RSBAC %s)\n***\n", argv[0], VERSION);
      printf("Use: %s class mode filename(s)\n\n", argv[0]);  
    }
    
  return (res);
}

