home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ZOO21E.EXE / NIXMODE.I < prev    next >
Text File  |  1991-07-11  |  1KB  |  43 lines

  1. #ifndef LINT
  2. /* @(#) nixmode.i 1.2 88/01/24 12:48:57 */
  3. static char modeid[]="@(#) nixmode.i 1.2 88/01/24 12:48:57";
  4. #endif
  5.  
  6. /*
  7. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  8.  
  9. UNIX-specific routines to get and set file attribute.  These might be
  10. usable on other systems that have the following identical things:
  11. fileno(), fstat(), chmod(), sys/types.h and sys/stat.h.
  12. */
  13.  
  14. /*
  15. Get file attributes.  Currently only the lowest nine of the
  16. **IX mode bits are used.  Also we return bit 23=0 and bit 22=1,
  17. which means use portable attribute format, and use attribute
  18. value instead of using default at extraction time.
  19. */
  20.  
  21. unsigned long getfattr (f)
  22. ZOOFILE f;
  23. {
  24.     int fd;
  25.    struct stat buf;           /* buffer to hold file information */
  26.     fd = fileno(f);
  27.    if (fstat (fd, &buf) == -1)
  28.       return (NO_FATTR);      /* inaccessible -- no attributes */
  29.     else
  30.         return (unsigned long) (buf.st_mode & 0x1ffL) | (1L << 22);
  31. }
  32.  
  33. /*
  34. Set file attributes.  Only the lowest nine bits are used.
  35. */
  36.  
  37. int setfattr (f, a)
  38. char *f;                            /* filename */
  39. unsigned long a;                /* atributes to set */
  40. {
  41.     return (chmod (f, (int) (a & 0x1ff)));
  42. }
  43.