last

git clone git://oldgit.suckless.org/last/
Log | Files | Refs

util.c (538B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <bio.h>
      4 #include "last.h"
      5 
      6 static void
      7 eat(char **s, int (*p)(int), int r) {
      8 	char *q;
      9 
     10 	for(q=*s; *q && p(*q) == r; q++)
     11 		;
     12 	*s = q;
     13 }
     14 
     15 char*
     16 tok(char **s) {
     17 	char *p;
     18 
     19 	eat(s, isspace, 1);
     20 	p = *s;
     21 	eat(s, isspace, 0);
     22 	if(**s)
     23 		*(*s)++ = '\0';
     24 	eat(s, isspace, 1);
     25 	return p;
     26 }
     27 
     28 void
     29 printfile(char *file, const char *fmt, ...) {
     30 	va_list ap;
     31 	int fd;
     32 
     33 	fd = open(file, OWRITE|ONONBLOCK);
     34 	if(fd < 0)
     35 		return;
     36 
     37 	va_start(ap, fmt);
     38 	vfprint(fd, (char*)fmt, ap);
     39 	va_end(ap);
     40 
     41 	close(fd);
     42 }
     43