28 #ifndef _UCOMMON_FSYS_H_
29 #define _UCOMMON_FSYS_H_
31 #ifndef _UCOMMON_CONFIG_H_
35 #ifndef _UCOMMON_PROTOCOLS_H_
39 #ifndef _UCOMMON_THREAD_H_
43 #ifndef _UCOMMON_STRING_H_
47 #ifndef _UCOMMON_TYPEREF_H_
51 #ifndef _UCOMMON_MEMORY_H_
71 #define __S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
74 #if !defined(S_ISDIR) && defined(S_IFDIR)
75 #define S_ISDIR(mode) __S_ISTYPE((mode), S_IFDIR)
78 #if !defined(S_ISCHR) && defined(S_IFCHR)
79 #define S_ISCHR(mode) __S_ISTYPE((mode), S_IFCHR)
80 #elif !defined(S_ISCHR)
81 #define S_ISCHR(mode) 0
84 #if !defined(S_ISBLK) && defined(S_IFBLK)
85 #define S_ISBLK(mode) __S_ISTYPE((mode), S_IFBLK)
86 #elif !defined(S_ISBLK)
87 #define S_ISBLK(mode) 0
90 #if !defined(S_ISREG) && defined(S_IFREG)
91 #define S_ISREG(mode) __S_ISTYPE((mode), S_IFREG)
92 #elif !defined(S_ISREG)
93 #define S_ISREG(mode) 1
96 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
97 #define S_ISSOCK(mode) __S_ISTYPE((mode), S_IFSOCK)
98 #elif !defined(S_ISSOCK)
99 #define S_ISSOCK(mode) (0)
102 #if !defined(S_ISFIFO) && defined(S_IFIFO)
103 #define S_ISFIFO(mode) __S_ISTYPE((mode), S_IFIFO)
104 #elif !defined(S_ISFIFO)
105 #define S_ISFIFO(mode) (0)
108 #if !defined(S_ISLNK) && defined(S_IFLNK)
109 #define S_ISLNK(mode) __S_ISTYPE((mode), S_IFLNK)
110 #elif !defined(S_ISLNK)
111 #define S_ISLNK(mode) (0)
140 OWNER_READONLY = 0400,
141 GROUP_READONLY = 0440,
142 PUBLIC_READONLY = 0444,
143 OWNER_PRIVATE = 0600,
145 GROUP_PRIVATE = 0660,
148 DIR_TEMPORARY = 01777
151 typedef struct stat fileinfo_t;
154 static int remapError(
void);
156 inline static int remapError(
void) {
185 static const offset_t
end;
235 inline operator fd_t()
const {
250 inline operator bool()
const {
251 return fd != INVALID_HANDLE_VALUE;
259 return fd == INVALID_HANDLE_VALUE;
266 void operator=(
const fsys& descriptor);
273 void operator*=(fd_t& descriptor);
279 void operator=(fd_t descriptor);
293 void set(fd_t descriptor);
306 int seek(offset_t offset);
313 int drop(offset_t size = 0);
319 bool is_tty(
void)
const;
325 static bool is_tty(fd_t fd);
333 ssize_t read(
void *buffer,
size_t count);
341 ssize_t write(
const void *buffer,
size_t count);
348 int info(fileinfo_t *buffer);
356 int trunc(offset_t offset);
369 static int prefix(
const char *path);
377 static int prefix(
char *path,
size_t size);
388 static int info(
const char *path, fileinfo_t *buffer);
395 static int erase(
const char *path);
404 static int copy(
const char *source,
const char *target,
size_t size = 1024);
412 static int rename(
const char *oldpath,
const char *newpath);
420 static int mode(
const char *path,
unsigned value);
427 static bool is_exists(
const char *path);
434 static bool is_readable(
const char *path);
441 static bool is_writable(
const char *path);
448 static bool is_executable(
const char *path);
455 static bool is_file(
const char *path);
462 static bool is_dir(
const char *path);
469 static bool is_link(
const char *path);
476 static bool is_device(
const char *path);
483 static bool is_hidden(
const char *path);
490 void open(
const char *path, access_t
access);
508 object.fd = descriptor;
517 void open(
const char *path,
unsigned mode, access_t
access);
526 static int unlink(
const char *path);
534 static int link(
const char *path,
const char *target);
542 static int hardlink(
const char *path,
const char *target);
550 static int linkinfo(
const char *path,
char *buffer,
size_t size);
562 inline int err(
void)
const {
571 static fd_t input(
const char *path);
578 static fd_t output(
const char *path);
585 static fd_t append(
const char *path);
591 static void release(fd_t descriptor);
600 static int pipe(fd_t& input, fd_t& output,
size_t size = 0);
610 static int inherit(fd_t& descriptor,
bool enable);
616 static fd_t null(
void);
623 static int load(
const char *path);
632 static int exec(
const char *path,
char **argv,
char **envp = NULL);
634 static inline bool is_file(
struct stat *inode) {
635 return S_ISREG(inode->st_mode);
638 static inline bool is_dir(
struct stat *inode) {
639 return S_ISDIR(inode->st_mode);
642 static inline bool is_link(
struct stat *inode) {
643 return S_ISLNK(inode->st_mode);
646 static inline bool is_dev(
struct stat *inode) {
647 return S_ISBLK(inode->st_mode) || S_ISCHR(inode->st_mode);
650 static inline bool is_char(
struct stat *inode) {
651 return S_ISCHR(inode->st_mode);
654 static inline bool is_disk(
struct stat *inode) {
655 return S_ISBLK(inode->st_mode);
658 static inline bool is_sys(
struct stat *inode) {
659 return S_ISSOCK(inode->st_mode) || S_ISFIFO(inode->st_mode);
683 typedef int (FAR WINAPI *addr_t)();
685 typedef void *addr_t;
697 dso(
const char *path);
708 void map(
const char *path);
721 addr_t find(
const char *symbol)
const;
723 inline int err(
void)
const {
727 inline addr_t operator[](
const char *symbol)
const {
731 inline addr_t operator()(
const char *symbol)
const {
735 inline operator bool()
const {
739 inline bool operator!()
const {
752 WIN32_FIND_DATA *ptr;
763 dir(
const char *path);
781 static int create(
const char *path,
unsigned mode);
788 static int remove(
const char *path);
794 void open(
const char *path);
802 ssize_t read(
char *buffer,
size_t count);
809 inline int err(
void)
const {
813 inline void reset(
void) {
821 inline operator bool()
const {
843 inline bool is_exists(
const char *path)
848 inline bool is_readable(
const char *path)
853 inline bool is_writable(
const char *path)
858 inline bool is_executable(
const char *path)
863 inline bool is_file(
const char *path)
868 inline bool is_dir(
const char *path)
873 inline bool is_link(
const char *path)
878 inline bool is_device(
const char *path)
static void assign(fsys &object, fd_t descriptor)
Assign a descriptor directly.
void access(SharedAccess &object)
Convenience function to access (lock) shared object through it's protocol.
A common string class and character string support functions.
void release(SharedAccess &object)
Convenience function to unlock shared object through it's protocol.
Thread classes and sychronization objects.
void * mem_t
Convenience type for loader operations.
fd_t operator*() const
Get the descriptor from the object by pointer reference.
Various miscellaneous platform specific headers and defines.
A thread-safe atomic heap management system.
static bool is_writable(const char *path)
Test if path writable.
Convenience class for directories.
static bool is_file(const char *path)
Test if path is a file.
void reset(void)
Reset error flag.
ObjectProtocol * copy(ObjectProtocol *object)
Convenience function to access object copy.
A copy-on-write string class that operates by reference count.
A container for generic and o/s portable threadsafe file system functions.
access_t
Enumerated file access modes.
static bool is_link(const char *path)
Test if path is a symlink.
fsys fsys_t
Convience type for fsys.
Convenience class for library plugins.
Private heaps, pools, and associations.
static const offset_t end
Used to mark "append" in set position operations.
static bool is_readable(const char *path)
Test if path readable.
static bool is_exists(const char *path)
Test if path exists.
long offset_t
File offset type.
Common namespace for all ucommon objects.
static bool is_device(const char *path)
Test if path is a device path.
void assign(fd_t descriptor)
Assign descriptor directly.
static bool is_dir(const char *path)
Test if path is a directory.
static bool is_executable(const char *path)
Test if path is executable.
bool operator!() const
Test if file descriptor is closed.
int err(void) const
Get last error.
fd_t handle(void) const
Get the native system descriptor handle of the file descriptor.
Abstract interfaces and support.
bool operator!() const
Test if file descriptor is closed.