/* C library  */
/* File information using os_file */
/* RISC User June 1991 */

#include "wimpt.h"
#include "os.h"
#include <stdio.h>


int flib_fileinfo(char *name, int *flen, int *ftype)

/* looks for a single named file
 * returns 0 if absent, 1 if file found, 2 if it is a dir
 * if dir not found, it also returns 0
 * if filing system or drive not found it returns greater than 2
 * if a filing system error occurs, a message box is displayed and
 * -1 is returned
 * it uses os_file 17 (see PRM p. 850)
 *
 *   The os_filestr structure:-
 *       int action;              action or object type if output data 
 *       char * name;             pointer to filename or pathname 
 *       int loadaddr, execaddr;  load, exec addresses 
 *       int start, end;          start address/length, end add./attributes 
 *       int reserved[4];         space to allow treatment as reg_block 
 *       
 * NB osf.end will give access attributes - see PRM 836
 */

{
  os_error *e;
  os_filestr osf;                      /* the structure */

  osf.name=name;
  osf.action=17;
  wimpt_complain(e=os_file(&osf));
  if (e) return -1;
  
  *flen=osf.start;                     /* file length */
  *ftype=(osf.loadaddr >> 8) & 0xfff;  /* file type */
  return osf.action;                   /* 1=file 2=dir -1=err else absent */
}

                                 Listing 1
=========================================================================

int main (int argc, char *argv[])

{
  int len;
  int type;

  if (argc<2)
  {
    printf("no argument given\n") ;
    return 0;
  }
  printf("result %i\n",flib_fileinfo(argv[1], &len, &type));
  printf("len &%x, type &%x\n",len,type);

  return 0;
}
                                 Listing 2
=========================================================================
