libmtp: trexist.c

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

# trexist.c

    00001 #include "common.h"
    00002
    00003 static void usage (void)
    00004 {
    00005   fprintf(stderr, "trexist <trackid>\n");
    00006 }
    00007
    00008 int main (int argc, char **argv)
    00009 {
    00010   LIBMTP_mtpdevice_t *device;
    00011   u_int32_t id;
    00012   char *endptr;
    00013
    00014   // We need track ID
    00015   if ( argc != 2 ) {
    00016     usage();
    00017     return 1;
    00018   }
    00019
    00020   // Sanity check song ID
    00021   id = strtoul(argv[1], &endptr, 10);
    00022   if ( *endptr != 0 ) {
    00023     fprintf(stderr, "illegal value %s\n", argv[1]);
    00024     return 1;
    00025   } else if ( ! id ) {
    00026     fprintf(stderr, "bad song id %u\n", id);
    00027     return 1;
    00028   }
    00029
    00030   LIBMTP_Init();
    00031   device = LIBMTP_Get_First_Device();
    00032   if (device == NULL) {
    00033     printf("No devices. Connect/replug device and try again.\n");
    00034     exit (0);
    00035   }
    00036
    00037   printf("%s\n", LIBMTP_Track_Exists(device, id) ? "Yes" : "No");
    00038
    00039   LIBMTP_Release_Device(device);
    00040   printf("OK.\n");
    00041   exit (0);
    00042 }
    00043