Fossil SCM
Better error checking in the mkversion utility program used during the build process.
Commit
8b9ce19e38d5b7dab3fe3d15a327e4c4f9ba91f36a3b9de56b6542de1a46c218
Parent
5698492fbb379b7…
1 file changed
+16
-3
+16
-3
| --- src/mkversion.c | ||
| +++ src/mkversion.c | ||
| @@ -8,10 +8,19 @@ | ||
| 8 | 8 | ** Note that the manifest.uuid and manifest files are generated by Fossil. |
| 9 | 9 | */ |
| 10 | 10 | #include <stdio.h> |
| 11 | 11 | #include <string.h> |
| 12 | 12 | #include <stdlib.h> |
| 13 | + | |
| 14 | +static FILE *open_for_reading(const char *zFilename){ | |
| 15 | + FILE *f = fopen(zFilename, "r"); | |
| 16 | + if( f==0 ){ | |
| 17 | + fprintf(stderr, "cannot open \"%s\" for reading\n", zFilename); | |
| 18 | + exit(1); | |
| 19 | + } | |
| 20 | + return f; | |
| 21 | +} | |
| 13 | 22 | |
| 14 | 23 | int main(int argc, char *argv[]){ |
| 15 | 24 | FILE *m,*u,*v; |
| 16 | 25 | char *z; |
| 17 | 26 | #if defined(__DMC__) /* e.g. 0x857 */ |
| @@ -19,31 +28,35 @@ | ||
| 19 | 28 | #endif |
| 20 | 29 | int j = 0, x = 0, d = 0; |
| 21 | 30 | int vn[3]; |
| 22 | 31 | char b[1000]; |
| 23 | 32 | char vx[1000]; |
| 33 | + if( argc!=4 ){ | |
| 34 | + fprintf(stderr, "Usage: %s manifest.uuid manifest VERSION\n", argv[0]); | |
| 35 | + exit(1); | |
| 36 | + } | |
| 24 | 37 | memset(b,0,sizeof(b)); |
| 25 | 38 | memset(vx,0,sizeof(vx)); |
| 26 | - u = fopen(argv[1],"r"); | |
| 39 | + u = open_for_reading(argv[1]); | |
| 27 | 40 | if( fgets(b, sizeof(b)-1,u)==0 ){ |
| 28 | 41 | fprintf(stderr, "malformed manifest.uuid file: %s\n", argv[1]); |
| 29 | 42 | exit(1); |
| 30 | 43 | } |
| 31 | 44 | fclose(u); |
| 32 | 45 | for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){} |
| 33 | 46 | *z = 0; |
| 34 | 47 | printf("#define MANIFEST_UUID \"%s\"\n",b); |
| 35 | 48 | printf("#define MANIFEST_VERSION \"[%10.10s]\"\n",b); |
| 36 | - m = fopen(argv[2],"r"); | |
| 49 | + m = open_for_reading(argv[2]); | |
| 37 | 50 | while(b == fgets(b, sizeof(b)-1,m)){ |
| 38 | 51 | if(0 == strncmp("D ",b,2)){ |
| 39 | 52 | printf("#define MANIFEST_DATE \"%.10s %.8s\"\n",b+2,b+13); |
| 40 | 53 | printf("#define MANIFEST_YEAR \"%.4s\"\n",b+2); |
| 41 | 54 | } |
| 42 | 55 | } |
| 43 | 56 | fclose(m); |
| 44 | - v = fopen(argv[3],"r"); | |
| 57 | + v = open_for_reading(argv[3]); | |
| 45 | 58 | if( fgets(b, sizeof(b)-1,v)==0 ){ |
| 46 | 59 | fprintf(stderr, "malformed VERSION file: %s\n", argv[3]); |
| 47 | 60 | exit(1); |
| 48 | 61 | } |
| 49 | 62 | fclose(v); |
| 50 | 63 |
| --- src/mkversion.c | |
| +++ src/mkversion.c | |
| @@ -8,10 +8,19 @@ | |
| 8 | ** Note that the manifest.uuid and manifest files are generated by Fossil. |
| 9 | */ |
| 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | #include <stdlib.h> |
| 13 | |
| 14 | int main(int argc, char *argv[]){ |
| 15 | FILE *m,*u,*v; |
| 16 | char *z; |
| 17 | #if defined(__DMC__) /* e.g. 0x857 */ |
| @@ -19,31 +28,35 @@ | |
| 19 | #endif |
| 20 | int j = 0, x = 0, d = 0; |
| 21 | int vn[3]; |
| 22 | char b[1000]; |
| 23 | char vx[1000]; |
| 24 | memset(b,0,sizeof(b)); |
| 25 | memset(vx,0,sizeof(vx)); |
| 26 | u = fopen(argv[1],"r"); |
| 27 | if( fgets(b, sizeof(b)-1,u)==0 ){ |
| 28 | fprintf(stderr, "malformed manifest.uuid file: %s\n", argv[1]); |
| 29 | exit(1); |
| 30 | } |
| 31 | fclose(u); |
| 32 | for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){} |
| 33 | *z = 0; |
| 34 | printf("#define MANIFEST_UUID \"%s\"\n",b); |
| 35 | printf("#define MANIFEST_VERSION \"[%10.10s]\"\n",b); |
| 36 | m = fopen(argv[2],"r"); |
| 37 | while(b == fgets(b, sizeof(b)-1,m)){ |
| 38 | if(0 == strncmp("D ",b,2)){ |
| 39 | printf("#define MANIFEST_DATE \"%.10s %.8s\"\n",b+2,b+13); |
| 40 | printf("#define MANIFEST_YEAR \"%.4s\"\n",b+2); |
| 41 | } |
| 42 | } |
| 43 | fclose(m); |
| 44 | v = fopen(argv[3],"r"); |
| 45 | if( fgets(b, sizeof(b)-1,v)==0 ){ |
| 46 | fprintf(stderr, "malformed VERSION file: %s\n", argv[3]); |
| 47 | exit(1); |
| 48 | } |
| 49 | fclose(v); |
| 50 |
| --- src/mkversion.c | |
| +++ src/mkversion.c | |
| @@ -8,10 +8,19 @@ | |
| 8 | ** Note that the manifest.uuid and manifest files are generated by Fossil. |
| 9 | */ |
| 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | #include <stdlib.h> |
| 13 | |
| 14 | static FILE *open_for_reading(const char *zFilename){ |
| 15 | FILE *f = fopen(zFilename, "r"); |
| 16 | if( f==0 ){ |
| 17 | fprintf(stderr, "cannot open \"%s\" for reading\n", zFilename); |
| 18 | exit(1); |
| 19 | } |
| 20 | return f; |
| 21 | } |
| 22 | |
| 23 | int main(int argc, char *argv[]){ |
| 24 | FILE *m,*u,*v; |
| 25 | char *z; |
| 26 | #if defined(__DMC__) /* e.g. 0x857 */ |
| @@ -19,31 +28,35 @@ | |
| 28 | #endif |
| 29 | int j = 0, x = 0, d = 0; |
| 30 | int vn[3]; |
| 31 | char b[1000]; |
| 32 | char vx[1000]; |
| 33 | if( argc!=4 ){ |
| 34 | fprintf(stderr, "Usage: %s manifest.uuid manifest VERSION\n", argv[0]); |
| 35 | exit(1); |
| 36 | } |
| 37 | memset(b,0,sizeof(b)); |
| 38 | memset(vx,0,sizeof(vx)); |
| 39 | u = open_for_reading(argv[1]); |
| 40 | if( fgets(b, sizeof(b)-1,u)==0 ){ |
| 41 | fprintf(stderr, "malformed manifest.uuid file: %s\n", argv[1]); |
| 42 | exit(1); |
| 43 | } |
| 44 | fclose(u); |
| 45 | for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){} |
| 46 | *z = 0; |
| 47 | printf("#define MANIFEST_UUID \"%s\"\n",b); |
| 48 | printf("#define MANIFEST_VERSION \"[%10.10s]\"\n",b); |
| 49 | m = open_for_reading(argv[2]); |
| 50 | while(b == fgets(b, sizeof(b)-1,m)){ |
| 51 | if(0 == strncmp("D ",b,2)){ |
| 52 | printf("#define MANIFEST_DATE \"%.10s %.8s\"\n",b+2,b+13); |
| 53 | printf("#define MANIFEST_YEAR \"%.4s\"\n",b+2); |
| 54 | } |
| 55 | } |
| 56 | fclose(m); |
| 57 | v = open_for_reading(argv[3]); |
| 58 | if( fgets(b, sizeof(b)-1,v)==0 ){ |
| 59 | fprintf(stderr, "malformed VERSION file: %s\n", argv[3]); |
| 60 | exit(1); |
| 61 | } |
| 62 | fclose(v); |
| 63 |