diff options
Diffstat (limited to 'jacs/dat.c')
-rw-r--r-- | jacs/dat.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/jacs/dat.c b/jacs/dat.c new file mode 100644 index 0000000..094f27f --- /dev/null +++ b/jacs/dat.c @@ -0,0 +1,89 @@ +/* + * Copy me if you can. + * by 20h + */ + +#include <u.h> +#include <libc.h> +#include "dat.h" + +void * +reallocj(void *p, int s, short d) +{ + p = realloc(p, s); + if(p == nil) + sysfatal("realloc: %r"); + + if(d != 0) + memset(p, 0, s); + + return (void *)p; +} + +char * +setwindowlbl(char *w) +{ + int s; + + s = open("/dev/label", OWRITE); + if(s < 0) + return nil; + + write(s, w, strlen(w)); + + close(s); + return w; +} + +char * +getwindowlbl(void) +{ + int s; + char *ret; + short i; + + s = open("/dev/label", OREAD); + if(s < 0) + return nil; + + i = 0; + ret = malloc(0); + while(realloc(ret, ++i) != nil && read(s, &ret[i - 1], 1) > 0 && + i < 513); + + ret[i - 1] = '\0'; + + close(s); + return ret; +} + +char * +mktmstmp(char bord, char bord_e) +{ + Tm *tim; + char *ret; + + ret = reallocj(nil, 32, 2); + tim = localtime(time(0)); + snprint(ret, 31, "%c%.2d:%.2d%c ", bord, tim->hour, tim->min, bord_e); + + return ret; +} + +char * +printjid(char *user, char *serv, char *reso) +{ + char *ret; + int i; + + if(user == nil || serv == nil) + return nil; + + i = strlen(user) + strlen(serv) + 3 + ((reso != nil) ? strlen(reso) : 0); + + ret = reallocj(nil, i, 2); + snprint(ret, i, "%s@%s%s%s", user, serv, (reso != nil) ? "/" : "\0", + ((reso != nil) ? reso : "")); + + return ret; +} |