libk  Diff

Differences From Artifact [7ec69a3e9e]:

To Artifact [a786627a56]:


     1      1   #ifndef KIfile
     2      2   #define KIfile
            3  +#include <k/type.h>
            4  +#include <k/io.h>
            5  +
            6  +#ifdef __cplusplus
            7  +extern "C" {
            8  +#endif
            9  +
           10  +typedef enum kfcond {
           11  +	kfcond_ok = 0,
           12  +	kfcond_fail = 1,
           13  +		// an unspecified error occurred
           14  +	kfcond_bad_domain,
           15  +		// the values passed to the function are not within
           16  +		// that function's domain and are invalid
           17  +	kfcond_overstep,
           18  +		// kfstep() was only able to move part of the
           19  +		// distance requested
           20  +	kfcond_bad_index,
           21  +		// the requested index is past the end of the file
           22  +	kfcond_notfound,
           23  +		// the specified object could not be found
           24  +	kfcond_unauth,
           25  +		// you do not have permission to open this object
           26  +	kfcond_mem,
           27  +		// there is not enough memory to complete the
           28  +		// requested operation
           29  +} kfcond;
           30  +
           31  +typedef enum kfile_kind {
           32  +	kfile_closed,
           33  +		// the file object does not refer to an open file
           34  +	kfile_open,
           35  +		// the file object refers to an open file
           36  +} kfile_kind;
           37  +
           38  +enum kfopen {
           39  +	/* file open modes */
           40  +	kf_read   = 1 << 9,  kf_write = 1 << 10,
           41  +	kf_ascii  = 1 << 11, kf_new   = 1 << 12,
           42  +	kf_create = 1 << 13, kf_load  = 1 << 14,
           43  +	kf_top    = 1 << 15, kf_end   = 1 << 16,
           44  +	kf_wipe   = 1 << 17, kf_map   = 1 << 18,
           45  +
           46  +	/* file permission flags */
           47  +	kf_ur = 4 << 6, kf_uw = 2 << 6, kf_ux = 1 << 6,
           48  +	kf_gr = 4 << 3, kf_gw = 2 << 3, kf_gx = 1 << 3, 
           49  +	kf_or = 4 << 0, kf_ow = 2 << 0, kf_ox = 1 << 0,
           50  +}
           51  +
           52  +typedef struct kfile {
           53  +	enum kfile_kind kind;
           54  +	enum kfopen mode;
           55  +	kiochan chan;
           56  +	u8* content;
           57  +} kfile;
           58  +
           59  +enum kfset_mode {
           60  +	kfset_none, // do not move
           61  +	kfset_top, // move to x bytes from the start of the file
           62  +	kfset_end, // move to x bytes from the end of the file
           63  +}
           64  +
           65  +enum kfplace { 
           66  +	kfplace_none,
           67  +	kfplace_conf,
           68  +	kfplace_home,
           69  +	kfplace_desk,
           70  +	kfplace_dl,
           71  +	kfplace_img,
           72  +	kfplace_vid,
           73  +	kfplace_msc,
           74  +	kfplace_doc,
           75  +	kfplace_dat,
           76  +	kfplace_share,
           77  +	kfplace_share_global,
           78  +	kfplace_cache,
           79  +}
           80  +
           81  +kfile kfplace(enum kfplace location, const char* file, enum kfopen mode);
           82  +kfile kfopen (const char* file, enum kfopen mode);
           83  +kfile kfopens(const ksraw file, enum kfopen mode);
           84  +
           85  +kfcond kfset (struct kfile file, enum kfset_mode mode, sz position);
           86  +kfcond kfstep(struct kfile file, offset position);
           87  +
           88  +kfcond kfshred(struct kfile file, sz count);
           89  +
           90  +#ifdef __cplusplus
           91  +}
           92  +#endif
     3     93   
     4     94   #endif