summaryrefslogtreecommitdiff
path: root/textproc/wdiff/files/patch-ac
blob: d505d033d944d07f9b7b2ac76809cf7abf23d809 (plain) (blame)
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
119
120
121
122
123
124
125
--- wdiff.c.org	Sun Nov  6 16:57:23 1994
+++ wdiff.c	Thu Apr 15 18:21:41 2004
@@ -108,7 +108,7 @@
 struct option const longopts[] =
 {
   {"copyright"   , 0, NULL, 'C'},
-  {"version"     , 0, NULL, 'V'},
+  {"version"     , 0, NULL, 'v'},
   {"no-deleted"  , 0, NULL, '1'},
   {"no-inserted" , 0, NULL, '2'},
   {"no-common"   , 0, NULL, '3'},
@@ -168,6 +168,10 @@
 # define L_tmpnam PATH_MAX
 #endif
 
+#ifdef HAVE_MKSTEMP
+# define MKSTEMP_TEMPLATE	"/tmp/wdiffXXXXXXXX"
+#endif
+
 typedef struct side SIDE;	/* all variables for one side */
 struct side
 {
@@ -555,6 +559,9 @@
 split_file_into_words (SIDE *side)
 {
   struct stat stat_buffer;	/* for checking if file is directory */
+#ifdef HAVE_MKSTEMP
+  int fd;
+#endif
 
   /* Open files.  */
 
@@ -566,10 +573,23 @@
 	 this temporary local file.  Once done, prepare it for reading.
 	 We do not need the file name itself anymore.  */
 
+#ifdef HAVE_MKSTEMP
+      strcpy (side->temp_name, MKSTEMP_TEMPLATE);
+      if ((fd = mkstemp(side->temp_name)) < 0)
+	error (EXIT_OTHER_REASON, 0, "mkstemp failed");
+      side->file = fdopen (fd, "w+");
+      if (side->file == NULL)
+	{
+	  int e = errno;
+	  (void) unlink (side->temp_name);
+	  error (EXIT_OTHER_REASON, e, side->temp_name);
+	}
+#else
       tmpnam (side->temp_name);
       side->file = fopen (side->temp_name, "w+");
       if (side->file == NULL)
 	error (EXIT_OTHER_REASON, errno, side->temp_name);
+#endif
       if (unlink (side->temp_name) != 0)
 	error (EXIT_OTHER_REASON, errno, side->temp_name);
       while (side->character = getchar (), side->character != EOF)
@@ -593,10 +613,23 @@
   side->character = getc (side->file);
   side->position = 0;
 
+#ifdef HAVE_MKSTEMP
+  strcpy (side->temp_name, MKSTEMP_TEMPLATE);
+  if ((fd = mkstemp(side->temp_name)) < 0)
+    error (EXIT_OTHER_REASON, 0, "mkstemp failed");
+  side->temp_file = fdopen (fd, "w");
+  if (side->temp_file == NULL)
+    {
+      int e = errno;
+      (void) unlink (side->temp_name);
+      error (EXIT_OTHER_REASON, e, side->temp_name);
+    }
+#else
   tmpnam (side->temp_name);
   side->temp_file = fopen (side->temp_name, "w");
   if (side->temp_file == NULL)
     error (EXIT_OTHER_REASON, errno, side->temp_name);
+#endif
 
   /* Complete splitting input file into words on output.  */
 
@@ -892,8 +925,9 @@
 {
   /* Launch the diff program.  */
 
+  unsetenv ("DIFF_OPTIONS");
   if (ignore_case)
-    input_file = readpipe (DIFF_PROGRAM, "-c", left_side->temp_name,
+    input_file = readpipe (DIFF_PROGRAM, "-i", left_side->temp_name,
 			   right_side->temp_name, NULL);
   else
     input_file = readpipe (DIFF_PROGRAM, left_side->temp_name,
@@ -1111,7 +1145,7 @@
 Mandatory arguments to long options are mandatory for short options too.\n\
 \n\
   -C, --copyright            print Copyright then exit\n\
-  -V, --version              print program version then exit\n\
+  -v, --version              print program version then exit\n\
   -1, --no-deleted           inhibit output of deleted words\n\
   -2, --no-inserted          inhibit output of inserted words\n\
   -3, --no-common            inhibit output of common words\n\
@@ -1135,7 +1169,7 @@
 | Main program.	 |
 `---------------*/
 
-void
+int
 main (int argc, char *const argv[])
 {
   int option_char;		/* option character */
@@ -1173,7 +1207,7 @@
   count_changed_left = 0;
   count_changed_right = 0;
 
-  while (option_char = getopt_long (argc, argv, "123CVahidlnpstw:x:y:z:",
+  while (option_char = getopt_long (argc, argv, "123Cahidlnpstvw:x:y:z:",
 				    longopts, NULL),
 	 option_char != EOF)
     switch (option_char)
@@ -1329,5 +1363,5 @@
       || count_changed_left || count_changed_right)
     exit (EXIT_ANY_DIFFERENCE);
 
-  exit (EXIT_NO_DIFFERENCES);
+  return EXIT_NO_DIFFERENCES;
 }