File: io_debugstring.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (63 lines) | stat: -rw-r--r-- 1,984 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "io_internal.h"
#include <iarray.h>
#include <time.h>
#include "fmt.h"
#include <sys/time.h>

unsigned int io_debugstring(int64 s,char* buf,unsigned int bufsize) {
  struct timeval tv;
  unsigned int i;
  io_entry* e;
  gettimeofday(&tv,NULL);
  e=iarray_get(&io_fds,s);
  if (!e) return 0;
  if (bufsize<100) return 0;
  i=fmt_str(buf,"first_readable ");
  i+=fmt_long(buf+i,first_readable);
  i+=fmt_str(buf+i,", first_writeable ");
  i+=fmt_long(buf+i,first_writeable);
#ifdef HAVE_SIGIO
  i+=fmt_str(buf+i,", alt_firstread ");
  i+=fmt_long(buf+i,alt_firstread);
  i+=fmt_str(buf+i,", alt_firstwrite ");
  i+=fmt_long(buf+i,alt_firstwrite);
#endif
  i+=fmt_str(buf+i,"\n");

  i+=fmt_str(buf+i,"fd # ");
  i+=fmt_ulong(buf+i,s);
  i+=fmt_str(buf+i,": ");
  if (bufsize-i<100) return 0;
  i+=fmt_str(buf+i,"timeout ");
  i+=fmt_long(buf+i,e->timeout.sec.x-4611686018427387914ULL-tv.tv_sec);
  i+=fmt_str(buf+i,".");
  i+=fmt_ulong(buf+i,e->timeout.nano);
  i+=fmt_str(buf+i," ");
  if (bufsize-i<100) return 0;
  if (e->wantread) i+=fmt_str(buf+i,"wr ");
  if (e->wantwrite) i+=fmt_str(buf+i,"ww ");
  if (e->canread) i+=fmt_str(buf+i,"cr ");
  if (e->canwrite) i+=fmt_str(buf+i,"cw ");
  if (e->nonblock) i+=fmt_str(buf+i,"nb ");
  if (!e->inuse) i+=fmt_str(buf+i,"!inuse ");
  if (e->kernelwantread) i+=fmt_str(buf+i,"kwr ");
  if (e->kernelwantwrite) i+=fmt_str(buf+i,"kww ");
  if (e->epolladded) i+=fmt_str(buf+i,"ea ");
  if (e->mmapped) {
    i+=fmt_str(buf+i,"mmap(");
    i+=fmt_xlong(buf+i,(unsigned long)e->mmapped);
    i+=fmt_str(buf+i,",");
    i+=fmt_xlong(buf+i,(unsigned long)e->maplen);
    i+=fmt_str(buf+i,"@");
    i+=fmt_xlonglong(buf+i,(unsigned long)e->mapofs);
  }
  if (bufsize-i<100) return 0;
  i+=fmt_str(buf+i,"next_read ");
  i+=fmt_long(buf+i,e->next_read);
  i+=fmt_str(buf+i," next_write ");
  i+=fmt_long(buf+i,e->next_write);
  i+=fmt_str(buf+i," cookie ");
  i+=fmt_xlonglong(buf+i,(unsigned long)e->cookie);
  buf[i]=0;
  return i;
}