ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
Functions | Variables
posix.c File Reference

POSIX wrapper for FatFS. More...

#include "user_config.h"
#include "stringsup.h"
#include "fatfs.h"
#include "posix.h"

Go to the source code of this file.

Functions

MEMSPACE int isatty (int fileno)
 Test POSIX fileno if it is a Serial Console/TTY. More...
 
MEMSPACE int fgetc (FILE *stream)
 Get byte from a TTY device or FatFs file stream open() or fopen() sets stream->get = fatfs_getc() for FatFs functions See fdevopen() sets stream->get for TTY devices. More...
 
MEMSPACE int fputc (int c, FILE *stream)
 Put a byte to TTY device or FatFs file stream open() or fopen() sets stream->put = fatfs_outc() for FatFs functions See fdevopen() sets stream->put get for TTY devices. More...
 
MEMSPACE int getchar ()
 functions normally defined as macros More...
 
MEMSPACE int putchar (int c)
 put a character to stdout See fdevopen() sets stream->put get for TTY devices More...
 
MEMSPACE int ungetc (int c, FILE *stream)
 Un-Get byte from a TTY device or FatFs file stream. More...
 
MEMSPACE int putc (int c, FILE *stream)
 Put a character to a stream See fdevopen() sets stream->put get for TTY devices. More...
 
MEMSPACE char * fgets (char *str, int size, FILE *stream)
 get a string from stdin See fdevopen() sets stream->put get for TTY devices More...
 
MEMSPACE int fputs (const char *str, FILE *stream)
 put a string to stdout See fdevopen() sets stream->put get for TTY devices More...
 
MEMSPACE int puts (const char *str)
 put a string to stdout See fdevopen() sets stream->put get for TTY devices More...
 
MEMSPACE int feof (FILE *stream)
 feof reports if the stream is at EOF More...
 
MEMSPACE int fgetpos (FILE *stream, size_t *pos)
 POSIX get position of file stream. More...
 
MEMSPACE int fseek (FILE *stream, long offset, int whence)
 POSIX seek to file possition. More...
 
MEMSPACE int fsetpos (FILE *stream, size_t *pos)
 POSIX set position of file stream. More...
 
MEMSPACE long ftell (FILE *stream)
 POSIX file position of open stream. More...
 
MEMSPACE off_t lseek (int fileno, off_t position, int whence)
 POSIX seek to file position. More...
 
MEMSPACE void rewind (FILE *stream)
 POSIX rewind file to the beginning. More...
 
MEMSPACE int close (int fileno)
 POSIX Close a file with fileno handel. More...
 
MEMSPACE int fileno (FILE *stream)
 Convert POSIX stream pointer to POSIX fileno (index of __iob[]) More...
 
MEMSPACE FILEfileno_to_stream (int fileno)
 Convert POSIX fileno to POSIX FILE stream pointer. NOT POSIX. More...
 
MEMSPACE FILEfopen (const char *path, const char *mode)
 POSIX Open a file with path name and ascii file mode string. More...
 
MEMSPACE size_t fread (void *ptr, size_t size, size_t nmemb, FILE *stream)
 POSIX read nmemb elements from buf, size bytes each, to the stream fd. More...
 
MEMSPACE int ftruncate (int fd, off_t length)
 POSIX truncate open file to length. More...
 
MEMSPACE size_t fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream)
 POSIX write nmemb elements from buf, size bytes each, to the stream fd. More...
 
MEMSPACE int open (const char *pathname, int flags)
 POSIX Open a file with integer mode flags. More...
 
MEMSPACE ssize_t read (int fd, const void *buf, size_t count)
 POSIX read count bytes from *buf to fileno fd. More...
 
MEMSPACE void sync (void)
 POSIX Sync all pending file changes and metadata on ALL files. More...
 
MEMSPACE int syncfs (int fd)
 POSIX Sync pending file changes and metadata for specified fileno. More...
 
MEMSPACE int truncate (const char *path, off_t length)
 POSIX truncate named file to length. More...
 
MEMSPACE ssize_t write (int fd, const void *buf, size_t count)
 POSIX Write count bytes from *buf to fileno fd. More...
 
MEMSPACE int fclose (FILE *stream)
 POSIX close a file stream. More...
 
