X-Git-Url: http://git.silcnet.org/gitweb/?p=runtime.git;a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcfileutil.h;h=0824553804a32a497b216e565b6f3d2aa4fe7f8c;hp=a02c49b3a3126a56982f7ea234dacf3c0a33c2ca;hb=5586a7f0e211638059148cc853e47caedf53d098;hpb=88c430b4a9562ab0aa6dc410bfbf76a1f9ebb407 diff --git a/lib/silcutil/silcfileutil.h b/lib/silcutil/silcfileutil.h index a02c49b3..08245538 100644 --- a/lib/silcutil/silcfileutil.h +++ b/lib/silcutil/silcfileutil.h @@ -17,7 +17,7 @@ */ -/****h* silcutil/SILC File Util Interface +/****h* silcutil/File Util Interface * * DESCRIPTION * @@ -29,9 +29,74 @@ #ifndef SILCFILEUTIL_H #define SILCFILEUTIL_H +/****d* silcutil/SilcFileMode + * + * NAME + * + * typedef enum { ... } SilcFileMode; + * + * DESCRIPTION + * + * A file mode bits that specify the file's mode, type and protection + * in the SilcFileStat context. + * + * SOURCE + */ +typedef enum { + /* Type */ + SILC_FILE_IFDIR = 0x00000001, /* Entry is directory */ + SILC_FILE_IFCHR = 0x00000002, /* Entry is character device */ + SILC_FILE_IFBLK = 0x00000004, /* Entry is block device */ + SILC_FILE_IFREG = 0x00000008, /* Entry is regular file */ + SILC_FILE_IFIFO = 0x00000010, /* Entry is FIFO */ + SILC_FILE_IFLNK = 0x00000020, /* Entry is symbolic link */ + SILC_FILE_IFSOCK = 0x00000040, /* Entry is socket */ + + /* Protection */ + SILC_FILE_IRUSR = 0x00000080, /* Owner has read permission */ + SILC_FILE_IWUSR = 0x00000100, /* Owner has write permission */ + SILC_FILE_IXUSR = 0x00000200, /* Owner has execute permission */ + SILC_FILE_IRGRP = 0x00000400, /* Group has read permission */ + SILC_FILE_IWGRP = 0x00000800, /* Group has write permission */ + SILC_FILE_IXGRP = 0x00001000, /* Group has execute permission */ + SILC_FILE_IROTH = 0x00002000, /* Others have read permission */ + SILC_FILE_IWOTH = 0x00004000, /* Others have write permission */ + SILC_FILE_IXOTH = 0x00008000, /* Others have execute permission */ +} SilcFileMode; +/***/ + +/****s* silcutil/SilcFileStat + * + * NAME + * + * typedef struct SilcFileStatObject { ... } *SilcFileStat, + * SilcFileStatStruct; + * + * DESCRIPTION + * + * The file entry status information structure. The structure contains + * various information about a file. The structure is filled by calling + * the silc_file_stat or silc_file_fstat functions. + * + * SOURCE + */ +typedef struct SilcFileStatObject { + SilcTimeStruct last_access; /* Time of last access */ + SilcTimeStruct last_mod; /* Time of last modification */ + SilcTimeStruct last_change; /* Time of last status change */ + SilcUInt64 size; /* Entry size in bytes */ + SilcUInt32 uid; /* Owner ID of the entry */ + SilcUInt32 gid; /* Group owner ID of the entry */ + SilcUInt32 dev; /* Entry device number */ + SilcUInt32 rdev; /* Device number if special file */ + SilcUInt32 nlink; /* Number of hard links */ + SilcFileMode mode; /* Entry mode */ +} *SilcFileStat, SilcFileStatStruct; +/***/ + /* Prototypes */ -/****f* silcutil/SilcFileUtilAPI/silc_file_open +/****f* silcutil/silc_file_open * * SYNOPSIS * @@ -47,7 +112,7 @@ ***/ int silc_file_open(const char *filename, int flags); -/****f* silcutil/SilcFileUtilAPI/silc_file_open_mode +/****f* silcutil/silc_file_open_mode * * SYNOPSIS * @@ -63,7 +128,7 @@ int silc_file_open(const char *filename, int flags); ***/ int silc_file_open_mode(const char *filename, int flags, int mode); -/****f* silcutil/SilcFileUtilAPI/silc_file_read +/****f* silcutil/silc_file_read * * SYNOPSIS * @@ -77,7 +142,7 @@ int silc_file_open_mode(const char *filename, int flags, int mode); ***/ int silc_file_read(int fd, unsigned char *buf, SilcUInt32 buf_len); -/****f* silcutil/SilcFileUtilAPI/silc_file_write +/****f* silcutil/silc_file_write * * SYNOPSIS * @@ -91,7 +156,7 @@ int silc_file_read(int fd, unsigned char *buf, SilcUInt32 buf_len); ***/ int silc_file_write(int fd, const char *buffer, SilcUInt32 len); -/****f* silcutil/SilcFileUtilAPI/silc_file_close +/****f* silcutil/silc_file_close * * SYNOPSIS * @@ -105,7 +170,7 @@ int silc_file_write(int fd, const char *buffer, SilcUInt32 len); ***/ int silc_file_close(int fd); -/****f* silcutil/SilcFileUtilAPI/silc_file_set_nonblock +/****f* silcutil/silc_file_set_nonblock * * SYNOPSIS * @@ -118,7 +183,7 @@ int silc_file_close(int fd); ***/ int silc_file_set_nonblock(int fd); -/****f* silcutil/SilcFileUtilAPI/silc_file_readfile +/****f* silcutil/silc_file_readfile * * SYNOPSIS * @@ -133,7 +198,7 @@ int silc_file_set_nonblock(int fd); * NULL terminated. * * If the `return_len' pointer is not NULL, it's filled with the length of - * the file. + * the file. The returned length does not include the terminator. * * If `stack' is non-NULL the returned buffer is allocated from `stack'. * The allocation consumes `stack' so caller should push the stack before @@ -143,7 +208,7 @@ int silc_file_set_nonblock(int fd); char *silc_file_readfile(const char *filename, SilcUInt32 *return_len, SilcStack stack); -/****f* silcutil/SilcFileUtilAPI/silc_file_writefile +/****f* silcutil/silc_file_writefile * * SYNOPSIS * @@ -159,7 +224,7 @@ char *silc_file_readfile(const char *filename, SilcUInt32 *return_len, int silc_file_writefile(const char *filename, const char *buffer, SilcUInt32 len); -/****f* silcutil/SilcFileUtilAPI/silc_file_writefile_mode +/****f* silcutil/silc_file_writefile_mode * * SYNOPSIS * @@ -175,7 +240,7 @@ int silc_file_writefile(const char *filename, const char *buffer, int silc_file_writefile_mode(const char *filename, const char *buffer, SilcUInt32 len, int mode); -/****f* silcutil/SilcFileUtilAPI/silc_file_size +/****f* silcutil/silc_file_size * * SYNOPSIS * @@ -183,9 +248,63 @@ int silc_file_writefile_mode(const char *filename, const char *buffer, * * DESCRIPTION * - * Returns the size of `filename'. Returns 0 on error. + * Returns the size of `filename'. Returns 0 on error and sets silc_errno. + * If silc_errno is not set the file size is 0 bytes if this returns 0. * ***/ SilcUInt64 silc_file_size(const char *filename); +/****f* silcutil/silc_file_fsize + * + * SYNOPSIS + * + * SilcUInt64 silc_file_fsize(int fd); + * + * DESCRIPTION + * + * Returns the size of the file indicated by open file descriptor `fd'. + * Returns 0 on error and sets silc_errno. If silc_errno is not set the + * file size is 0 bytes if this returns 0. + * + ***/ +SilcUInt64 silc_file_fsize(int fd); + +/****f* silcutil/silc_file_stat + * + * SYNOPSIS + * + * SilcBool silc_file_stat(const char *filename, SilcBool follow_symlinks, + * SilcFileStat return_stat); + * + * DESCRIPTION + * + * Returns status information of a file named `filename'. The status + * information is returned to `return_stat' structure. If the + * `follow_symlinks' is TRUE this will return the status of the file the + * symlink referts to. If it is FALSE, returns the status of the link + * itself. + * + * Returns FALSE on error and sets the silc_errno. Returns TRUE otherwise. + * + ***/ +SilcBool silc_file_stat(const char *filename, SilcBool follow_symlinks, + SilcFileStat return_stat); + +/****f* silcutil/silc_file_fstat + * + * SYNOPSIS + * + * SilcBool silc_file_fstat(int fd, SilcFileStat return_stat); + * + * DESCRIPTION + * + * Returns status information of a opened file indicated by the file + * descriptor `fd'. The status information is returned to the + * `return_stat' structure. + * + * Returns FALSE on error and sets the silc_errno. Returns TRUE otherwise. + * + ***/ +SilcBool silc_file_fstat(int fd, SilcFileStat return_stat); + #endif /* !SILCFILEUTIL_H */