source: trunk/libs/mini-libc/stdio.h @ 469

Last change on this file since 469 was 459, checked in by alain, 6 years ago

Introduce the math library, to support the floating point
data used by the multi-thread fft application.
Fix several bugs regarding the FPU context save/restore.
Introduce support for the %f format in printf.

File size: 6.9 KB
Line 
1/*
2 * stdio.h - User level <stdio> library definition.
3 *
4 * Author     Alain Greiner (2016,2017,2018)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _STDIO_H_
25#define _STDIO_H_
26
27/*********************************************************************************************
28 * This file defines the user level, TXT related <stdio> library.
29 * These functions call the read() and write() functions defined in the <unistd> library
30 * to access the TXT terminal.
31 ********************************************************************************************/
32
33/*********************************************************************************************
34 * This defines the user level FILE structure.
35 ********************************************************************************************/
36
37#define  MAX_OPEN_FILE_PER_PROCESS  256
38#define  VALID_OPEN_FILE            0x12345678
39#define  EOF                        -1
40#define  NULL                       (void *)0
41
42typedef struct file_s
43{
44    int fd;
45    int key;
46}
47FILE;
48
49/*********************************************************************************************
50 * This function writes a formated string to the standard "stdout" stream.
51 *********************************************************************************************
52 * @ returns number of characters written if success / returns -1 if failure.
53 ********************************************************************************************/
54int printf( const char * format, ... );
55
56/*********************************************************************************************
57 * This function writes one single character to the standard "stdout" stream.
58 *********************************************************************************************
59 * @ returns written character code if success / returns 0 (EOF) if failure.
60 ********************************************************************************************/
61int putchar( int c );
62
63/*********************************************************************************************
64 * This function returns one single character from the standard "stdin" stream.
65 *********************************************************************************************
66 * @ returns read character code if success / returns 0 (EOF) if failure.
67 ********************************************************************************************/
68int getchar();
69
70/*********************************************************************************************
71 * This function copies a formated string to a fixed size buffer.
72 * it includes the NUL terminating character.
73 * it cheks that the formated string fit in the buffer length.
74 *********************************************************************************************
75 * @ string    : pointer on target buffer.
76 * @ length    : max bumber of characters in target buffer.
77 * @ format    : formated string.
78 * @ returns number of characters written if success / returns -1 if failure.
79 ********************************************************************************************/
80int snprintf( char         * string,
81              unsigned int   length,
82              const char   * format, ... );
83
84/*********************************************************************************************
85 * This function opens the file identified by the <pathname> argument and associates
86 * the stream pointed by <FILE> with it.
87 * The <mode> argument is a string that can have the following values:
88 * - "r"   Open text file for reading.
89 *         The stream is positioned at the beginning of the file.
90 * - "r+"  Open for reading and writing.
91 *         The stream is positioned at the beginning of the file.
92 * - "w"   Truncate the file to zero length or create text file for writing.
93 *         The stream is positioned at the beginning of the file.
94 * - "w+"  Open for reading and writing.
95 *         The file is created if it does not exist, otherwise it is truncated.
96 *         The stream is positioned at the beginning of the file.
97 * - "a"   Open for writing.  The file is created if it does not exist.
98 *         The stream is positioned at the end of the file. 
99 *         Subsequent writes to the file will always end up at the current end of file,
100 *         irrespective of any intervening fseek() or similar.
101 * - "a+"  Open for reading and writing. 
102 *         The file is created if it does not exist. 
103 *         The stream is positioned at the end of the file.
104 *         Subsequent writes to the file will always end up at the current end of file,
105 *         irrespective of any intervening fseek() or similar.
106 *********************************************************************************************
107 * @ pathname  : file pathname.
108 * @ mode      : must be NULL <=> only "w+" mode is supported.
109 * @ returns a stream pointer if success / returns NULL if file not found.
110 ********************************************************************************************/
111FILE * fopen( const char * pathname,
112              const char * mode );
113
114/*********************************************************************************************
115 * This function dissociates the stream from its underlying file and close this file.
116 * If the stream was being used for output, any buffered data is written first.
117 *********************************************************************************************
118 * @ stream    : pointer on a stream.
119 * @ returns 0 if success / returns EOF if failure.
120 ********************************************************************************************/
121int fclose( FILE * stream );
122
123/*********************************************************************************************
124 * This function copies a formated string to an output stream identified by the <stream>
125 * argument. It can be a  regular file or a character oriented output device.
126 *********************************************************************************************
127 * @ stream    : pointer on a stream.
128 * @ format    : formated string.
129 * @ returns number of characters written if success / returns -1 if failure.
130 ********************************************************************************************/
131int fprintf( FILE       * stream,
132             const char * format, ... );
133
134
135#endif  // _STDIO_H_
Note: See TracBrowser for help on using the repository browser.