Subversion Repositories Kolibri OS

Rev

Rev 4921 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/*
2
 * Copyright (c) 1990 The Regents of the University of California.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms are permitted
6
 * provided that the above copyright notice and this paragraph are
7
 * duplicated in all such forms and that any documentation,
8
 * advertising materials, and other materials related to such
9
 * distribution and use acknowledge that the software was developed
10
 * by the University of California, Berkeley.  The name of the
11
 * University may not be used to endorse or promote products derived
12
 * from this software without specific prior written permission.
13
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
 
18
/*
19
FUNCTION
6099 serge 20
<>, <>---return file descriptor associated with stream
4349 Serge 21
 
22
INDEX
23
	fileno
6099 serge 24
INDEX
25
	fileno_unlocked
4349 Serge 26
 
27
ANSI_SYNOPSIS
28
	#include 
29
	int fileno(FILE *<[fp]>);
30
 
6099 serge 31
	#define _BSD_SOURCE
32
	#include 
33
	int fileno_unlocked(FILE *<[fp]>);
34
 
4349 Serge 35
TRAD_SYNOPSIS
36
	#include 
37
	int fileno(<[fp]>)
38
	FILE *<[fp]>;
39
 
6099 serge 40
	#define _BSD_SOURCE
41
	#include 
42
	int fileno_unlocked(<[fp]>)
43
	FILE *<[fp]>;
44
 
4349 Serge 45
DESCRIPTION
46
You can use <> to return the file descriptor identified by <[fp]>.
47
 
6099 serge 48
<> is a non-thread-safe version of <>.
49
<> may only safely be used within a scope
50
protected by flockfile() (or ftrylockfile()) and funlockfile().  This
51
function may safely be used in a multi-threaded program if and only
52
if they are called while the invoking thread owns the (FILE *)
53
object, as is the case after a successful call to the flockfile() or
54
ftrylockfile() functions.  If threads are disabled, then
55
<> is equivalent to <>.
56
 
4349 Serge 57
RETURNS
58
<> returns a non-negative integer when successful.
59
If <[fp]> is not an open stream, <> returns -1.
60
 
61
PORTABILITY
62
<> is not part of ANSI C.
63
POSIX requires <>.
64
 
6099 serge 65
<> is a BSD extension also provided by GNU libc.
66
 
4349 Serge 67
Supporting OS subroutines required: none.
68
*/
69
 
70
#include <_ansi.h>
71
#include 
4921 Serge 72
#include 
4349 Serge 73
#include "local.h"
74
 
75
int
76
_DEFUN(fileno, (f),
77
       FILE * f)
78
{
79
  int result;
80
  CHECK_INIT (_REENT, f);
4921 Serge 81
  _newlib_flockfile_start (f);
82
  if (f->_flags)
6099 serge 83
    result = __sfileno (f);
4921 Serge 84
  else
85
    {
86
      result = -1;
87
      _REENT->_errno = EBADF;
88
    }
89
  _newlib_flockfile_end (f);
4349 Serge 90
  return result;
91
}