Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cal.h>
- #include <stdio.h>
- #include <string.h>
- main (int argc, char *argv[])
- {
- int index = 1;
- struct cal *cal_s;
- char version_software_current[512];
- char *version_software_string;
- void *tmp = NULL;
- unsigned long len;
- if (cal_init (&cal_s) < 0)
- {
- printf ("Failed to init CAL.\n");
- return 1;
- }
- if (cal_read_block (cal_s, "sw-release-ver", &tmp, &len, CAL_FLAG_USER) < 0)
- {
- cal_finish (cal_s);
- printf ("Failed to SW Release version from CAL.\n");
- return 2;
- }
- if (len < 1 && !tmp)
- {
- cal_finish (cal_s);
- printf ("Failed to read SW Release version from CAL.\n");
- return 3;
- }
- version_software_string = (char *)tmp;
- strcpy (version_software_current, (char *)version_software_string);
- while (index < argc)
- {
- if (!strcmp (argv[index], "-w"))
- {
- ++index;
- if (index < argc)
- {
- version_software_string = (char *)realloc (version_software_string, (strlen (argv[index]) + 1));
- version_software_string = strcpy (version_software_string, argv[index]);
- printf ("\"%s\" was written.\n", version_software_string);
- }
- }
- ++index;
- }
- if (strcmp (version_software_string, version_software_current))
- {
- if (!strcmp (version_software_string, ""))
- {
- if (cal_write_block (cal_s, "sw-release-ver", version_software_string, sizeof (version_software_string), CAL_FLAG_USER) < 0)
- {
- cal_finish (cal_s);
- printf ("Failed to write to the software version area of CAL.\n");
- return 4;
- }
- }
- else
- {
- if (cal_write_block (cal_s, "sw-release-ver", version_software_string, strlen (version_software_string) + 1, CAL_FLAG_USER) < 0)
- {
- cal_finish (cal_s);
- printf ("Failed to write to the software version area of CAL.\n");
- return 4;
- }
- }
- }
- cal_finish (cal_s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement