10 #include "lixp_util.h"
13 /* ------------------------------------------------------------------------
16 int lixp_pusherror(lua_State
*L
, const char *info
)
20 lua_pushstring(L
, strerror(errno
));
21 lua_pushnumber(L
, errno
);
24 lua_pushfstring(L
, "%s: %s", info
, strerror(errno
));
25 lua_pushnumber(L
, errno
);
28 lua_pushfstring(L
, "%s", info
);
33 /* ------------------------------------------------------------------------
34 * write a buffer to an IXP file
36 int lixp_write_data (IxpCFid
*fid
, const char *data
, size_t data_len
)
43 int rc
= ixp_write(fid
, (char*)data
+ ofs
, left
);
57 /* ------------------------------------------------------------------------
58 * dump IXP status structure to lua table
60 static void setrwx(long m
, char *s
)
62 static char *modes
[] = {
67 strncpy(s
, modes
[m
], 3);
70 static void build_modestr(char *buf
, const struct IxpStat
*stat
)
73 if(stat
->mode
& P9_DMDIR
)
76 setrwx((stat
->mode
>> 6) & 7, &buf
[2]);
77 setrwx((stat
->mode
>> 3) & 7, &buf
[5]);
78 setrwx((stat
->mode
>> 0) & 7, &buf
[8]);
82 static void build_timestr(char *buf
, const struct IxpStat
*stat
)
84 ctime_r((time_t*)&stat
->mtime
, buf
);
85 buf
[strlen(buf
) - 1] = '\0';
89 #define setfield(type,name,value) \
90 lua_pushstring (L, name); \
91 lua_push##type (L, value); \
93 int lixp_pushstat (lua_State
*L
, const struct IxpStat
*stat
)
98 setfield(number
, "type", stat
->type
);
99 setfield(number
, "dev", stat
->dev
);
100 //setfield(Qid, "qid", stat->qid); // TODO: what is this?
101 setfield(number
, "mode", stat
->mode
);
102 setfield(number
, "atime", stat
->atime
);
103 setfield(number
, "mtime", stat
->mtime
);
104 setfield(number
, "length", stat
->length
);
105 setfield(string
, "name", stat
->name
);
106 setfield(string
, "uid", stat
->uid
);
107 setfield(string
, "gid", stat
->gid
);
108 setfield(string
, "muid", stat
->muid
);
110 build_modestr(buf
, stat
);
111 setfield(string
, "modestr", buf
);
113 build_timestr(buf
, stat
);
114 setfield(string
, "timestr", buf
);