| 1 |
/* Copyright (c) 2002, Joerg Wunsch |
/* Copyright (c) 2002,2005 Joerg Wunsch |
| 2 |
All rights reserved. |
All rights reserved. |
| 3 |
|
|
| 4 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 29 |
|
|
| 30 |
/* $Id$ */ |
/* $Id$ */ |
| 31 |
|
|
| 32 |
#include <inttypes.h> |
#include <stdint.h> |
| 33 |
#include <stdio.h> |
#include <stdio.h> |
| 34 |
#include <stdlib.h> |
#include <stdlib.h> |
| 35 |
|
|
| 36 |
#include "stdio_private.h" |
#include "stdio_private.h" |
| 37 |
|
|
|
FILE *__iob[3]; /* stdin, stdout, stderr */ |
|
|
|
|
| 38 |
/** \ingroup avr_stdio |
/** \ingroup avr_stdio |
| 39 |
This function is a replacement for \c fopen(). |
This function is a replacement for \c fopen(). |
| 40 |
|
|
| 47 |
insufficient dynamic memory is available to establish a new stream. |
insufficient dynamic memory is available to establish a new stream. |
| 48 |
|
|
| 49 |
If the \c put function pointer is provided, the stream is opened |
If the \c put function pointer is provided, the stream is opened |
| 50 |
with write intent. The function passed as \c put shall take one |
with write intent. The function passed as \c put shall take two |
| 51 |
character to write to the device as argument , and shall return 0 |
arguments, the first a character to write to the device, |
| 52 |
|
and the second a pointer to FILE, and shall return 0 |
| 53 |
if the output was successful, and a nonzero value if the character |
if the output was successful, and a nonzero value if the character |
| 54 |
could not be sent to the device. |
could not be sent to the device. |
| 55 |
|
|
| 56 |
If the \c get function pointer is provided, the stream is opened |
If the \c get function pointer is provided, the stream is opened |
| 57 |
with read intent. The function passed as \c get shall take no |
with read intent. The function passed as \c get shall take |
| 58 |
arguments, and return one character from the device, passed as an |
a pointer to FILE as its single argument, |
| 59 |
|
and return one character from the device, passed as an |
| 60 |
\c int type. If an error occurs when trying to read from the |
\c int type. If an error occurs when trying to read from the |
| 61 |
device, it shall return \c -1. |
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. |
| 64 |
|
|
| 65 |
If both functions are provided, the stream is opened with read |
If both functions are provided, the stream is opened with read |
| 66 |
and write intent. |
and write intent. |
| 69 |
and the first one opened with write intent is assigned to both, |
and the first one opened with write intent is assigned to both, |
| 70 |
\c stdout and \c stderr. |
\c stdout and \c stderr. |
| 71 |
|
|
|
The third parameter \c opts is currently unused, but reserved for |
|
|
future extensions. |
|
|
|
|
| 72 |
fdevopen() uses calloc() (und thus malloc()) in order to allocate |
fdevopen() uses calloc() (und thus malloc()) in order to allocate |
| 73 |
the storage for the new stream. |
the storage for the new stream. |
| 74 |
|
|
| 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 |
| 80 |
|
not use for new code. |
| 81 |
*/ |
*/ |
| 82 |
|
|
| 83 |
FILE * |
FILE * |
| 84 |
fdevopen(int (*put)(char), int (*get)(void), int opts __attribute__((unused))) |
fdevopen(int (*put)(char, FILE *), int (*get)(FILE *)) |
| 85 |
{ |
{ |
| 86 |
FILE *s; |
FILE *s; |
| 87 |
|
|