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) {
176 typedef long offset_t;
181 static const offset_t end;
197 fsys(
const fsys& descriptor);
204 fsys(
const char *path, access_t access);
212 fsys(
const char *path,
unsigned permission, access_t access);
223 inline fd_t operator*()
const {
231 inline operator fd_t()
const {
238 inline void reset(
void) {
246 inline operator bool()
const {
247 return fd != INVALID_HANDLE_VALUE;
254 inline bool operator!()
const {
255 return fd == INVALID_HANDLE_VALUE;
262 fsys& operator=(
const fsys& descriptor);
269 fsys& operator*=(fd_t& descriptor);
275 fsys& operator=(fd_t descriptor);
281 inline fd_t handle(
void)
const {
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);
491 inline void assign(fd_t descriptor) {
501 inline static void assign(fsys&
object, fd_t descriptor) {
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 {
743 class __EXPORT dir :
private fsys
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 {
824 inline bool operator!()
const {
838 inline bool is_exists(
const char *path)
840 return fsys::is_exists(path);
843 inline bool is_readable(
const char *path)
845 return fsys::is_readable(path);
848 inline bool is_writable(
const char *path)
850 return fsys::is_writable(path);
853 inline bool is_executable(
const char *path)
855 return fsys::is_executable(path);
858 inline bool is_file(
const char *path)
860 return fsys::is_file(path);
863 inline bool is_dir(
const char *path)
865 return fsys::is_dir(path);
868 inline bool is_link(
const char *path)
870 return fsys::is_link(path);
873 inline bool is_device(
const char *path)
875 return fsys::is_device(path);
T copy(const T &src)
Convenience function to copy objects.
A thread-safe atomic heap management system.
class __attribute__((visibility("default"))) dir typedef fsys fsys_t
Convenience class for directories.
Various miscellaneous platform specific headers and defines.
Abstract interfaces and support.
Private heaps, pools, and associations.
Common namespace for all ucommon objects.
void * mem_t
Convenience type for loader operations.
Thread classes and sychronization objects.