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

Last change on this file since 624 was 623, checked in by alain, 6 years ago

Introduce three new types of vsegs (KCODE,KDATA,KDEV)
to map the kernel vsegs in the process VSL and GPT.
This now used by both the TSAR and the I86 architectures.

File size: 7.6 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#define  MAX_OPEN_FILE_PER_PROCESS  256
34#define  VALID_OPEN_FILE            0x12345678
35#define  EOF                        -1
36#define  NULL                       (void *)0
37
38/*********************************************************************************************
39 * This defines the user level FILE structure.
40 ********************************************************************************************/
41
42typedef struct stream_s
43{
44    int fd;          // index in both kernel fd_array[], and user open_file_array[]
45    int key;         // entry valid in open_file_array[] when (key == VALID_OPEN_FILE)
46}
47FILE;
48
49/*********************************************************************************************
50 * This function causes the file/directory named <old> to be renamed as <new>.
51 * If <new> exists, it is previously removed.
52 *********************************************************************************************
53 * @ returns 0 if success / returns -1 if failure.
54 ********************************************************************************************/
55int rename( const char * old,
56            const char * new );
57
58/*********************************************************************************************
59 * This function writes a formated string to the standard "stdout" stream.
60 *********************************************************************************************
61 * @ returns number of characters written if success / returns -1 if failure.
62 ********************************************************************************************/
63int printf( const char * format, ... );
64
65/*********************************************************************************************
66 * This function writes one single character to the standard "stdout" stream.
67 *********************************************************************************************
68 * @ returns written character code if success / returns 0 (EOF) if failure.
69 ********************************************************************************************/
70int putchar( int c );
71
72/*********************************************************************************************
73 * This function returns one single character from the standard "stdin" stream.
74 *********************************************************************************************
75 * @ returns read character code if success / returns 0 (EOF) if failure.
76 ********************************************************************************************/
77int getchar( void );
78
79/*********************************************************************************************
80 * This function copies a formated string to a fixed size buffer.
81 * it includes the NUL terminating character.
82 * it cheks that the formated string fit in the buffer length.
83 *********************************************************************************************
84 * @ string    : pointer on target buffer.
85 * @ length    : max bumber of characters in target buffer.
86 * @ format    : formated string.
87 * @ returns number of characters written if success / returns -1 if failure.
88 ********************************************************************************************/
89int snprintf( char         * string,
90              unsigned int   length,
91              const char   * format, ... );
92
93/*********************************************************************************************
94 * This function opens the file identified by the <pathname> argument and associates
95 * the stream pointed by <FILE> with it.
96 * The <mode> argument is a string that can have the following values:
97 * - "r"   Open text file for reading.
98 *         The stream is positioned at the beginning of the file.
99 * - "r+"  Open for reading and writing.
100 *         The stream is positioned at the beginning of the file.
101 * - "w"   Truncate the file to zero length or create text file for writing.
102 *         The stream is positioned at the beginning of the file.
103 * - "w+"  Open for reading and writing.
104 *         The file is created if it does not exist, otherwise it is truncated.
105 *         The stream is positioned at the beginning of the file.
106 * - "a"   Open for writing.  The file is created if it does not exist.
107 *         The stream is positioned at the end of the file. 
108 *         Subsequent writes to the file will always end up at the current end of file,
109 *         irrespective of any intervening fseek() or similar.
110 * - "a+"  Open for reading and writing. 
111 *         The file is created if it does not exist. 
112 *         The stream is positioned at the end of the file.
113 *         Subsequent writes to the file will always end up at the current end of file,
114 *         irrespective of any intervening fseek() or similar.
115 *********************************************************************************************
116 * @ pathname  : file pathname.
117 * @ mode      : must be NULL <=> only "w+" mode is supported.
118 * @ returns a stream pointer if success / returns NULL if file not found.
119 ********************************************************************************************/
120FILE * fopen( const char * pathname,
121              const char * mode );
122
123/*********************************************************************************************
124 * This function dissociates the stream from its underlying file and close this file.
125 * If the stream was being used for output, any buffered data is written first.
126 *********************************************************************************************
127 * @ stream    : pointer on a stream.
128 * @ returns 0 if success / returns EOF if failure.
129 ********************************************************************************************/
130int fclose( FILE * stream );
131
132/*********************************************************************************************
133 * This function copies a formated string to an output stream identified by the <stream>
134 * argument. It can be a  regular file or a character oriented output device.
135 *********************************************************************************************
136 * @ stream    : pointer on a stream.
137 * @ format    : formated string.
138 * @ returns number of characters written if success / returns -1 if failure.
139 ********************************************************************************************/
140int fprintf( FILE       * stream,
141             const char * format, ... );
142
143
144#endif  // _STDIO_H_
Note: See TracBrowser for help on using the repository browser.