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

Last change on this file since 616 was 610, checked in by alain, 6 years ago

Fix several bugs in VFS to support the following
ksh commandis : cp, mv, rm, mkdir, cd, pwd

File size: 7.4 KB
RevLine 
[439]1/*
[445]2 * stdio.h - User level <stdio> library definition.
[439]3 *
[445]4 * Author     Alain Greiner (2016,2017,2018)
[439]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
[445]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 ********************************************************************************************/
[439]32
[459]33#define  MAX_OPEN_FILE_PER_PROCESS  256
34#define  VALID_OPEN_FILE            0x12345678
35#define  EOF                        -1
36#define  NULL                       (void *)0
37
[473]38/*********************************************************************************************
39 * This defines the user level FILE structure.
40 ********************************************************************************************/
41
[459]42typedef struct file_s
43{
44    int fd;
45    int key;
46}
47FILE;
48
[444]49/*********************************************************************************************
[610]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/*********************************************************************************************
[444]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, ... );
[439]64
[444]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 );
[439]71
[444]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 ********************************************************************************************/
[476]77int getchar( void );
[439]78
[444]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 *********************************************************************************************
[445]84 * @ string    : pointer on target buffer.
[444]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, ... );
[439]92
[459]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
[439]144#endif  // _STDIO_H_
Note: See TracBrowser for help on using the repository browser.