Crosswind

print_id3

Jun 12th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.80 KB | None | 0 0
  1. struct id3tag {
  2.     char *title[31];
  3.     char *interpret[31];
  4.     char *album[31];
  5.     char *year[5];
  6.     char *comment[31];
  7.     int *genre[1];
  8. } tag;
  9.  
  10. int print_id3(char *filename) {
  11.     FILE *file;
  12.     char tag_mark[3] = {"TAG"};
  13.     int bool, i;
  14.  
  15.     file = fopen(filename, "r");
  16.  
  17.     if (file == NULL) {
  18.         return 1;
  19.     }
  20.     // Dateizeiger auf die Position 128 bytes vor Dateiende setzen
  21.     int status_fseek = fseek(file, -128, SEEK_END);
  22.     if (status_fseek != 0) {
  23.         (void) fclose(file);
  24.         return 3;
  25.     }
  26.     // die ersten 3 Byte auslesen
  27.     char tag_read[3];
  28.     (void) fread((void *) &tag_read, 1, 3, file);
  29.  
  30.     if (ferror(file) != 0) {
  31.         (void) fclose(file);
  32.         return 3;
  33.     }
  34.     // wenn die ersten drei Byte TAG heißen, dann ist ein id3tag geschrieben
  35.     for (i = 0; i < 3; i++) {
  36.         bool = (tag_mark[i] == tag_read[i]) ? 1 : 0;
  37.     }
  38.  
  39.     if (bool == 1) {
  40.         (void) fread((void *) &tag.title, 1, sizeof(((struct id3tag *) 0)->title) / 8 - 1, file);
  41.         tag.title[30] = "\0";
  42.  
  43.         (void) fread((void *) &tag.interpret, 1, sizeof(((struct id3tag *) 0)->interpret) / 8 - 1, file);
  44.         tag.interpret[30] = "\0";
  45.  
  46.         (void) fread((void *) &tag.album, 1, sizeof(((struct id3tag *) 0)->album) / 8 - 1, file);
  47.         tag.album[30] = "\0";
  48.  
  49.         (void) fread((void *) &tag.comment, 1, sizeof(((struct id3tag *) 0)->comment) / 8 - 1, file);
  50.         tag.comment[30] = "\0";
  51.  
  52.         (void) fread((void *) &tag.year, 1, sizeof(((struct id3tag *) 0)->year) / 8 - 1, file);
  53.         tag.year[4] = "\0";
  54.  
  55.         (void) fread((void *) &tag.genre, 1, sizeof(((struct id3tag *) 0)->genre) / 8 - 1, file);
  56.  
  57.         (void) fclose(file);
  58.         return 0;
  59.     } else {
  60.         (void) fclose(file);
  61.         return 2;
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment