arch/m68k-amiga: Define the gcc symbol 'start' instead of using .bss
[AROS.git] / compiler / clib / fchmod.c
blob9e3646819e27bf6e516a15015fc40ee3a0f82e3a
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 "__fdesc.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
36 Change permission bits of a file specified by an open file descriptor.
38 INPUTS
39 filedes - File descriptor of the file
40 mode - Permission bits to set
42 RESULT
43 0 on success and -1 on error. If an error occurred, the global
44 variable errno is set.
46 NOTES
47 See chmod() documentation for more details about the mode parameter.
49 EXAMPLE
51 BUGS
53 SEE ALSO
54 chmod()
56 INTERNALS
58 ******************************************************************************/
60 fdesc *fdesc;
61 UBYTE *buffer;
62 int buffersize = 256;
64 if (!(fdesc = __getfdesc(filedes)))
66 errno = EBADF;
67 return -1;
70 /* Get the full path of the stated filesystem object and use it to
71 compute hash value */
74 if(!(buffer = AllocVec(buffersize, MEMF_ANY)))
76 errno = IoErr2errno(IoErr());
77 return -1;
80 if(NameFromFH(fdesc->fcb->fh, buffer, buffersize))
81 break;
82 else if(IoErr() != ERROR_LINE_TOO_LONG)
84 errno = IoErr2errno(IoErr());
85 FreeVec(buffer);
86 return -1;
88 FreeVec(buffer);
89 buffersize *= 2;
91 while(TRUE);
93 if (!SetProtection(buffer, prot_u2a(mode)))
95 FreeVec(buffer);
96 errno = IoErr2errno(IoErr());
97 return -1;
100 FreeVec(buffer);
101 return 0;
102 } /* fchmod */