PatchworkOS
Loading...
Searching...
No Matches
file.h File Reference
#include <stdint.h>
#include <stdio.h>
#include <sys/list.h>
#include <threads.h>

Go to the source code of this file.

Data Structures

struct  fpos_t
 
struct  FILE
 

Macros

#define _UNGETC_MAX   64
 
#define _FILE_GETC(stream)
 
#define _FILE_CHECK_AVAIL(fh)   (((fh->bufIndex == fh->bufEnd) && (fh->ungetIndex == 0)) ? _file_fill_buffer(fh) : 0)
 

Enumerations

enum  _file_flags_t {
  _FILE_READ = (1 << 0) ,
  _FILE_WRITE = (1 << 2) ,
  _FILE_RW = (1 << 3) ,
  _FILE_APPEND = (1 << 4) ,
  _FILE_BIN = (1 << 5) ,
  _FILE_OWNS_BUFFER = (1 << 6) ,
  _FILE_FULLY_BUFFERED = (1 << 7) ,
  _FILE_LINE_BUFFERED = (1 << 8) ,
  _FILE_UNBUFFERED = (1 << 9) ,
  _FILE_ERROR = (1 << 10) ,
  _FILE_WIDESTREAM = (1 << 11) ,
  _FILE_BYTESTREAM = (1 << 12) ,
  _FILE_DELETE_ON_CLOSE = (1 << 13) ,
  _FILE_EOF = (1 << 14)
}
 

Functions

_file_flags_t _file_flags_parse (const char *mode)
 
FILE_file_new (void)
 
void _file_free (FILE *stream)
 
uint64_t _file_init (FILE *stream, fd_t fd, _file_flags_t flags, void *buffer, uint64_t bufferSize)
 
void _file_deinit (FILE *stream)
 
uint64_t _file_flush_buffer (FILE *stream)
 
uint64_t _file_fill_buffer (FILE *stream)
 
uint64_t _file_seek (FILE *stream, int64_t offset, int whence)
 
uint64_t _file_prepare_read (FILE *stream)
 
uint64_t _file_prepare_write (FILE *stream)
 
void _files_init (void)
 
void _files_push (FILE *file)
 
void _files_remove (FILE *file)
 
void _files_close (void)
 
uint64_t _files_flush (void)
 

Macro Definition Documentation

◆ _FILE_CHECK_AVAIL

#define _FILE_CHECK_AVAIL (   fh)    (((fh->bufIndex == fh->bufEnd) && (fh->ungetIndex == 0)) ? _file_fill_buffer(fh) : 0)

Definition at line 53 of file file.h.

◆ _FILE_GETC

#define _FILE_GETC (   stream)
Value:
(((stream)->ungetIndex == 0) ? (unsigned char)(stream)->buf[(stream)->bufIndex++] \
: (unsigned char)(stream)->ungetBuf[--(stream)->ungetIndex])

Definition at line 49 of file file.h.

◆ _UNGETC_MAX

#define _UNGETC_MAX   64

Definition at line 32 of file file.h.

Enumeration Type Documentation

◆ _file_flags_t

Enumerator
_FILE_READ 
_FILE_WRITE 
_FILE_RW 
_FILE_APPEND 
_FILE_BIN 
_FILE_OWNS_BUFFER 
_FILE_FULLY_BUFFERED 
_FILE_LINE_BUFFERED 
_FILE_UNBUFFERED 
_FILE_ERROR 
_FILE_WIDESTREAM 
_FILE_BYTESTREAM 
_FILE_DELETE_ON_CLOSE 
_FILE_EOF 

Definition at line 8 of file file.h.

Function Documentation

◆ _file_deinit()

void _file_deinit ( FILE stream)

Definition at line 146 of file file.c.

References _FILE_OWNS_BUFFER, FILE::buf, close(), FILE::fd, FILE::flags, free(), FILE::mtx, and mtx_destroy().

Referenced by fclose().

◆ _file_fill_buffer()

uint64_t _file_fill_buffer ( FILE stream)

◆ _file_flags_parse()

_file_flags_t _file_flags_parse ( const char *  mode)

Definition at line 12 of file file.c.

References _FILE_APPEND, _FILE_BIN, _FILE_READ, _FILE_RW, _FILE_WRITE, files, and NULL.

Referenced by fopen().

◆ _file_flush_buffer()

uint64_t _file_flush_buffer ( FILE stream)

◆ _file_free()

void _file_free ( FILE stream)

Definition at line 92 of file file.c.

References free(), stderr, stdin, and stdout.

Referenced by fclose(), and fopen().

◆ _file_init()

uint64_t _file_init ( FILE stream,
fd_t  fd,
_file_flags_t  flags,
void *  buffer,
uint64_t  bufferSize 
)

◆ _file_new()

FILE * _file_new ( void  )

Definition at line 80 of file file.c.

References calloc(), FILE::entry, list_entry_init(), and NULL.

Referenced by fopen().

◆ _file_prepare_read()

uint64_t _file_prepare_read ( FILE stream)

◆ _file_prepare_write()

◆ _file_seek()

uint64_t _file_seek ( FILE stream,
int64_t  offset,
int  whence 
)

◆ _files_close()

void _files_close ( void  )

Definition at line 278 of file file.c.

References fclose(), files, filesMtx, LIST_FOR_EACH_SAFE, mtx_lock(), and mtx_unlock().

Referenced by exit().

◆ _files_flush()

uint64_t _files_flush ( void  )

Definition at line 292 of file file.c.

References EOF, ERR, fflush(), files, filesMtx, LIST_FOR_EACH, mtx_lock(), and mtx_unlock().

Referenced by fflush().

◆ _files_init()

void _files_init ( void  )

Definition at line 254 of file file.c.

References abort(), files, filesMtx, fprintf(), list_init(), mtx_init(), mtx_recursive, stderr, and thrd_success.

Referenced by _user_init().

◆ _files_push()

void _files_push ( FILE file)

Definition at line 264 of file file.c.

References file, files, filesMtx, list_push(), mtx_lock(), and mtx_unlock().

Referenced by _std_stream_init(), and fopen().

◆ _files_remove()

void _files_remove ( FILE file)

Definition at line 271 of file file.c.

References file, files, filesMtx, list_remove(), mtx_lock(), and mtx_unlock().

Referenced by fclose().