Lines 1-5
Link Here
|
1 |
--- wavegain.c 2005-11-27 16:58:46.000000000 +0800 |
1 |
--- wavegain.c.orig 2009-02-14 07:27:18.005266616 +0800 |
2 |
+++ wavegain.c 2008-05-25 03:23:17.000000000 +0800 |
2 |
+++ wavegain.c 2009-02-14 07:29:15.783066588 +0800 |
3 |
@@ -19,20 +19,8 @@ |
3 |
@@ -19,20 +19,8 @@ |
4 |
#include <string.h> |
4 |
#include <string.h> |
5 |
#include <ctype.h> |
5 |
#include <ctype.h> |
Lines 20-81
Link Here
|
20 |
- |
20 |
- |
21 |
#include "gain_analysis.h" |
21 |
#include "gain_analysis.h" |
22 |
#include "i18n.h" |
22 |
#include "i18n.h" |
23 |
#include "config.h" |
23 |
#include "getopt.h" |
24 |
@@ -58,6 +46,14 @@ |
24 |
@@ -57,6 +45,9 @@ |
25 |
#define ROUND64(x) ( doubletmp = (x) + Dither.Add + (Int64_t)0x001FFFFD80000000L, *(Int64_t*)(&doubletmp) - (Int64_t)0x433FFFFD80000000L ) |
25 |
#define ROUND64(x) ( doubletmp = (x) + Dither.Add + (Int64_t)0x001FFFFD80000000L, *(Int64_t*)(&doubletmp) - (Int64_t)0x433FFFFD80000000L ) |
26 |
#endif |
26 |
#endif |
27 |
|
27 |
|
28 |
+ |
28 |
+#include <errno.h> |
29 |
+ |
|
|
30 |
+# include <errno.h> |
31 |
+static int xrename(const char *oldpath, const char *newpath); |
29 |
+static int xrename(const char *oldpath, const char *newpath); |
32 |
+ |
30 |
+ |
33 |
+ |
31 |
extern int write_to_log; |
34 |
+ |
|
|
35 |
+ |
36 |
extern int write_log; |
37 |
dither_t Dither; |
32 |
dither_t Dither; |
38 |
double doubletmp; |
33 |
double doubletmp; |
39 |
@@ -584,16 +580,26 @@ |
34 |
@@ -639,7 +630,14 @@ |
40 |
close_audio_file(infile, aufile, wg_opts); |
|
|
41 |
fclose(infile); |
42 |
|
43 |
- if (!settings->std_out) { |
44 |
+ if (!settings->std_out) { |
45 |
+ |
46 |
if (remove(filename) != 0) { |
47 |
fprintf(stderr, " Error deleting old file '%s'\n", filename); |
48 |
goto exit; |
35 |
goto exit; |
49 |
} |
36 |
} |
50 |
- |
37 |
|
51 |
- if (rename(TEMP_NAME, filename) != 0) { |
38 |
- if (rename(TEMP_NAME, filename) != 0) { |
52 |
+ |
39 |
+ /* |
53 |
+ /* |
40 |
+ * int rename(const char *old, const char *new); |
54 |
+ * int rename(const char *old, const char *new); |
41 |
+ * In POSIX, rename will fail if the 'old' and 'new' names are on different mounted file systems. |
55 |
+ * In POSIX, rename will fail if the 'old' and 'new' names are on different mounted file systems. |
42 |
+ * ( From http://en.wikipedia.org/wiki/Rename_%28C%29 ) |
56 |
+ * ( From http://en.wikipedia.org/wiki/Rename_%28C%29 ) |
43 |
+ * Function 'xrename' from 'normalize-0.7.6' is one clever solution |
57 |
+ * Function 'xrename' from 'normalize-0.7.6' is one clever solution |
44 |
+ */ |
58 |
+ */ |
45 |
+ /*if (rename(TEMP_NAME, filename) != 0) {*/ |
59 |
+ |
46 |
+ if (xrename(TEMP_NAME, filename) != 0) { |
60 |
+ /*if (rename(TEMP_NAME, filename) != 0) { */ |
|
|
61 |
+ if (xrename(TEMP_NAME, filename) != 0) { |
62 |
fprintf(stderr, " Error renaming '" TEMP_NAME "' to '%s' (uh-oh)\n", filename); |
47 |
fprintf(stderr, " Error renaming '" TEMP_NAME "' to '%s' (uh-oh)\n", filename); |
63 |
goto exit; |
48 |
goto exit; |
64 |
} |
49 |
} |
65 |
+ |
50 |
@@ -650,4 +648,61 @@ |
66 |
} |
51 |
return result; |
67 |
|
|
|
68 |
result = 1; |
69 |
@@ -603,3 +609,65 @@ |
70 |
} |
52 |
} |
71 |
|
53 |
|
72 |
|
|
|
73 |
+ |
74 |
+ |
75 |
+/* From normalize-0.7.6/nid3lib/write.c |
54 |
+/* From normalize-0.7.6/nid3lib/write.c |
76 |
+ * Move the file "oldpath" to "newpath", or copy and delete if they |
55 |
+ * Move the file "oldpath" to "newpath", or copy and delete if they |
77 |
+ * are on different filesystems. |
56 |
+ * are on different filesystems. |
78 |
+ */ |
57 |
+*/ |
79 |
+static int |
58 |
+static int |
80 |
+xrename(const char *oldpath, const char *newpath) |
59 |
+xrename(const char *oldpath, const char *newpath) |
81 |
+{ |
60 |
+{ |
Lines 95-134
Link Here
|
95 |
+ if (errno == EXDEV) { |
74 |
+ if (errno == EXDEV) { |
96 |
+ /* files are on different filesystems, so we have to copy */ |
75 |
+ /* files are on different filesystems, so we have to copy */ |
97 |
+ if (unlink(newpath) == -1 && errno != ENOENT) |
76 |
+ if (unlink(newpath) == -1 && errno != ENOENT) |
98 |
+ return -1; |
77 |
+ return -1; |
99 |
+ |
78 |
+ |
100 |
+ in = fopen(oldpath, "rb"); |
79 |
+ in = fopen(oldpath, "rb"); |
101 |
+ if (in == NULL) |
80 |
+ if (in == NULL) |
102 |
+ return -1; |
81 |
+ return -1; |
103 |
+ out = fopen(newpath, "wb"); |
82 |
+ out = fopen(newpath, "wb"); |
104 |
+ if (out == NULL) { |
83 |
+ if (out == NULL) { |
105 |
+ fclose(in); |
84 |
+ fclose(in); |
106 |
+ return -1; |
85 |
+ return -1; |
107 |
+ } |
86 |
+ } |
108 |
+ |
87 |
+ |
109 |
+ while ((sz = fread(buf, 1, 4096, in)) > 0) |
88 |
+ while ((sz = fread(buf, 1, 4096, in)) > 0) |
110 |
+ fwrite(buf, 1, sz, out); |
89 |
+ fwrite(buf, 1, sz, out); |
111 |
+ |
90 |
+ |
112 |
+ if (ferror(in) || ferror(out)) { |
91 |
+ if (ferror(in) || ferror(out)) { |
113 |
+ fclose(in); |
92 |
+ fclose(in); |
114 |
+ fclose(out); |
93 |
+ fclose(out); |
115 |
+ return -1; |
94 |
+ return -1; |
116 |
+ } |
95 |
+ } |
117 |
+ if (fclose(in) == EOF) { |
96 |
+ if (fclose(in) == EOF) { |
118 |
+ fclose(out); |
97 |
+ fclose(out); |
119 |
+ return -1; |
98 |
+ return -1; |
120 |
+ } |
99 |
+ } |
121 |
+ if (fclose(out) == EOF) |
100 |
+ if (fclose(out) == EOF) |
122 |
+ return -1; |
101 |
+ return -1; |
123 |
+ |
102 |
+ |
124 |
+ if (unlink(oldpath) == -1) |
103 |
+ if (unlink(oldpath) == -1) |
125 |
+ return -1; |
104 |
+ return -1; |
126 |
+ } else { |
105 |
+ } else { |
127 |
+ return -1; |
106 |
+ return -1; |
128 |
+ } |
107 |
+ } |
129 |
+ } |
108 |
+ } |
130 |
+ |
109 |
|
131 |
+ return 0; |
110 |
+ return 0; |
132 |
+} |
111 |
+} |
133 |
+ |
|
|
134 |
+ |