27 #ifndef _UCOMMON_FSYS_H_
28 #define _UCOMMON_FSYS_H_
30 #ifndef _UCOMMON_CONFIG_H_
34 #ifndef _UCOMMON_PROTOCOLS_H_
38 #ifndef _UCOMMON_THREAD_H_
42 #ifndef _UCOMMON_STRING_H_
46 #ifndef _UCOMMON_MEMORY_H_
66 #define __S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
69 #if !defined(S_ISDIR) && defined(S_IFDIR)
70 #define S_ISDIR(mode) __S_ISTYPE((mode), S_IFDIR)
73 #if !defined(S_ISCHR) && defined(S_IFCHR)
74 #define S_ISCHR(mode) __S_ISTYPE((mode), S_IFCHR)
75 #elif !defined(S_ISCHR)
76 #define S_ISCHR(mode) 0
79 #if !defined(S_ISBLK) && defined(S_IFBLK)
80 #define S_ISBLK(mode) __S_ISTYPE((mode), S_IFBLK)
81 #elif !defined(S_ISBLK)
82 #define S_ISBLK(mode) 0
85 #if !defined(S_ISREG) && defined(S_IFREG)
86 #define S_ISREG(mode) __S_ISTYPE((mode), S_IFREG)
87 #elif !defined(S_ISREG)
88 #define S_ISREG(mode) 1
91 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
92 #define S_ISSOCK(mode) __S_ISTYPE((mode), S_IFSOCK)
93 #elif !defined(S_ISSOCK)
94 #define S_ISSOCK(mode) (0)
97 #if !defined(S_ISFIFO) && defined(S_IFIFO)
98 #define S_ISFIFO(mode) __S_ISTYPE((mode), S_IFIFO)
99 #elif !defined(S_ISFIFO)
100 #define S_ISFIFO(mode) (0)
103 #if !defined(S_ISLNK) && defined(S_IFLNK)
104 #define S_ISLNK(mode) __S_ISTYPE((mode), S_IFLNK)
105 #elif !defined(S_ISLNK)
106 #define S_ISLNK(mode) (0)
135 OWNER_READONLY = 0400,
136 GROUP_READONLY = 0440,
137 PUBLIC_READONLY = 0444,
138 OWNER_PRIVATE = 0600,
140 GROUP_PRIVATE = 0660,
143 DIR_TEMPORARY = 01777
146 typedef struct stat fileinfo_t;
149 static int remapError(
void);
151 inline static int remapError(
void)
228 inline operator fd_t()
const
241 inline operator bool()
const
242 {
return fd != INVALID_HANDLE_VALUE;}
249 {
return fd == INVALID_HANDLE_VALUE;}
255 void operator=(
const fsys& descriptor);
262 void operator*=(fd_t& descriptor);
268 void operator=(fd_t descriptor);
281 void set(fd_t descriptor);
294 int seek(offset_t offset);
301 int drop(offset_t size = 0);
313 static bool is_tty(fd_t fd);
321 ssize_t read(
void *buffer,
size_t count);
329 ssize_t write(
const void *buffer,
size_t count);
336 int info(fileinfo_t *buffer);
344 int trunc(offset_t offset);
357 static int prefix(
const char *path);
365 static int prefix(
char *path,
size_t size);
375 static int info(
const char *path, fileinfo_t *buffer);
382 static int erase(
const char *path);
391 static int copy(
const char *source,
const char *target,
size_t size = 1024);
399 static int rename(
const char *oldpath,
const char *newpath);
407 static int mode(
const char *path,
unsigned value);
414 static bool is_exists(
const char *path);
421 static bool is_readable(
const char *path);
428 static bool is_writable(
const char *path);
435 static bool is_executable(
const char *path);
442 static bool is_file(
const char *path);
449 static bool is_dir(
const char *path);
456 static bool is_link(
const char *path);
463 static bool is_device(
const char *path);
470 static bool is_hidden(
const char *path);
477 void open(
const char *path, access_t
access);
484 {close(); fd = descriptor;};
492 {
object.close();
object.fd = descriptor;};
500 void open(
const char *path,
unsigned mode, access_t
access);
509 static int unlink(
const char *path);
517 static int link(
const char *path,
const char *target);
525 static int hardlink(
const char *path,
const char *target);
533 static int linkinfo(
const char *path,
char *buffer,
size_t size);
545 inline int err(
void)
const
553 static fd_t input(
const char *path);
560 static fd_t output(
const char *path);
567 static fd_t append(
const char *path);
573 static void release(fd_t descriptor);
582 static int pipe(fd_t& input, fd_t& output,
size_t size = 0);
592 static int inherit(fd_t& descriptor,
bool enable);
598 static fd_t null(
void);
605 static int load(
const char *path);
614 static int exec(
const char *path,
char **argv,
char **envp = NULL);
616 static inline bool is_file(
struct stat *inode)
617 {
return S_ISREG(inode->st_mode);}
619 static inline bool is_dir(
struct stat *inode)
620 {
return S_ISDIR(inode->st_mode);}
622 static inline bool is_link(
struct stat *inode)
623 {
return S_ISLNK(inode->st_mode);}
625 static inline bool is_dev(
struct stat *inode)
626 {
return S_ISBLK(inode->st_mode) || S_ISCHR(inode->st_mode);}
628 static inline bool is_char(
struct stat *inode)
629 {
return S_ISCHR(inode->st_mode);}
631 static inline bool is_disk(
struct stat *inode)
632 {
return S_ISBLK(inode->st_mode);}
634 static inline bool is_sys(
struct stat *inode)
635 {
return S_ISSOCK(inode->st_mode) || S_ISFIFO(inode->st_mode);}
656 typedef int (FAR WINAPI *addr_t)();
658 typedef void *addr_t;
670 dso(
const char *path);
681 void map(
const char *path);
694 addr_t find(
const char *symbol)
const;
696 inline int err(
void)
const
699 inline addr_t operator[](
const char *symbol)
const
700 {
return find(symbol);}
702 inline addr_t operator()(
const char *symbol)
const
703 {
return find(symbol);}
705 inline operator bool()
706 {
return ptr != NULL;}
708 inline bool operator!()
709 {
return ptr == NULL;}
720 WIN32_FIND_DATA *ptr;
731 dir(
const char *path);
749 static int create(
const char *path,
unsigned mode);
756 static int remove(
const char *path);
762 void open(
const char *path);
770 ssize_t
read(
char *buffer,
size_t count);
777 inline int err(
void)
const
780 inline void reset(
void)
787 inline operator bool()
const
788 {
return ptr != NULL;};
795 {
return ptr == NULL;};
807 inline bool is_exists(
const char *path)
808 {
return fsys::is_exists(path);}
810 inline bool is_readable(
const char *path)
811 {
return fsys::is_readable(path);}
813 inline bool is_writable(
const char *path)
814 {
return fsys::is_writable(path);}
816 inline bool is_executable(
const char *path)
817 {
return fsys::is_executable(path);}
819 inline bool is_file(
const char *path)
820 {
return fsys::is_file(path);}
822 inline bool is_dir(
const char *path)
823 {
return fsys::is_dir(path);}
825 inline bool is_link(
const char *path)
826 {
return fsys::is_link(path);}
828 inline bool is_device(
const char *path)
829 {
return fsys::is_device(path);}
Convenience class for library plugins.
void assign(fd_t descriptor)
Assign descriptor directly.
A container for generic and o/s portable threadsafe file system functions.
void release(SharedAccess &object)
Convenience function to unlock shared object through it's protocol.
static const offset_t end
Used to mark "append" in set position operations.
A copy-on-write string class that operates by reference count.
bool operator!() const
Test if file descriptor is closed.
bool operator!() const
Test if file descriptor is closed.
int err(void) const
Get last error.
access_t
Enumerated file access modes.
void * mem_t
Convenience type for loader operations.
ssize_t read(void *buffer, size_t count)
Read data from descriptor or scan directory.
fd_t handle(void) const
Get the native system descriptor handle of the file descriptor.
Thread classes and sychronization objects.
A common string class and character string support functions.
fsys fsys_t
Convience type for fsys.
static void assign(fsys &object, fd_t descriptor)
Assign a descriptor directly.
Abstract interfaces and support.
long offset_t
File offset type.
ObjectProtocol * copy(ObjectProtocol *object)
Convenience function to access object copy.
Private heaps, pools, and associations.
void reset(void)
Reset error flag.
int close(void)
Close a fsys resource.
void access(SharedAccess &object)
Convenience function to access (lock) shared object through it's protocol.
void open(const char *path, access_t access)
Open a file or directory.
Various miscellaneous platform specific headers and defines.
fd_t operator*() const
Get the descriptor from the object by pointer reference.
Convenience class for directories.