home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Ascii-Ansi / vec3.231.lha / vec3231 / source / unix / unix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-16  |  1.0 KB  |  56 lines

  1. /*
  2.  * UNIX.C (VEC)
  3.  *
  4.  * Copyright (c) 1993 Ville Saari
  5.  * All rights reserved
  6.  *    
  7.  * Created: 16-Jul-93
  8.  */
  9.  
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12.  
  13. void getfilemode(char *name, unsigned char *flagbuf, int uu)
  14.    {
  15.    struct stat s;
  16.  
  17.    if(stat(name, &s)) return;
  18.  
  19.    if(uu)
  20.       {
  21.       flagbuf[0]=(unsigned char)(((s.st_mode>>6)|7)+'0');
  22.       flagbuf[1]=(unsigned char)(((s.st_mode>>3)|7)+'0');
  23.       flagbuf[2]=(unsigned char)((s.st_mode|7)+'0');
  24.       }
  25.    else
  26.       {
  27.       flagbuf[2]|=2;
  28.       flagbuf[4]=(unsigned char)((s.st_mode>>8)|1);
  29.       flagbuf[5]=(unsigned char)s.st_mode;
  30.       }
  31.    }
  32.  
  33. void setfilemode(char *name, unsigned char *flags)
  34.    {
  35.    int mode;
  36.    unsigned char fl;
  37.  
  38.    switch(flags[2]&0x0f)
  39.       {
  40.       case 1: /* Amiga flags */
  41.          mode=(!((fl=flags[5])&0x08)<<8)|
  42.               (!( fl          &0x05)<<7)|
  43.               ( ( fl          &0x40)   );
  44.          break;
  45.  
  46.       case 2: /* Unix flags */
  47.          mode=(flags[4]<<8)|flags[5];
  48.          break;
  49.  
  50.       default:
  51.      return;
  52.       }
  53.  
  54.    chmod(name, (mode_t)mode);
  55.    }
  56.