posix.c (692B)
1 #include <u.h> 2 #include <libc.h> 3 #include <bio.h> 4 #include <fcntl.h> 5 #include "last.h" 6 7 void 8 noblock(int fd) { 9 int old; 10 11 old = fcntl(fd, F_GETFL, 0); 12 if(fcntl(fd, F_SETFL, old | O_NONBLOCK) == -1) 13 sysfatal("Can't set O_NONBLOCK for %d: %r", fd); 14 } 15 16 void 17 label(const char *fmt, ...) { 18 static char *status; 19 char *home; 20 VFmt v; 21 22 if(!isatty(1)) 23 return; 24 25 v.fmt = (char*)fmt; 26 va_start(v.args, fmt); 27 print("\033];LastFM: %V\007", &v); 28 va_end(v.args); 29 30 /* return; */ 31 32 if(status == nil) { 33 home = getenv("HOME"); 34 status = smprint("%s/lib/status", home); 35 free(home); 36 } 37 /* Why does this block? */ 38 va_start(v.args, fmt); 39 printfile(status, "LastFM: %V", &v); 40 va_end(v.args); 41 } 42