![]() |
m2mb API docs
25.30.003
m2mb API sets documentation
|
File system stdio library implementation. More...
Go to the source code of this file.
Macros | |
| #define | NULL 0 |
| #define | M2MB_SEEK_SET 0 /* Seek from beginning of file. */ |
| #define | M2MB_SEEK_CUR 1 /* Seek from current position. */ |
| #define | M2MB_SEEK_END 2 /* Seek from end of file. */ |
Typedefs | |
| typedef struct M2MB_FILE_TAG | M2MB_FILE_T |
Functions | |
| M2MB_FILE_T * | m2mb_fs_fopen (const CHAR *path, const CHAR *mode) |
| Open file as stream. More... | |
| SIZE_T | m2mb_fs_fread (void *ptr, SIZE_T size, SIZE_T nitems, M2MB_FILE_T *stream) |
| Read file as stream. More... | |
| SIZE_T | m2mb_fs_fwrite (void *ptr, SIZE_T size, SIZE_T nitems, M2MB_FILE_T *stream) |
| Write file as stream. More... | |
| INT32 | m2mb_fs_fclose (M2MB_FILE_T *stream) |
| Close file as stream. More... | |
| INT32 | m2mb_fs_fseek (M2MB_FILE_T *stream, INT32 offset, INT32 whence) |
| Move file position indicator. More... | |
| INT32 | m2mb_fs_ftell (M2MB_FILE_T *stream) |
| Get file position indicator. More... | |
| INT32 | m2mb_fs_fflush (M2MB_FILE_T *stream) |
| Flush file as stream. More... | |
| INT32 | m2mb_fs_fileno (M2MB_FILE_T *stream) |
| Get file integer descriptor. More... | |
| INT32 | m2mb_fs_fgetc (M2MB_FILE_T *stream) |
| Read char from file as stream. More... | |
| CHAR * | m2mb_fs_fgets (CHAR *s, INT32 size, M2MB_FILE_T *stream) |
| Read line string from file as stream. More... | |
| INT32 | m2mb_fs_fputc (INT32 c, M2MB_FILE_T *stream) |
| Write char to file as stream. More... | |
| INT32 | m2mb_fs_fputs (const CHAR *s, M2MB_FILE_T *stream) |
| Write string to file as stream. More... | |
| INT32 | m2mb_fs_remove (const CHAR *path) |
| Delete file. More... | |
| INT32 | m2mb_fs_rename (const CHAR *oldpath, const CHAR *newpath) |
| Rename file or directory. More... | |
File system stdio library implementation.
m2m/m2m_common/m2mb_inc/m2mb_fs_stdio.h
stdio library for files. The following functions are implemented: m2mb_fs_fopen m2mb_fs_fread m2mb_fs_fwrite m2mb_fs_fclose m2mb_fs_fseek m2mb_fs_ftell m2mb_fs_fflush m2mb_fs_fileno m2mb_fs_fgetc m2mb_fs_fgets m2mb_fs_fputc m2mb_fs_fputs m2mb_fs_remove m2mb_fs_rename
@notes Dependencies: m2m/m2m_common/m2mb_inc/m2mb_types.h
| INT32 m2mb_fs_fclose | ( | M2MB_FILE_T * | stream | ) |
Close file as stream.
The function flushes the stream pointed to by stream (writing any buffered output data) and closes the underlying file descriptor.
| [in] | stream | Pointer to stream file object. |
Example
| INT32 m2mb_fs_fflush | ( | M2MB_FILE_T * | stream | ) |
Flush file as stream.
The function forces a write of all user-space buffered data for the given output.
| [in] | stream | Pointer to stream file object. |
Example
| INT32 m2mb_fs_fgetc | ( | M2MB_FILE_T * | stream | ) |
Read char from file as stream.
The function reads the next character from the stream pointed to by stream.
| [in] | stream | Pointer to stream file object. |
Example
| CHAR* m2mb_fs_fgets | ( | CHAR * | s, |
| INT32 | size, | ||
| M2MB_FILE_T * | stream | ||
| ) |
Read line string from file as stream.
The function reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an end of file or a newline. If a newline is read, it is stored into the buffer. A terminating null byte ('\0') is stored after the last character in the buffer.
| [out] | s | Buffer to fill with read data. |
| [in] | size | Size of buffer s. One more than the max number of characters to be read. |
| [in] | stream | Pointer to stream file object. |
Example
| INT32 m2mb_fs_fileno | ( | M2MB_FILE_T * | stream | ) |
Get file integer descriptor.
The function examines the argument stream and returns its integer descriptor.
| [in] | stream | Pointer to stream file object. |
Example
| M2MB_FILE_T* m2mb_fs_fopen | ( | const CHAR * | path, |
| const CHAR * | mode | ||
| ) |
Open file as stream.
The function opens the file whose name is the string pointed to by path and associates a stream with it.
| [in] | path | Name of file to be open. |
| [in] | mode | Mode for opening file. r Open text file for reading. The stream is positioned at the beginning of the file. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file. The mode string can also include the letter 'b' either as a last character or as a character between the characters in any of the two-character strings described above. The 'b' is ignored. |
Example
| INT32 m2mb_fs_fputc | ( | INT32 | c, |
| M2MB_FILE_T * | stream | ||
| ) |
Write char to file as stream.
The function writes the character c, cast to an unsigned char, to the stream pointed to by stream.
| [in] | c | Character to be written. |
| [in] | stream | Pointer to stream file object. |
Example
| INT32 m2mb_fs_fputs | ( | const CHAR * | s, |
| M2MB_FILE_T * | stream | ||
| ) |
Write string to file as stream.
The function writes the string s to stream, without its terminating null byte ('\0').
| [in] | s | Null byte terminated string to be written. |
| [in] | stream | Pointer to stream file object. |
Example
| SIZE_T m2mb_fs_fread | ( | void * | ptr, |
| SIZE_T | size, | ||
| SIZE_T | nitems, | ||
| M2MB_FILE_T * | stream | ||
| ) |
Read file as stream.
The function reads nitems elements of data, each size bytes long, from the stream pointed to by stream, storing them at the location given by ptr.
| [out] | ptr | Buffer to fill with read data. |
| [in] | size | Size in bytes of each item. |
| [in] | nitems | Number of items to read. |
| [in] | stream | Pointer to stream file object. |
Example
| INT32 m2mb_fs_fseek | ( | M2MB_FILE_T * | stream, |
| INT32 | offset, | ||
| INT32 | whence | ||
| ) |
Move file position indicator.
The function sets the file position indicator for the stream pointed to by stream. The new position, measured in bytes, is obtained by adding offset bytes to the position specified by whence.
| [in] | stream | Pointer to stream file object. |
| [in] | offset | Number of bytes to move the file position indicator from the position specified by whence. |
| [in] | whence | File position. M2MB_SEEK_SET Beginning of the file. M2MB_SEEK_CUR Current file position. M2MB_SEEK_END End of file. |
Example
| INT32 m2mb_fs_ftell | ( | M2MB_FILE_T * | stream | ) |
Get file position indicator.
The function obtains the current value of the file position indicator for the stream pointed to by stream.
| [in] | stream | Pointer to stream file object. |
Example
| SIZE_T m2mb_fs_fwrite | ( | void * | ptr, |
| SIZE_T | size, | ||
| SIZE_T | nitems, | ||
| M2MB_FILE_T * | stream | ||
| ) |
Write file as stream.
The function writes nitems elements of data, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr.
| [in] | ptr | Buffer containing data to be written. |
| [in] | size | Size in bytes of each item. |
| [in] | nitems | Number of items to write. |
| [in] | stream | Pointer to stream file object. |
Example
| INT32 m2mb_fs_remove | ( | const CHAR * | path | ) |
Delete file.
The function deletes the file whose name is the string pointed to by path.
| [in] | path | Name of file to be deleted. |
Example
| INT32 m2mb_fs_rename | ( | const CHAR * | oldpath, |
| const CHAR * | newpath | ||
| ) |
Rename file or directory.
The function changes the name of a file or a directory. The old argument points to the pathname of the file to be renamed. The new argument points to the new pathname of the file.
| [in] | oldpath | Name of file to be renamed. |
| [in] | newpath | Name of new file. |
Example