MEMSPACE void dump_stat (struct stat *sp)
 Display struct stat, from POSIX stat(0 or fstat(), in ASCII. NOT POSIX. More...
 
MEMSPACE char * mctime (time_t timev)
 Display Ascii formatted time from timev seconds NOT POSIX. More...
 
MEMSPACE int stat (char *name, struct stat *buf)
 POSIX stat - get file status of named file. More...
 
MEMSPACE int utime (const char *filename, const struct utimbuf *times)
 Set Modification and Access time of a file. More...
 
MEMSPACE char * basename (char *str)
 POSIX Basename of filename. More...
 
MEMSPACE char * baseext (char *str)
 File extention of a file name. NOT POSIX. More...
 
MEMSPACE int chdir (const char *pathname)
 POSIX change directory. More...
 
MEMSPACE int chmod (const char *pathname, mode_t mode)
 POSIX chmod function - change file access permission Unfortunately file f_open modes and f_chmod modes are not the same Files that are open have way more options - but only while the file is open. More...
 
MEMSPACE int dirname (char *str)
 POSIX directory name of a filename. Return the index of the last '/' character. More...
 
MEMSPACE char * getcwd (char *pathname, int len)
 POSIX get current working directory. More...
 
MEMSPACE int mkdir (const char *pathname, mode_t mode)
 POSIX make a directory. More...
 
MEMSPACE int rename (const char *oldpath, const char *newpath)
 POSIX rename a file by name. More...
 
MEMSPACE int rmdir (const char *pathname)
 POSIX delete a directory. More...
 
MEMSPACE int unlink (const char *pathname)
 POSIX delete a file. More...
 
int closedir (DIR *dirp)
 POSIX closedir. More...
 
DIRopendir (const char *pathdir)
 
dirent_treaddir (DIR *dirp)
 
MEMSPACE void clrerror (FILE *stream)
 clrerror resets stream EOF and error flags More...
 
MEMSPACE int ferror (FILE *stream)
 ferror reports if the stream has an error flag set More...
 
MEMSPACE void perror (const char *s)
 POSIX perror() - convert POSIX errno to text with user message. More...
 
MEMSPACE char WEAK_ATRstrerror (int errnum)
 POSIX strerror() - convert POSIX errno to text with user message. More...
 
MEMSPACE char * strerror_r (int errnum, char *buf, size_t buflen)
 POSIX strerror_r() - convert POSIX errno to text with user message. More...
 
MEMSPACE FILEfdevopen (int(*put)(char, FILE *), int(*get)(FILE *))
 Device open functions. More...
 
int mkfs (char *name)
 Formt SD card. More...
 
MEMSPACE int fatfs_getc (FILE *stream)
 Private FatFs function called by fgetc() to get a byte from file stream FIXME buffer this function call NOT POSIX open() assigns stream->get = fatfs_getc() More...
 
MEMSPACE int fatfs_putc (char c, FILE *stream)
 Private FatFs function called by fputc() to put a byte from file stream NOT POSIX open() assigns stream->put = fatfs_putc() More...
 
MEMSPACE int fatfs_to_errno (FRESULT Result)
 Convert FafFs error result to POSIX errno. NOT POSIX. More...
 
MEMSPACE int fatfs_to_fileno (FIL *fh)
 Convert FatFS file handle to POSIX fileno. NOT POSIX. More...
 
MEMSPACE time_t fat_time_to_unix (uint16_t date, uint16_t time)
 Convert FatFs file date and time to POSIX epoch seconds. NOT POSIX. More...
 
MEMSPACE void unix_time_to_fat (time_t epoch, uint16_t *date, uint16_t *time)
 Convert Linux POSIX time_t to FAT32 date and time. NOT POSIX. More...
 
MEMSPACE FILfileno_to_fatfs (int fileno)
 Convert POSIX fileno to FatFS handle NOT POSIX. More...
 
MEMSPACE int free_file_descriptor (int fileno)
 Free POSIX fileno FILE descriptor. NOT POSIX. More...
 
MEMSPACE int new_file_descriptor (void)
 Allocate a POSIX FILE descriptor. NOT POSIX. More...
 
MEMSPACE int posix_fopen_modes_to_open (const char *mode)
 Convert POSIX fopen mode to POSIX open mode flags. NOT POSIX. More...
 
static MEMSPACE void _fprintf_putc (struct _printf_t *p, char ch)
 fprintf character write function More...
 
MEMSPACE int fprintf (FILE *fp, const char *format,...)
 fprintf function Example user defined printf function using fputc for I/O This method allows I/O to devices and strings without typical C++ overhead More...
 

Variables

int errno
 Note: fdevopen assigns stdin,stdout,stderr. More...
 
FILE__iob [MAX_FILES]
 POSIX fileno to POSIX FILE stream table. More...
 
const char * sys_errlist []
 POSIX error messages for each errno value. More...
 
static DIR _dp
 POSIX opendir. More...
 
static dirent_t _de
 POSIX opendir. More...
 

Detailed Description

POSIX wrapper for FatFS.

Copyright © 2014-2017 Mike Gore, All rights reserved. GPL License
See also
http://github.com/magore/hp85disk
http://github.com/magore/hp85disk/COPYRIGHT.md for specific Copyright details
You are free to use this code under the terms of GPL
please retain a copy of this notice in any code you use it in.

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file posix.c.

Function Documentation

static MEMSPACE void _fprintf_putc ( struct _printf_t p,
char  ch 
)
static

fprintf character write function

  • POSIX fprintf function
    Parameters
    [in]*pprintf user buffer
    [in]chcharacter TODO if fputc fails we might want to also set an error in the *p structure - error in the stream will already be set

Definition at line 2468 of file posix.c.

Referenced by fprintf().

MEMSPACE char* baseext ( char *  str)

File extention of a file name. NOT POSIX.

Parameters
[in]strstring to find extension in.
Returns
pointer to basename extension.

Definition at line 1466 of file posix.c.

MEMSPACE char* basename ( char *  str)

POSIX Basename of filename.

  • POSIX file and directory manipulation- man page (3).
Parameters
[in]strstring to find basename in.
Returns
pointer to basename of string.

Definition at line 1446 of file posix.c.

Referenced by FontHeaderInfo(), ls_info(), and main().

MEMSPACE int chdir ( const char *  pathname)

POSIX change directory.

  • man page chdir (2).
Parameters
[in]pathnamedirectory to change to
Returns
0 on sucess.
-1 on error with errno set.

Definition at line 1488 of file posix.c.

Referenced by posix_tests().

MEMSPACE int chmod ( const char *  pathname,
mode_t  mode 
)

POSIX chmod function - change file access permission Unfortunately file f_open modes and f_chmod modes are not the same Files that are open have way more options - but only while the file is open.

  • so this is a bit of a hack - we can only set read only - if on one has write perms

man page chmod (2).

Parameters
[in]pathnamefilename string.
[in]modePOSIX chmod modes.
Returns
fileno on success.

Definition at line 1513 of file posix.c.

Referenced by mkdir(), and posix_tests().

MEMSPACE int close ( int  fileno)

POSIX Close a file with fileno handel.

  • POSIX file functions- man page close (2).
Parameters
[in]filenofileno of file.
Returns
0 on sucess.
-1 on error with errno set.

Definition at line 685 of file posix.c.

Referenced by fclose(), and send_message().

int closedir ( DIR dirp)

POSIX closedir.

  • POSIX - directory scanning functions- man page closedir (2).
Parameters
[in]dirpDIR * directory handle
Returns
0 on sucess.
-1 on error with errno set.

Definition at line 1717 of file posix.c.

Referenced by ls().

MEMSPACE void clrerror ( FILE stream)

clrerror resets stream EOF and error flags

  • POSIX error functions- man page clrerror(3).
Parameters
[in]streamPOSIX stream pointer.
Returns
EOF on error with errno set.

Definition at line 1786 of file posix.c.

MEMSPACE int dirname ( char *  str)

POSIX directory name of a filename. Return the index of the last '/' character.

  • Example:
    1 dir[0] = 0;
    2 ret = dirname(path)
    3 if(ret)
    4  strncpy(dir,path,ret);
Parameters
[in]strstring to examine.
Returns
0 if no directory part.
index of last '/' character.

Definition at line 1551 of file posix.c.

MEMSPACE void dump_stat ( struct stat sp)

Display struct stat, from POSIX stat(0 or fstat(), in ASCII. NOT POSIX.

  • POSIX file information functions
    Parameters
    [in]spstruct stat pointer.
    Returns
    void.

Definition at line 1260 of file posix.c.

Referenced by posix_tests().

MEMSPACE time_t fat_time_to_unix ( uint16_t  date,
uint16_t  time 
)

Convert FatFs file date and time to POSIX epoch seconds. NOT POSIX.

  • man page timegm (3).
Parameters
[in]dateFatFs date.
[in]timeFatFs time.
See also
timegm()
Returns
epoch seconds

Definition at line 2227 of file posix.c.

Referenced by stat().

MEMSPACE int fatfs_getc ( FILE stream)

Private FatFs function called by fgetc() to get a byte from file stream FIXME buffer this function call NOT POSIX open() assigns stream->get = fatfs_getc()

  • man page fgetc (3).
  • Notes: fgetc does all tests prior to caling us, including ungetc.
Parameters
[in]streamPOSIX stream pointer.
Returns
character.
EOF on error with errno set.

Definition at line 1984 of file posix.c.

Referenced by open().

MEMSPACE int fatfs_putc ( char  c,
FILE stream 
)

Private FatFs function called by fputc() to put a byte from file stream NOT POSIX open() assigns stream->put = fatfs_putc()

  • man page fputc (3).
  • Notes: fputc does all tests prior to caling us.
Parameters
[in]ccharacter.
[in]streamPOSIX stream pointer.
Returns
character
EOF on error with errno set.

Definition at line 2074 of file posix.c.

Referenced by fputc(), and open().

MEMSPACE int fatfs_to_errno ( FRESULT  Result)

Convert FafFs error result to POSIX errno. NOT POSIX.

  • man page errno (3).
Parameters
[in]ResultFatFs Result code.
Returns
POSIX errno.
EBADMSG if no conversion possible.

Definition at line 2114 of file posix.c.

Referenced by chdir(), chmod(), close(), closedir(), fatfs_getc(), fatfs_putc(), ftruncate(), getcwd(), lseek(), mkdir(), open(), opendir(), read(), readdir(), rename(), rmdir(), stat(), syncfs(), truncate(), unlink(), utime(), and write().

MEMSPACE int fatfs_to_fileno ( FIL fh)

Convert FatFS file handle to POSIX fileno. NOT POSIX.

Parameters
[in]fhFatFS file pointer.
Returns
fileno on success.
-1 on error with errno set to EBADF.

Definition at line 2190 of file posix.c.

MEMSPACE int fclose ( FILE stream)

POSIX close a file stream.

  • man page flose (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
0 on sucess.
-1 on error witrh errno set.

Definition at line 1239 of file posix.c.

Referenced by buffer_read_close(), cat(), copy(), hexdump(), logfile(), main(), MatRead(), MatWrite(), ReadBdf(), sum(), timetests(), and upload().

MEMSPACE FILE* fdevopen ( int(*)(char, FILE *)  put,
int(*)(FILE *)  get 
)

Device open functions.

Assign stdin,stdout,stderr or any use defined I/O NOT POSIX

Parameters
[in]*putputc function pointer
[in]*getgutc function pointer

Definition at line 1876 of file posix.c.

MEMSPACE int feof ( FILE stream)

feof reports if the stream is at EOF

  • POSIX file position functions- man page feof (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
1 if EOF set, 0 otherwise.

Definition at line 505 of file posix.c.

MEMSPACE int ferror ( FILE stream)

ferror reports if the stream has an error flag set

  • man page ferror (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
1 if EOF set, 0 otherwise.

Definition at line 1798 of file posix.c.

MEMSPACE int fgetc ( FILE stream)

Get byte from a TTY device or FatFs file stream open() or fopen() sets stream->get = fatfs_getc() for FatFs functions See fdevopen() sets stream->get for TTY devices.

  • man page fgetc (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
character.
EOF on error with errno set.

Definition at line 216 of file posix.c.

Referenced by fgets(), getchar(), and read().

MEMSPACE int fgetpos ( FILE stream,
size_t pos 
)

POSIX get position of file stream.

  • man page fgetpos (3).
Parameters
[in]streamPOSIX file stream.
[in]posposition pointer for return.
Returns
0 on sucess.
-1 on error with errno set.

Definition at line 522 of file posix.c.

MEMSPACE char* fgets ( char *  str,
int  size,
FILE stream 
)

get a string from stdin See fdevopen() sets stream->put get for TTY devices

POSIX string I/O

  • man page fgets (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
character.

Definition at line 420 of file posix.c.

Referenced by cat(), main(), MatRead(), ReadBdf(), setdate(), upload(), and user_tasks().

MEMSPACE int fileno ( FILE stream)

Convert POSIX stream pointer to POSIX fileno (index of __iob[])

  • man page fileno (3)
    Parameters
    [in]streamstream pointer
    Returns
    int fileno on success
    -1 with errno = EBAFD if stream is NULL or not found

Definition at line 724 of file posix.c.

Referenced by fclose(), fileno(), fileno_to_stream(), fopen(), fread(), free_file_descriptor(), fseek(), ftell(), fwrite(), open(), and ungetc().

MEMSPACE FIL* fileno_to_fatfs ( int  fileno)

Convert POSIX fileno to FatFS handle NOT POSIX.

  • FatFS file handle is pointed to by the avr-libc stream->udata.
Parameters
[in]filenofileno of file
Returns
FIL * FatFS file handle on success.
NULL if POSIX fileno is invalid NULL

Definition at line 2276 of file posix.c.

Referenced by close(), ftell(), ftruncate(), lseek(), open(), read(), sync(), syncfs(), and write().

MEMSPACE FILE* fileno_to_stream ( int  fileno)

Convert POSIX fileno to POSIX FILE stream pointer. NOT POSIX.

  • inverse of POSIX fileno()
  • man page fileno (3)
Parameters
[in]filenoPOSIX fileno is the index of __iob[].
See also
fileno()
Returns
FILE * on success
NULL on error with errno set, NULL if fileno out of bounds

Definition at line 754 of file posix.c.

Referenced by close(), fileno_to_fatfs(), fopen(), free_file_descriptor(), lseek(), open(), read(), syncfs(), and write().

MEMSPACE FILE* fopen ( const char *  path,
const char *  mode 
)

POSIX Open a file with path name and ascii file mode string.

  • man page fopen(3).
Parameters
[in]pathfilename string.
[in]modePOSIX open mode strings.
Returns
stream * on success.
NULL on error with errno set.

Definition at line 782 of file posix.c.

Referenced by buffer_read_open(), cat(), copy(), hexdump(), logfile(), main(), MatRead(), MatWrite(), ReadBdf(), sum(), timetests(), and upload().

MEMSPACE int fprintf ( FILE fp,
const char *  format,
  ... 
)

fprintf function Example user defined printf function using fputc for I/O This method allows I/O to devices and strings without typical C++ overhead

Parameters
[in]*fpFILE stream pointer
[in]fmtprintf forat string
[in]...vararg list or arguments
Returns
size of printed result

Definition at line 2484 of file posix.c.

Referenced by Convert_Font2c(), db_calloc(), emit_data(), emit_number(), emit_str(), escape(), FontHeaderInfo(), FontPreview(), FontPreviewFull(), FontPreviewProportional(), get_date(), main(), MatWrite(), ReadBdf(), send_message(), timetests(), WriteCharacterBits(), WriteFontBits(), WriteFontBitsPreview(), WriteFontInfo(), and WriteFontTable().

MEMSPACE int fputc ( int  c,
FILE stream 
)

Put a byte to TTY device or FatFs file stream open() or fopen() sets stream->put = fatfs_outc() for FatFs functions See fdevopen() sets stream->put get for TTY devices.

  • man page fputc (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
character.

Definition at line 278 of file posix.c.

Referenced by _fprintf_putc(), fputs(), putc(), putchar(), puts(), and write().

MEMSPACE int fputs ( const char *  str,
FILE stream 
)

put a string to stdout See fdevopen() sets stream->put get for TTY devices

  • man page fputs (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
character.

Definition at line 457 of file posix.c.

MEMSPACE size_t fread ( void *  ptr,
size_t  size,
size_t  nmemb,
FILE stream 
)

POSIX read nmemb elements from buf, size bytes each, to the stream fd.

  • man page fread (3).
Parameters
[in]ptrbuffer.
[in]nmembnumber of items to read.
[in]sizesize of each item in bytes.
[in]streamPOSIX file stream.
Returns
count on sucess.
0 or < size on error with errno set.

Definition at line 803 of file posix.c.

Referenced by buffer_getc(), copy(), hexdump(), main(), and sum().

MEMSPACE int free_file_descriptor ( int  fileno)

Free POSIX fileno FILE descriptor. NOT POSIX.

Parameters
[in]filenoPOSIX file number __iob[] index.
Returns
fileno on success.
-1 on failure.

Definition at line 2311 of file posix.c.

Referenced by close(), and open().

MEMSPACE int fseek ( FILE stream,
long  offset,
int  whence 
)

POSIX seek to file possition.

  • man page fseek (3).
Parameters
[in]streamPOSIX file stream.
[in]offsetoffset to seek to.
[in]whence
  • SEEK_SET The offset is set to offset bytes.
  • SEEK_CUR The offset is set to its current location plus offset bytes.
  • SEEK_END The offset is set to the size of the file plus offset bytes.
Returns
file position on sucess.
-1 on error.

Definition at line 545 of file posix.c.

Referenced by fsetpos(), and rewind().

MEMSPACE int fsetpos ( FILE stream,
size_t pos 
)

POSIX set position of file stream.

  • man page fsetpos (3).
Parameters
[in]streamPOSIX file stream.
[in]posposition pointer.
Returns
0 with *pos set to position on sucess.
-1 on error with errno set.

Definition at line 571 of file posix.c.

MEMSPACE long ftell ( FILE stream)

POSIX file position of open stream.

  • man page fteel (3).
Parameters
[in]streamPOSIX file stream.
Returns
file position on sucess.
-1 on error with errno set.

Definition at line 585 of file posix.c.

Referenced by fgetpos().

MEMSPACE int ftruncate ( int  fd,
off_t  length 
)

POSIX truncate open file to length.

  • man page ftruncate (3).
Parameters
[in]fdopen file number.
[in]lengthlength to truncate to.
Returns
0 on success.
-1 on fail.

Definition at line 827 of file posix.c.

MEMSPACE size_t fwrite ( const void *  ptr,
size_t  size,
size_t  nmemb,
FILE stream 
)

POSIX write nmemb elements from buf, size bytes each, to the stream fd.

  • man page write (2).
Parameters
[in]ptrbuffer.
[in]nmembnumber of items to write.
[in]sizesize of each item in bytes.
[in]streamPOSIX file stream.
Returns
count written on sucess.
0 or < size on error with errno set.

Definition at line 868 of file posix.c.

Referenced by copy(), logfile(), main(), and upload().

MEMSPACE int getchar ( void  )

functions normally defined as macros

get a character from stdin See fdevopen() sets stream->get for TTY devices

  • man page getchar (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
character.

Definition at line 336 of file posix.c.

Referenced by testpage().

MEMSPACE char* getcwd ( char *  pathname,
int  len 
)

POSIX get current working directory.

  • man page getcwd (2).
Parameters
[in]pathnamedirectory to change to
Returns
0 on sucess.
-1 on error with errno set.

Definition at line 1596 of file posix.c.

Referenced by ls(), main(), and posix_tests().

MEMSPACE int isatty ( int  fileno)

Test POSIX fileno if it is a Serial Console/TTY.

  • POSIX character I/O functions
    • man page isatty (3).
Parameters
[in]filenoPOSIX fileno of open file.
Returns
1 if fileno is a serial TTY/Console (uart in avr-libc terms).
0 if POSIX fileno is NOT a Serial TTY.
Todo:
Perhaps we should verify console functions have been added ?

Definition at line 196 of file posix.c.

Referenced by dump_stat(), fileno_to_fatfs(), free_file_descriptor(), ftell(), ftruncate(), lseek(), new_file_descriptor(), sync(), syncfs(), and ungetc().

MEMSPACE off_t lseek ( int  fileno,
off_t  position,
int  whence 
)

POSIX seek to file position.

  • man page lseek (2).
Parameters
[in]filenoPOSIX fileno of open file.
[in]positionoffset to seek to.
[in]whence
  • SEEK_SET The offset is set to offset bytes.
  • SEEK_CUR The offset is set to its current location plus offset bytes.
  • SEEK_END The offset is set to the size of the file plus offset bytes.
Returns
file position on sucess.
-1 on error.

Definition at line 617 of file posix.c.

Referenced by fseek().

MEMSPACE char* mctime ( time_t  timev)

Display Ascii formatted time from timev seconds NOT POSIX.

  • Assumes no timezone offset.
  • man page ctime (3).
Parameters
[in]timevepoch time in seconds
Returns
ascii string pointer of POSIX ctime()
See also
ctime()

Definition at line 1323 of file posix.c.

Referenced by dump_stat(), and ls_info().

MEMSPACE int mkdir ( const char *  pathname,
mode_t  mode 
)

POSIX make a directory.

  • man page mkdir (2).
Parameters
[in]pathnamedirectory to create
Returns
0 on sucess.
-1 on error with errno set.

Definition at line 1619 of file posix.c.

Referenced by posix_tests().

int mkfs ( char *  name)

Formt SD card.

  • FatFS to POSIX bridge functions
    Parameters
    [in]*namedevice name void

Definition at line 1922 of file posix.c.

Referenced by posix_tests().

MEMSPACE int new_file_descriptor ( void  )

Allocate a POSIX FILE descriptor. NOT POSIX.

Returns
fileno on success.
-1 on failure with errno set.

Definition at line 2355 of file posix.c.

Referenced by open().

MEMSPACE int open ( const char *  pathname,
int  flags 
)

POSIX Open a file with integer mode flags.

  • man page open (2).
Parameters
[in]pathnamefilename string.
[in]flagsPOSIX open modes.
Returns
fileno on success.
-1 on error with errno set.

Seek to end of the file

Definition at line 895 of file posix.c.

Referenced by fopen().

DIR* opendir ( const char *  pathdir)

Definition at line 1736 of file posix.c.

Referenced by ls().

MEMSPACE void perror ( const char *  s)

POSIX perror() - convert POSIX errno to text with user message.

  • man page errno (3).
Parameters
[in]sUser message displayed before the error message
See also
sys_errlist[].
Returns
void.

Definition at line 1814 of file posix.c.

Referenced by escape(), send_message(), and timetests().

MEMSPACE int posix_fopen_modes_to_open ( const char *  mode)

Convert POSIX fopen mode to POSIX open mode flags. NOT POSIX.

  • man page fopen (3).
  • man page open (2).
  • Valid modes.
  • Read
    • "r", "rb"
  • Read and Write
    • "r+", "r+b", "rb+"
  • Write
    • "w", "wb"
  • Write and Read.
    • "w+", "w+b", "wb+"
    • "w+" implies write/read access.
  • Append
    • "a", "ab"
  • Append and Read
    • "a+", "a+b", "ab+"
  • Note: ORDER IS IMPORTANT! so w+ is NOT the same as r+.
  • ALWAYS do a fflush or fseek between rear write operations if + is used..
Parameters
[in]modePOSIX file mode string.
Returns
open mode flags.
-1 on error.
Warning
read and write BOTH share the same stream buffer and buffer index pointers.

Definition at line 2418 of file posix.c.

Referenced by fopen().

MEMSPACE int putc ( int  c,
FILE stream 
)

Put a character to a stream See fdevopen() sets stream->put get for TTY devices.

  • man page putc (3).
Parameters
[in]streamPOSIX stream pointer.

Definition at line 401 of file posix.c.

MEMSPACE int putchar ( int  c)

put a character to stdout See fdevopen() sets stream->put get for TTY devices

  • man page putchar (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
character.

Definition at line 351 of file posix.c.

Referenced by fatfs_ls(), hexdump(), snprintf(), and write_buffer().

MEMSPACE int puts ( const char *  str)

put a string to stdout See fdevopen() sets stream->put get for TTY devices

  • man page puts (3).
Parameters
[in]streamPOSIX stream pointer.
Returns
character.

Definition at line 480 of file posix.c.

Referenced by cat().

MEMSPACE ssize_t read ( int  fd,
const void *  buf,
size_t  count 
)

POSIX read count bytes from *buf to fileno fd.

  • man page read (2).
Parameters
[in]fdPOSIX fileno.
[in]bufbuffer.
[in]countnumber of bytes to write.
Returns
count on sucess.
-1 on error with errno set.

Definition at line 1006 of file posix.c.

Referenced by fread(), rx_fifo_read(), and send_message().

dirent_t* readdir ( DIR dirp)

Definition at line 1755 of file posix.c.

Referenced by ls().

MEMSPACE int rename ( const char *  oldpath,
const char *  newpath 
)

POSIX rename a file by name.

  • man page (2).
Parameters
[in]oldpathoriginal name.
[in]newpathnew name.
Returns
0 on success.
-1 on error with errno set.

Definition at line 1648 of file posix.c.

Referenced by posix_tests().

MEMSPACE void rewind ( FILE stream)

POSIX rewind file to the beginning.

  • man page rewind (3).
Parameters
[in]streamPOSIX file stream.
Returns
void.

Definition at line 666 of file posix.c.

MEMSPACE int rmdir ( const char *  pathname)

POSIX delete a directory.

  • man page rmdir (2).
Parameters
[in]pathnamedirectory to delete.
Returns
0 on sucess.
-1 on error with errno set.

Definition at line 1671 of file posix.c.

Referenced by posix_tests().

MEMSPACE int stat ( char *  name,
struct stat buf 
)

POSIX stat - get file status of named file.

  • man page (2).
Parameters
[in]namefile name.
[in]bufstruct stat buffer to return results in.
Returns
0 on success.
-1 on error with errno set.

Definition at line 1344 of file posix.c.

Referenced by f_getfree(), f_mkfs(), find_volume(), ls(), ls_info(), main(), and posix_tests().

MEMSPACE char WEAK_ATR* strerror ( int  errnum)

POSIX strerror() - convert POSIX errno to text with user message.

  • man page strerror (3).
Parameters
[in]errnumindex for sys_errlist[]
See also
sys_errlist[].
Returns
char *

Definition at line 1840 of file posix.c.

MEMSPACE char* strerror_r ( int  errnum,
char *  buf,
size_t  buflen 
)

POSIX strerror_r() - convert POSIX errno to text with user message.

  • man page strerror (3).
Parameters
[in]errnumindex for sys_errlist[]
[in]bufuser buffer for error message
[in]buflenlength of user buffer for error message
See also
sys_errlist[].
Returns
char *

Definition at line 1857 of file posix.c.

MEMSPACE void sync ( void  )

POSIX Sync all pending file changes and metadata on ALL files.

  • man page sync (2).
Returns
void.

Definition at line 1069 of file posix.c.

Referenced by upload().

MEMSPACE int syncfs ( int  fd)

POSIX Sync pending file changes and metadata for specified fileno.

  • man page syncfs (2).
Parameters
[in]fdPOSIX fileno to sync.
Returns
0.
-1 on error witrh errno set.

Definition at line 1096 of file posix.c.

Referenced by sync().

MEMSPACE int truncate ( const char *  path,
off_t  length 
)

POSIX truncate named file to length.

  • man page truncate (2).
Parameters
[in]pathfile name to truncate.
[in]lengthlength to truncate to.
Returns
0 on sucess.
-1 n fail.

Definition at line 1142 of file posix.c.

MEMSPACE int ungetc ( int  c,
FILE stream 
)

Un-Get byte from a TTY device or FatFs file stream.

  • man page ungetc (3).
Parameters
[in]cCharacter to unget
[in]streamPOSIX stream pointer.
Returns
character.
EOF on error with errno set.

Definition at line 368 of file posix.c.

MEMSPACE void unix_time_to_fat ( time_t  epoch,
uint16_t date,
uint16_t time 
)

Convert Linux POSIX time_t to FAT32 date and time. NOT POSIX.

  • man page gmtime (3).
    Parameters
    [in]epochunix epoch seconds
    [in]*datefat32 date
    [in]*timefat32 time
    Returns
    void

Definition at line 2252 of file posix.c.

Referenced by utime().

MEMSPACE int unlink ( const char *  pathname)

POSIX delete a file.

  • man page unlink (2).
Parameters
[in]pathnamefilename to delete.
Returns
0 on sucess.
-1 on error with errno set.

Definition at line 1693 of file posix.c.

Referenced by posix_tests().

MEMSPACE int utime ( const char *  filename,
const struct utimbuf times 
)

Set Modification and Access time of a file.

Parameters
[in]filenamefile name

Definition at line 1407 of file posix.c.

MEMSPACE ssize_t write ( int  fd,
const void *  buf,
size_t  count 
)

POSIX Write count bytes from *buf to fileno fd.

  • man page write (2).
Parameters
[in]fdPOSIX fileno.
[in]bufbuffer.
[in]countnumber of bytes to write.
Returns
count on sucess.
-1 on error with errno set.

Definition at line 1180 of file posix.c.

Referenced by fwrite(), and send_message().

Variable Documentation

FILE* __iob[MAX_FILES]

POSIX fileno to POSIX FILE stream table.

  • Note: the index of __iob[] is reffered to "fileno".
  • Reference: libc/avr-libc-1.8.0/libc/stdio.
  • stdin = __iob[0].
  • __iob[1] = stdout.
  • __iob[2] = stderr.

Definition at line 139 of file posix.c.

dirent_t _de
static

POSIX opendir.

  • man page readdir(2).
Parameters
[in]dirpDIR * directory handle
Returns
DIR * on sucess.
NULL on error with errno set.

Definition at line 1754 of file posix.c.

DIR _dp
static

POSIX opendir.

  • man page opendir (2).
Parameters
[in]pathnamedirectory to delete.
Returns
DIR * on sucess.
NULL on error with errno set.

Definition at line 1735 of file posix.c.

int errno
const char* sys_errlist[]

POSIX error messages for each errno value.

  • man page errno (3)

Definition at line 144 of file posix.c.

Referenced by perror(), strerror(), and strerror_r().