Advertisement
Guest User

Untitled

a guest
Jul 10th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. #include <cal.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. main (int argc, char *argv[])
  6. {
  7.     int index = 1;
  8.     struct cal *cal_s;
  9.     char version_software_current[512];
  10.     char *version_software_string;
  11.     void *tmp = NULL;
  12.     unsigned long len;
  13.     if (cal_init (&cal_s) < 0)
  14.     {
  15.         printf ("Failed to init CAL.\n");
  16.         return 1;
  17.     }
  18.     if (cal_read_block (cal_s, "sw-release-ver", &tmp, &len, CAL_FLAG_USER) < 0)
  19.     {
  20.         cal_finish (cal_s);
  21.         printf ("Failed to SW Release version from CAL.\n");
  22.         return 2;
  23.     }
  24.     if (len < 1 && !tmp)
  25.     {
  26.         cal_finish (cal_s);
  27.         printf ("Failed to read SW Release version from CAL.\n");
  28.         return 3;
  29.     }
  30.     version_software_string = (char *)tmp;
  31.     strcpy (version_software_current, (char *)version_software_string);
  32.     while (index < argc)
  33.     {
  34.             if (!strcmp (argv[index], "-w"))
  35.         {
  36.             ++index;
  37.             if (index < argc)
  38.             {
  39.                 version_software_string = (char *)realloc (version_software_string, (strlen (argv[index]) + 1));
  40.                 version_software_string = strcpy (version_software_string, argv[index]);
  41.                 printf ("\"%s\" was written.\n", version_software_string);
  42.             }
  43.         }
  44.         ++index;
  45.     }
  46.     if (strcmp (version_software_string, version_software_current))
  47.     {
  48.         if (!strcmp (version_software_string, ""))
  49.         {
  50.             if (cal_write_block (cal_s, "sw-release-ver", version_software_string, sizeof (version_software_string), CAL_FLAG_USER) < 0)
  51.             {
  52.                 cal_finish (cal_s);
  53.                 printf ("Failed to write to the software version area of CAL.\n");
  54.                 return 4;
  55.             }
  56.         }
  57.         else
  58.         {
  59.             if (cal_write_block (cal_s, "sw-release-ver", version_software_string, strlen (version_software_string) + 1, CAL_FLAG_USER) < 0)
  60.             {
  61.                 cal_finish (cal_s);
  62.                 printf ("Failed to write to the software version area of CAL.\n");
  63.                 return 4;
  64.             }
  65.         }
  66.     }
  67.     cal_finish (cal_s);
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement