Upgraded GRUB2 to 2.00 release.
[AROS.git] / compiler / clib / fchmod.c
blob9bcbe39d87a8a4afa08f8128aac63daf45836891
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 function fchmod().
6 */
8 #include <errno.h>
10 #include <aros/debug.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <sys/types.h>
14 #include <stdlib.h>
16 #include "__fdesc.h"
17 #include "__upath.h"
19 ULONG prot_u2a(mode_t protect);
21 /*****************************************************************************
23 NAME */
24 #include <sys/types.h>
25 #include <sys/stat.h>
27 int fchmod (
29 /* SYNOPSIS */
30 int filedes,
31 mode_t mode)
33 /* FUNCTION
34 Change permission bits of a file specified by an open file descriptor.
36 INPUTS
37 filedes - File descriptor of the file
38 mode - Permission bits to set
40 RESULT
41 0 on success and -1 on error. If an error occurred, the global
42 variable errno is set.
44 NOTES
45 See chmod() documentation for more details about the mode parameter.
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 chmod()
54 INTERNALS
56 ******************************************************************************/
58 fdesc *fdesc;
59 UBYTE *buffer;
60 int buffersize = 256;
62 if (!(fdesc = __getfdesc(filedes)))
64 errno = EBADF;
65 return -1;
68 /* Get the full path of the stated filesystem object and use it to
69 compute hash value */
72 if(!(buffer = AllocVec(buffersize, MEMF_ANY)))
74 errno = __arosc_ioerr2errno(IoErr());
75 return -1;
78 if(NameFromFH(fdesc->fcb->fh, buffer, buffersize))
79 break;
80 else if(IoErr() != ERROR_LINE_TOO_LONG)
82 errno = __arosc_ioerr2errno(IoErr());
83 FreeVec(buffer);
84 return -1;
86 FreeVec(buffer);
87 buffersize *= 2;
89 while(TRUE);
91 if (!SetProtection(buffer, prot_u2a(mode)))
93 FreeVec(buffer);
94 errno = __arosc_ioerr2errno(IoErr());
95 return -1;
98 FreeVec(buffer);
99 return 0;
100 } /* fchmod */