1
/* Copyright (c) 2002, Joerg Wunsch
1
/* Copyright (c) 2002,2005 Joerg Wunsch
4
4
Redistribution and use in source and binary forms, with or without
27
27
POSSIBILITY OF SUCH DAMAGE.
30
/* $Id: fdevopen.c,v 1.4 2004/12/22 22:08:23 joerg_wunsch Exp $ */
30
/* $Id: fdevopen.c,v 1.6 2005/09/14 19:04:58 joerg_wunsch Exp $ */
34
34
#include <stdlib.h>
36
36
#include "stdio_private.h"
38
FILE *__iob[3]; /* stdin, stdout, stderr */
40
38
/** \ingroup avr_stdio
41
39
This function is a replacement for \c fopen().
49
47
insufficient dynamic memory is available to establish a new stream.
51
49
If the \c put function pointer is provided, the stream is opened
52
with write intent. The function passed as \c put shall take one
53
character to write to the device as argument , and shall return 0
50
with write intent. The function passed as \c put shall take two
51
arguments, the first a character to write to the device,
52
and the second a pointer to FILE, and shall return 0
54
53
if the output was successful, and a nonzero value if the character
55
54
could not be sent to the device.
57
56
If the \c get function pointer is provided, the stream is opened
58
with read intent. The function passed as \c get shall take no
59
arguments, and return one character from the device, passed as an
57
with read intent. The function passed as \c get shall take
58
a pointer to FILE as its single argument,
59
and return one character from the device, passed as an
60
60
\c int type. If an error occurs when trying to read from the
61
device, it shall return \c -1.
61
device, it shall return \c _FDEV_ERR.
62
If an end-of-file condition was reached while reading from the
63
device, \c _FDEV_EOF shall be returned.
63
65
If both functions are provided, the stream is opened with read
67
69
and the first one opened with write intent is assigned to both,
68
70
\c stdout and \c stderr.
70
The third parameter \c opts is currently unused, but reserved for
73
72
fdevopen() uses calloc() (und thus malloc()) in order to allocate
74
73
the storage for the new stream.
75
\note If the macro __STDIO_FDEVOPEN_COMPAT_12 is declared before
76
including <stdio.h>, a function prototype for fdevopen() will be
77
chosen that is backwards compatible with avr-libc version 1.2 and
78
before. This is solely intented for providing a simple migration
79
path without the need to immediately change all source code. Do
78
fdevopen(int (*put)(char), int (*get)(void), int opts __attribute__((unused)))
84
fdevopen(int (*put)(char, FILE *), int (*get)(FILE *))