home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / library / fchown.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  2KB  |  54 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *  Portions Copyright (C) 1996 Jeff Shepherd
  6.  *
  7.  *  This library is free software; you can redistribute it and/or
  8.  *  modify it under the terms of the GNU Library General Public
  9.  *  License as published by the Free Software Foundation; either
  10.  *  version 2 of the License, or (at your option) any later version.
  11.  *
  12.  *  This library is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  *  Library General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU Library General Public
  18.  *  License along with this library; if not, write to the Free
  19.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. #define _KERNEL
  23. #include "ixemul.h"
  24. #include "kprintf.h"
  25. #include <stdlib.h>
  26.  
  27. int
  28. fchown(int fd, uid_t uid, gid_t gid)
  29. {
  30.   struct file *f = u.u_ofile[fd];
  31.   struct stat stb;
  32.  
  33.   if (fd >= 0 && fd < NOFILE && f)
  34.     {
  35.       if (syscall (SYS_fstat, fd, &stb) == -1) return -1;
  36.       if (stb.st_mode & 0600)
  37.         {
  38.           if (syscall (SYS_fchmod, fd, stb.st_mode & ~0176000) == -1) return -1;
  39.         }
  40.  
  41.       if (uid == (uid_t)(-1)) uid = stb.st_uid;
  42.       if (gid == (gid_t)(-1)) gid = stb.st_gid;
  43.  
  44.       f->f_stb.st_uid = uid;
  45.       f->f_stb.st_gid = gid;
  46.       f->f_stb_dirty |= FSDF_OWNER;
  47.       return 0;
  48.     }
  49.  
  50.   errno = EBADF;
  51.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  52.   return -1;
  53. }
  54.