53 "posix prefix is optional\n" 55 "posix chmod file NNN\n" 56 "posix cat file [-p]\n" 58 "posix copy file1 file2\n" 59 "posix hexdump file [-p]\n" 70 "posix rename old new\n" 95 if(
MATCH(ptr,
"posix") )
98 if ( !ptr ||
MATCH(ptr,
"help") )
105 if (
MATCHARGS(ptr,
"cat", (ind + 1), argc))
109 for(i=ind;i<argc;++i)
111 if(
MATCH(argv[i],
"-p"))
114 for(i=ind;i<argc;++i)
116 if(!
MATCH(argv[i],
"-p"))
117 cat(argv[ind], page);
129 if (
MATCHARGS(ptr,
"copy", (ind + 2), argc))
131 copy(argv[ind],argv[ind+1]);
135 if (
MATCHARGS(ptr,
"cd", (ind + 1), argc))
142 if (
MATCHARGS(ptr,
"hexdump", (ind + 1), argc))
146 for(i=ind;i<argc;++i)
148 if(
MATCH(argv[i],
"-p"))
151 for(i=ind;i<argc;++i)
153 if(!
MATCH(argv[i],
"-p"))
159 if (
MATCHARGS(ptr,
"log", (ind + 2), argc))
161 logfile(argv[ind],argv[ind+1]);
165 if (
MATCHARGS(ptr,
"ls", (ind + 0), argc))
169 for(i=ind;i<argc;++i)
171 if(!
MATCH(argv[i],
"-l"))
182 if (
MATCHARGS(ptr,
"mkfs", (ind + 1), argc))
189 if (
MATCHARGS(ptr,
"mkdir", (ind + 1), argc))
196 mkdir(argv[ind],mode);
200 if (
MATCHARGS(ptr,
"page", (ind + 1), argc))
206 if (
MATCHARGS(ptr,
"pwd", (ind + 0), argc))
213 if (
MATCHARGS(ptr,
"rename", (ind + 2), argc))
215 rename(argv[ind],argv[ind+1]);
219 if (
MATCHARGS(ptr,
"rm", (ind + 1), argc))
225 if (
MATCHARGS(ptr,
"sum", (ind + 1), argc))
231 if (
MATCHARGS(ptr,
"stat", (ind + 1), argc))
239 if (
MATCHARGS(ptr,
"rmdir", (ind + 1), argc))
245 if (
MATCHARGS(ptr,
"upload", (ind + 1), argc))
259 long cat(
char *name,
int dopage)
266 fp =
fopen(name,
"rb");
269 printf(
"Can't open: %s\n", name);
272 while(
fgets(line,
sizeof(line)-2,fp) !=
NULL)
291 printf(
"%ld bytes\n", (
long)size);
309 printf(
"Opening %s\n", from);
311 fi =
fopen(from,
"rb");
314 printf(
"Can't open: %s\n", from);
318 printf(
"Creating %s\n", to);
322 printf(
"Can't open: %s\n", to);
338 if( (
int)
fwrite(buf,1,len,fo) < len)
344 printf(
"Copied: %08ld\r", size);
350 printf(
"%lu bytes copied.\n", size);
374 printf(
"Can' open: %s\n", name);
380 while( (len =
fread(buf,1, 16, fi)) > 0)
385 printf(
"%02x ",0xff & buf[i]);
393 if(buf[i] >= 0x20 && buf[i] <= 0x7e)
474 if(
stat(name, &sp) == -1)
476 printf(
"can not stat: %s\n", name);
504 printf(
"%s none none %12ld %s %s\n",
517 int ls(
char *name,
int verbose)
527 if(!name || !*name ||
MATCH(name,
".") )
529 if( !
getcwd(fullpath,
sizeof(fullpath)-2) )
531 printf(
"ls: Can't get current directory\n");
543 printf(
"Listing:[%s]\n",fullpath);
545 if (
stat(fullpath, &st))
547 printf(
"ls: cannot stat [%s]\n", fullpath);
560 printf(
"opendir failed\n");
571 printf(
"name:[%s] too long with full path\n",de->
d_name);
574 if(!
MATCH(fullpath,
"/") )
579 files +=
ls_info(fullpath,verbose);
590 printf(
"Files: %d\n", (
int)files);
605 fo =
fopen(name,
"ab");
608 printf(
"Can't open: %s\n", name);
613 if(
fwrite(str,1,size,fo) < size)
637 printf(
"Can' open: %s\n", name);
641 while( (len =
fread(buffer,1, 256, fi)) > 0)
644 sum += (0xff & buffer[i]);
651 printf(
"Sum: %04Xh, %5u\n", (
int) sum, (
unsigned int) sum);
668 fp =
fopen(name,
"wb");
671 printf(
"Can' open: %s\n", name);
684 len2 =
fwrite(buffer, 1, len,fp);
MEMSPACE long upload(char *name)
Capture an ASCII file to sdcard First blank line exits capture.
MEMSPACE WEAK_ATR char * strcat(char *dest, const char *src)
Append string.
char d_name[MAX_NAME_LEN]
MEMSPACE int testpage(int count)
Used to page output of functions like cat, hexdump, etc.
MEMSPACE size_t WEAK_ATR strlen(const char *str)
String Length.
MEMSPACE void dump_stat(struct stat *sp)
Display struct stat, from POSIX stat(0 or fstat(), in ASCII. NOT POSIX.
MEMSPACE void sync(void)
POSIX Sync all pending file changes and metadata on ALL files.
dirent_t * readdir(DIR *dirp)
Master include file for project Includes all project includes and defines here.
Common Linux/POSIX time functions.
MEMSPACE int setpage(int count)
MEMSPACE void posix_help(int full)
MEMSPACE int ls_info(char *name, int verbose)
list one file
MEMSPACE char * fgets(char *str, int size, FILE *stream)
get a string from stdin See fdevopen() sets stream->put get for TTY devices
MEMSPACE FILE * fopen(const char *path, const char *mode)
POSIX Open a file with path name and ascii file mode string.
MEMSPACE int rmdir(const char *pathname)
POSIX delete a directory.
int mkfs(char *name)
Formt SD card.
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.
MEMSPACE long copy(char *from, char *to)
Copy a file.
void optimistic_yield(uint32_t interval_us)
int putchar(int c)
put a character to stdout See fdevopen() sets stream->put get for TTY devices
MEMSPACE WEAK_ATR char * strcpy(char *dest, const char *src)
copy a string
uint32_t time_t
type of EPOCH result.
MEMSPACE uint16_t sum(char *name)
sum of a file with 16bit hex and integer results
MEMSPACE void trim_tail(char *str)
Trim White space and control characters from end of string.
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.
MEMSPACE int unlink(const char *pathname)
POSIX delete a file.
MEMSPACE int hexdump(char *name, int dopage)
hex listing of file with paging, "q" exits
Math IO functions, and verious conversion code with floating point support.
MEMSPACE int fclose(FILE *stream)
POSIX close a file stream.
static int _pagesize
Used to page output of functions like cat, hexdump, etc.
MEMSPACE long strtol(const char *nptr, char **endptr, int base)
Convert ASCII string to number in a given base.
#define stdin
define stdin, stdout and stderr
MEMSPACE long cat(char *name, int dopage)
Display the contents of a file.
MEMSPACE long logfile(char *name, char *str)
Log string to a file.
Various string and character functions.
MEMSPACE int posix_tests(int argc, char *argv[])
POSIX tests.
MEMSPACE int puts(const char *str)
put a string to stdout See fdevopen() sets stream->put get for TTY devices
MEMSPACE void wdt_reset(void)
reset watchdog
MEMSPACE int mkdir(const char *pathname, mode_t mode)
POSIX make a directory.
int closedir(DIR *dirp)
POSIX closedir.
MEMSPACE int chmod(const char *pathname, mode_t mode)
POSIX chmod function - change file access permission Unfortunately file f_open modes and f_chmod mode...
MEMSPACE int printf(const char *format,...)
MEMSPACE int MATCHARGS(char *str, char *pat, int min, int argc)
Match two strings and compare argument index Display message if the number of arguments is too few...
MEMSPACE int chdir(const char *pathname)
POSIX change directory.
MEMSPACE char * basename(char *str)
POSIX Basename of filename.
MEMSPACE char * getcwd(char *pathname, int len)
POSIX get current working directory.
int kbhit(int uart_no)
Has ANY character been read in stdin.
MEMSPACE int stat(char *name, struct stat *buf)
POSIX stat - get file status of named file.
MEMSPACE void safefree(void *p)
Safe free - Only free a pointer if it is in malloc memory range. We want to try to catch frees of sta...
MEMSPACE char * mctime(time_t timev)
Display Ascii formatted time from timev seconds NOT POSIX.
MEMSPACE int getchar()
functions normally defined as macros
DIR * opendir(const char *pathdir)
MEMSPACE int atoi(const char *str)
Convert ASCII string to number in base 10.
MEMSPACE int ls(char *name, int verbose)
Directory listing.
MEMSPACE void * safecalloc(size_t nmemb, size_t size)
Safe Calloc - Display Error message if Calloc fails.
MEMSPACE int rename(const char *oldpath, const char *newpath)
POSIX rename a file by name.
#define S_IFMT
POSIX File types, see fstat and stat.