muimaster.library: support Listview_List in List
[AROS.git] / compiler / posixc / fchmod.c
blob22251c30eb8780dffdd256b95eecdddbf523ad64
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 /* The following function is located in chmod.c */
20 ULONG prot_u2a(mode_t protect);
22 /*****************************************************************************
24 NAME */
25 #include <sys/types.h>
26 #include <sys/stat.h>
28 int fchmod (
30 /* SYNOPSIS */
31 int filedes,
32 mode_t mode)
34 /* FUNCTION
35 Change permission bits of a file specified by an open file descriptor.
37 INPUTS
38 filedes - File descriptor of the file
39 mode - Permission bits to set
41 RESULT
42 0 on success and -1 on error. If an error occurred, the global
43 variable errno is set.
45 NOTES
46 See chmod() documentation for more details about the mode parameter.
48 EXAMPLE
50 BUGS
52 SEE ALSO
53 chmod()
55 INTERNALS
57 ******************************************************************************/
59 fdesc *fdesc;
60 UBYTE *buffer;
61 int buffersize = 256;
63 if (!(fdesc = __getfdesc(filedes)))
65 errno = EBADF;
66 return -1;
69 /* Get the full path of the stated filesystem object and use it to
70 compute hash value */
73 if(!(buffer = AllocVec(buffersize, MEMF_ANY)))
75 errno = __stdc_ioerr2errno(IoErr());
76 return -1;
79 if(NameFromFH(fdesc->fcb->handle, buffer, buffersize))
80 break;
81 else if(IoErr() != ERROR_LINE_TOO_LONG)
83 errno = __stdc_ioerr2errno(IoErr());
84 FreeVec(buffer);
85 return -1;
87 FreeVec(buffer);
88 buffersize *= 2;
90 while(TRUE);
92 if (!SetProtection(buffer, prot_u2a(mode)))
94 FreeVec(buffer);
95 errno = __stdc_ioerr2errno(IoErr());
96 return -1;
99 FreeVec(buffer);
100 return 0;
101 } /* fchmod */