Proposal C<stat> opcode and interface

1) ops

  stat (out PMC, in STR, in INT)
  stat (out PMC, in PMC, in INT)

Return a new array-like[1] PMC $1 with file stats from file (PIO or string) $2,
or PerlUndef, if file doesn't exist, $3 are flags:


.PARROT_STAT_NO_FOLLOW_LINK

The array(-like) has keyed access with these keys

  .PARROT_STAT_FILE_SIZE
  .PARROT_STAT_FILE_SIZE_LO
  .PARROT_STAT_FILE_SIZE_HI

  .PARROT_STAT_MODE a bitmask with these bits:
     .PARROT_STAT_MODE_ISDIR
     .PARROT_STAT_MODE_ISFILE
     [ more platform-unspecific bits ]

  .PARROT_STAT_PERM a bitmask with these bits
     .PARROT_STAT_PERM_IS_READABLE
     .PARROT_STAT_PERM_IS_WRITABLE
     .PARROT_STAT_PERM_IS_EXECUTABLE

.PARROT_STAT_MTIME modified time

  .PARROT_STAT_OS_TYPE a constant defining the os-specific
     part that follows
       .PARROT_STAT_stat
       .PARROT_STAT_stat64
       ...

  .PARROT_STAT_OS_SPECIFIC
      A (Un)?ManagedStruct PMC with OS-specific data like a
       struct stat64

2) Interface

   PMC* Parrot_stat_s(Interp*, STRING* file, INTVAL flags);
   PMC* Parrot_stat_p(Interp*, PMC*    pio,  INTVAL flags);

3) Interface to platforms

INTVAL Parrot_stat_os_s(Interp*, Parrot_stat*, STRING* file, INTVAL flags);
INTVAL Parrot_stat_os_p(Interp*, Parrot_stat*, PMC* pio, INTVAL flags);


   typedef struct _parrot_stat {
      size64_t size;
      UINTVAL mode;
      UINTVAL perm;
      FLOATVAL mtime;  // in Parrot units
      UINTVAL os_stat_type;
      union {
        struct stat;
        struct stat64;
        ...
     } u;
   } Parrot_stat;

4) Notes
The information in the first few fields should not be platform
specific. If platforms have more in common then above bits, the
structure should be expanded.

[1] it needs just these vtables implemeted: I0 = P0[i], N0 = P0[i],
i.e. get_{integer,number}_keyed_int

Comments, improvements, and implementations thereafter welcome
leo



Reply via email to