~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
cvs/emstar/fusd/examples/binary-read.c


  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <unistd.h>
  4 #include <sys/types.h>
  5 #include <sys/stat.h>
  6 #include <fcntl.h>
  7 #include <sys/ioctl.h>
  8 #include <string.h>
  9 
 10 #include "fusd/fusd.h"
 11 
 12 
 13 #define MAXLEN 10000
 14 
 15 int main(int argc, char *argv[])
 16 {
 17   int fd, retval, len = 0, num_status, i;
 18   char *buf = malloc(MAXLEN);
 19   char tmp[1024];
 20   fusd_status_t *stat;
 21 
 22   /* open a channel to fusd */
 23   if ((fd = open(FUSD_STATUS_DEVNAME, O_RDONLY)) < 0) {
 24     printf("can't open FUSD status (%s): %m", FUSD_STATUS_DEVNAME);
 25     exit(1);
 26   }
 27 
 28   /* Tell it we want to read status in binary */
 29   if (ioctl(fd, FUSD_STATUS_USE_BINARY) < 0) {
 30     printf("trying to switch FUSD status into binary mode: %m");
 31     exit(1);
 32   }
 33 
 34   while ((retval = read(fd, tmp, sizeof(tmp))) > 0) {
 35     memcpy(buf+len, tmp, retval);
 36     len += retval;
 37     if (len >= MAXLEN-sizeof(tmp)) {
 38       printf("buffer too small\n");
 39       exit(1);
 40     }
 41   }
 42 
 43   stat = (fusd_status_t *) buf;
 44   num_status = len / sizeof(fusd_status_t);
 45 
 46   printf("Zombie?   Device\n");
 47   printf("-------   ------\n");
 48 
 49   for (i = 0; i < num_status; i++)
 50     printf("%5d     %s\n", stat[i].zombie, stat[i].name);
 51 
 52   return 0;
 53 }
 54 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.