Added setting position while duplicating file handles with FMF_WRITE mode. It's neede...
[cake.git] / compiler / clib / fchmod.c
blob2d401ee6d616b3364dab862088735cf263827fce
1 /*
2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C 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 "__stdio.h"
17 #include "__open.h"
18 #include "__errno.h"
19 #include "__upath.h"
21 ULONG prot_u2a(mode_t protect);
23 /*****************************************************************************
25 NAME */
26 #include <sys/types.h>
27 #include <sys/stat.h>
29 int fchmod (
31 /* SYNOPSIS */
32 int filedes,
33 mode_t mode)
35 /* FUNCTION
37 INPUTS
39 RESULT
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
49 INTERNALS
51 HISTORY
53 ******************************************************************************/
55 fdesc *fdesc;
56 UBYTE *buffer;
57 int buffersize = 256;
58 char *path;
60 if (!(fdesc = __getfdesc(filedes)))
62 errno = EBADF;
63 return -1;
66 /* Get the full path of the stated filesystem object and use it to
67 compute hash value */
70 if(!(buffer = AllocVec(buffersize, MEMF_ANY)))
72 errno = IoErr2errno(IoErr());
73 return -1;
76 if(NameFromLock(fdesc->fh, buffer, buffersize))
77 break;
78 else if(IoErr() != ERROR_LINE_TOO_LONG)
80 errno = IoErr2errno(IoErr());
81 FreeVec(buffer);
82 return -1;
84 FreeVec(buffer);
85 buffersize *= 2;
87 while(TRUE);
89 if (!SetProtection(buffer, prot_u2a(mode)))
91 FreeVec(buffer);
92 errno = IoErr2errno(IoErr());
93 return -1;
96 FreeVec(buffer);
97 return 0;
98 } /* fchmod */