File: check_read_write_352823.patch

package info (click to toggle)
nrg2iso 0.4-4.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116 kB
  • sloc: ansic: 189; makefile: 16
file content (118 lines) | stat: -rw-r--r-- 2,730 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Patch Author: Mikael Berthe <mikael.berthe@lilotux.net>

This patch solves bug #352823. It has been added in version 0.4-2 of nrg2iso on
the 8th April 2008.


Patch packaged with quilt by Xavier Luthi <xavier@caroxav.be>
Index: nrg2iso-0.4/nrg2iso.c
===================================================================
--- nrg2iso-0.4.orig/nrg2iso.c	2008-04-07 12:38:39.000000000 +0200
+++ nrg2iso-0.4/nrg2iso.c	2008-04-07 12:39:27.000000000 +0200
@@ -1,5 +1,5 @@
-/* 
-   01/05/2003 Nrg2Iso v 0.1
+/*
+   01/05/2003 Nrg2Iso v 0.4
 
    Copyright (C) 2003 Grgory Kokanosky <gregory.kokanosky@free.fr>
 
@@ -39,15 +39,14 @@
 }
 
 
-int checkIso(char *filename)
+int checkIso(FILE *filestream)
 {
   int iso = 0 ;
-  FILE *f;
   char buf[17*2048];
-  
-  if(!(f=fopen(filename,"rb"))) return 0;
-  
-  if( fread( buf, 1,17*2048 ,f) == 17*2048 ) {
+
+  if(!filestream) return 0;
+
+  if( fread( buf, 1,17*2048 ,filestream) == 17*2048 ) {
 
     // taken from k3b
     // check if this is an iso9660-image
@@ -66,14 +65,8 @@
 	    buf[16*2048+6] == 1 &&
 	    buf[16*2048+7] == 0 );
   }
-  if(iso){
-    printf("It seems that %s is already an ISO 9660 image \n",filename);
-    printf("[Aborting conversion]\n");
-  }
 
-  
-  fclose(f);
- return iso;
+  return iso;
 }
 
 #define NUM_OF_COLUMNS 70
@@ -81,9 +74,9 @@
 int main(int argc, char **argv){
   FILE *nrgFile, *isoFile;
   char buffer[1024 * 1024];
-  size_t i=0,j=0;
-  size_t size=0,k=0,l;
-  size_t nrgSize=0;
+  size_t i=0;
+  off_t size=0,l;
+  off_t nrgSize=0;
   int percent = 0;
   int old_percent = -1;
   struct stat buf;
@@ -101,18 +94,32 @@
   
   
   if( stat(argv[1],&buf)==0){
-    
-    if(!checkIso(argv[1])){
-      
-      nrgSize = buf.st_size;
-      nrgFile=fopen(argv[1],"rb");
+
+    nrgSize = buf.st_size;
+    nrgFile = fopen(argv[1],"rb");
+
+    if(nrgFile == NULL){
+      printf("%s : Cannot open\n",argv[1]);
+      return -1;
+    }
+
+    if(checkIso(nrgFile)){
+      printf("It seems that %s is already an ISO 9660 image \n",argv[1]);
+      printf("[Aborting conversion]\n");
+    }else{
       fseek (nrgFile, 307200, SEEK_SET);
       
       isoFile=fopen(argv[2],"wb+");
       
       while((i=  fread( buffer, 1, sizeof(buffer), nrgFile ))>0){
-	fwrite(buffer,i,1,isoFile);
-	
+	if(fwrite(buffer,i,1,isoFile) != 1) {
+	  printf("\r*** Write failure! ***\n");
+	  printf("[Aborting conversion]\n");
+	  fclose(nrgFile);
+	  fclose(isoFile);
+	  return -1;
+	}
+
 	size+=i;
 	percent = (int)(size * 100.0 / nrgSize);
 	
@@ -135,7 +142,7 @@
       
       fclose(nrgFile);
       fclose(isoFile);
-      printf("\n%s written : %lu bytes\n",argv[2],size);
+      printf("\n%s written : %llu bytes\n",argv[2],size);
     }
   }
   else