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_TYPEREF_H_ 47 #ifndef _UCOMMON_MEMORY_H_ 67 #define __S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask)) 70 #if !defined(S_ISDIR) && defined(S_IFDIR) 71 #define S_ISDIR(mode) __S_ISTYPE((mode), S_IFDIR) 74 #if !defined(S_ISCHR) && defined(S_IFCHR) 75 #define S_ISCHR(mode) __S_ISTYPE((mode), S_IFCHR) 76 #elif !defined(S_ISCHR) 77 #define S_ISCHR(mode) 0 80 #if !defined(S_ISBLK) && defined(S_IFBLK) 81 #define S_ISBLK(mode) __S_ISTYPE((mode), S_IFBLK) 82 #elif !defined(S_ISBLK) 83 #define S_ISBLK(mode) 0 86 #if !defined(S_ISREG) && defined(S_IFREG) 87 #define S_ISREG(mode) __S_ISTYPE((mode), S_IFREG) 88 #elif !defined(S_ISREG) 89 #define S_ISREG(mode) 1 92 #if !defined(S_ISSOCK) && defined(S_IFSOCK) 93 #define S_ISSOCK(mode) __S_ISTYPE((mode), S_IFSOCK) 94 #elif !defined(S_ISSOCK) 95 #define S_ISSOCK(mode) (0) 98 #if !defined(S_ISFIFO) && defined(S_IFIFO) 99 #define S_ISFIFO(mode) __S_ISTYPE((mode), S_IFIFO) 100 #elif !defined(S_ISFIFO) 101 #define S_ISFIFO(mode) (0) 104 #if !defined(S_ISLNK) && defined(S_IFLNK) 105 #define S_ISLNK(mode) __S_ISTYPE((mode), S_IFLNK) 106 #elif !defined(S_ISLNK) 107 #define S_ISLNK(mode) (0) 136 OWNER_READONLY = 0400,
137 GROUP_READONLY = 0440,
138 PUBLIC_READONLY = 0444,
139 OWNER_PRIVATE = 0600,
141 GROUP_PRIVATE = 0660,
144 DIR_TEMPORARY = 01777
147 typedef struct stat fileinfo_t;
150 static int remapError(
void);
152 inline static int remapError(
void) {
212 fsys(
const char *path,
unsigned permission,
access_t access);
223 inline fd_t operator*()
const {
231 inline operator fd_t()
const {
246 inline operator bool()
const {
247 return fd != INVALID_HANDLE_VALUE;
255 return fd == INVALID_HANDLE_VALUE;
262 fsys& operator=(
const fsys& descriptor);
269 fsys& operator*=(fd_t& descriptor);
275 fsys& operator=(fd_t descriptor);
289 void set(fd_t descriptor);
302 int seek(offset_t offset);
309 int drop(offset_t size = 0);
315 bool is_tty(
void)
const;
321 static bool is_tty(fd_t fd);
329 ssize_t read(
void *buffer,
size_t count);
337 ssize_t write(
const void *buffer,
size_t count);
344 int info(fileinfo_t *buffer);
352 int trunc(offset_t offset);
365 static int prefix(
const char *path);
373 static int prefix(
char *path,
size_t size);
375 static stringref_t prefix(
void);
383 static int info(
const char *path, fileinfo_t *buffer);
390 static int erase(
const char *path);
399 static int copy(
const char *source,
const char *target,
size_t size = 1024);
407 static int rename(
const char *oldpath,
const char *newpath);
415 static int mode(
const char *path,
unsigned value);
422 static bool is_exists(
const char *path);
429 static bool is_readable(
const char *path);
436 static bool is_writable(
const char *path);
443 static bool is_executable(
const char *path);
450 static bool is_file(
const char *path);
457 static bool is_dir(
const char *path);
464 static bool is_link(
const char *path);
471 static bool is_device(
const char *path);
478 static bool is_hidden(
const char *path);
485 void open(
const char *path, access_t access);
503 object.fd = descriptor;
512 void open(
const char *path,
unsigned mode, access_t access);
521 static int unlink(
const char *path);
529 static int link(
const char *path,
const char *target);
537 static int hardlink(
const char *path,
const char *target);
545 static int linkinfo(
const char *path,
char *buffer,
size_t size);
557 inline int err(
void)
const {
566 static fd_t input(
const char *path);
573 static fd_t output(
const char *path);
580 static fd_t append(
const char *path);
586 static void release(fd_t descriptor);
595 static int pipe(fd_t& input, fd_t& output,
size_t size = 0);
605 static int inherit(fd_t& descriptor,
bool enable);
611 static fd_t
null(void);
618 static int load(
const char *path);
627 static int exec(
const char *path,
char **argv,
char **envp = NULL);
629 static inline bool is_file(
struct stat *inode) {
630 return S_ISREG(inode->st_mode);
633 static inline bool is_dir(
struct stat *inode) {
634 return S_ISDIR(inode->st_mode);
637 static inline bool is_link(
struct stat *inode) {
638 return S_ISLNK(inode->st_mode);
641 static inline bool is_dev(
struct stat *inode) {
642 return S_ISBLK(inode->st_mode) || S_ISCHR(inode->st_mode);
645 static inline bool is_char(
struct stat *inode) {
646 return S_ISCHR(inode->st_mode);
649 static inline bool is_disk(
struct stat *inode) {
650 return S_ISBLK(inode->st_mode);
653 static inline bool is_sys(
struct stat *inode) {
654 return S_ISSOCK(inode->st_mode) || S_ISFIFO(inode->st_mode);
678 typedef int (FAR WINAPI *addr_t)();
680 typedef void *addr_t;
692 dso(
const char *path);
703 void map(
const char *path);
716 addr_t find(
const char *symbol)
const;
718 inline int err(
void)
const {
722 inline addr_t operator[](
const char *symbol)
const {
726 inline addr_t operator()(
const char *symbol)
const {
730 inline operator bool()
const {
734 inline bool operator!()
const {
747 WIN32_FIND_DATA *ptr;
758 dir(
const char *path);
776 static int create(
const char *path,
unsigned mode);
783 static int remove(
const char *path);
789 void open(
const char *path);
797 ssize_t read(
char *buffer,
size_t count);
804 inline int err(
void)
const {
808 inline void reset(
void) {
816 inline operator bool()
const {
838 inline bool is_exists(
const char *path)
843 inline bool is_readable(
const char *path)
848 inline bool is_writable(
const char *path)
853 inline bool is_executable(
const char *path)
858 inline bool is_file(
const char *path)
863 inline bool is_dir(
const char *path)
868 inline bool is_link(
const char *path)
873 inline bool is_device(
const char *path)
int err(void) const
Get last error.
fsys fsys_t
Convience type for fsys.
fd_t handle(void) const
Get the native system descriptor handle of the file descriptor.
static const offset_t end
Used to mark "append" in set position operations.
bool operator!() const
Test if file descriptor is closed.
static bool is_readable(const char *path)
Test if path readable.
static bool is_dir(const char *path)
Test if path is a directory.
bool operator!() const
Test if file descriptor is closed.
void assign(fd_t descriptor)
Assign descriptor directly.
void * mem_t
Convenience type for loader operations.
Convenience class for library plugins.
static bool is_device(const char *path)
Test if path is a device path.
Thread classes and sychronization objects.
Convenience class for directories.
Private heaps, pools, and associations.
static bool is_exists(const char *path)
Test if path exists.
long offset_t
File offset type.
Various miscellaneous platform specific headers and defines.
Common namespace for all ucommon objects.
T copy(const T &src)
Convenience function to copy objects.
Abstract interfaces and support.
static bool is_link(const char *path)
Test if path is a symlink.
static void assign(fsys &object, fd_t descriptor)
Assign a descriptor directly.
void reset(void)
Reset error flag.
access_t
Enumerated file access modes.
static bool is_writable(const char *path)
Test if path writable.
A container for generic and o/s portable threadsafe file system functions.
static bool is_file(const char *path)
Test if path is a file.
static bool is_executable(const char *path)
Test if path is executable.
A thread-safe atomic heap management system.