libnjb: delfile.c

- Main Page
- Modules
- Data Structures
- Files
- Directories
- Examples

# delfile.c

    00001 #include "common.h"
    00002
    00003 void usage (void);
    00004
    00005 int main (int argc, char **argv)
    00006 {
    00007   njb_t njbs[NJB_MAX_DEVICES], *njb;
    00008   u_int32_t id;
    00009   int n, debug, syntax, opt;
    00010   extern int optind;
    00011   extern char *optarg;
    00012   char *endptr;
    00013
    00014   debug = 0;
    00015   syntax = 0;
    00016
    00017   while ( (opt = getopt(argc, argv, "D:")) != -1 ) {
    00018     switch (opt) {
    00019     case 'D':
    00020       debug= atoi(optarg);
    00021       break;
    00022     default:
    00023       usage();
    00024     }
    00025   }
    00026   argc -= optind;
    00027   argv += optind;
    00028
    00029   if ( argc != 1 ) usage();
    00030
    00031   id = strtoul(argv[0], &endptr, 10);
    00032   if ( endptr[0] != '\0' ) {
    00033     fprintf(stderr, "invalid file id %s\n", argv[0]);
    00034     return 1;
    00035   }
    00036
    00037   if ( debug ) NJB_Set_Debug(debug);
    00038
    00039   if ( NJB_Discover(njbs, 0, &n) == -1 ) {
    00040     fprintf(stderr, "could not probe for NJB devices\n");
    00041     return 1;
    00042   }
    00043   if ( n == 0 ) {
    00044     fprintf(stderr, "no NJB devices found\n");
    00045     return 0;
    00046   }
    00047
    00048   njb = njbs;
    00049
    00050   if ( NJB_Open(njb) == -1 ) {
    00051     NJB_Error_Dump(njb, stderr);
    00052     return 1;
    00053   }
    00054
    00055   if ( NJB_Capture(njb) == -1 ) {
    00056     NJB_Error_Dump(njb, stderr);
    00057     return 1;
    00058   }
    00059
    00060   if ( NJB_Delete_Datafile(njb, id) == -1 ) {
    00061     NJB_Error_Dump(njb, stderr);
    00062   }
    00063
    00064   NJB_Release(njb);
    00065
    00066   NJB_Close(njb);
    00067
    00068   return 0;
    00069 }
    00070
    00071 void usage (void)
    00072 {
    00073   fprintf(stderr, "usage: delfile [ -D debuglvl ] <fileid>\n");
    00074   exit(1);
    00075 }