r6831@lvps87-230-33-50: verhaegs | 2008-02-03 14:08:57 +0100
[tangerine.git] / compiler / clib / ftell.c
blob6dff9eb5f833d2825b753f878a51c2e74ee9b1b1
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 Tell the position in a stream.
6 */
8 #include <errno.h>
9 #include <dos/dos.h>
10 #include <proto/dos.h>
11 #include "__errno.h"
12 #include "__stdio.h"
13 #include "__open.h"
15 /*****************************************************************************
17 NAME */
18 #include <stdio.h>
20 long ftell (
22 /* SYNOPSIS */
23 FILE * stream)
25 /* FUNCTION
26 Tell the current position in a stream.
28 INPUTS
29 stream - Obtain position of this stream
31 RESULT
32 The position on success and -1 on error.
33 If an error occurred, the global variable errno is set.
35 NOTES
37 EXAMPLE
39 BUGS
41 SEE ALSO
42 fopen(), fseek(), fwrite()
44 INTERNALS
46 ******************************************************************************/
48 long cnt;
49 BPTR fh;
50 fdesc *fdesc = __getfdesc(stream->fd);
52 if (!fdesc)
54 errno = EBADF;
55 return 0;
58 fh = (BPTR)(fdesc->fh);
60 Flush (fh);
61 cnt = Seek (fh, 0, OFFSET_CURRENT);
63 if (cnt == -1)
64 errno = IoErr2errno (IoErr ());
66 return cnt;
67 } /* ftell */