summaryrefslogtreecommitdiff
path: root/converters/chmview/files/patch-ab
blob: 8ea84981592b5d4cc09f4b5b7c105697098fc545 (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
diff -r -u ../src/chmview.c ./chmview.c
--- ../src/chmview.c	Fri Mar 28 20:59:31 2003
+++ ./chmview.c	Fri Mar 28 19:01:39 2003
@@ -3,9 +3,7 @@
 #include <limits.h>
 #include <errno.h>
 #include <string.h>
-#include <dir.h>
 #include "chmlib.h"
-#define PATH_MAX 512
 
 static char *pointtoname(char *path)
 {
@@ -15,6 +13,7 @@
   return p;
 }
 
+#if 0
 static int makedir(char *path)
 {
   char *end;
@@ -47,6 +46,38 @@
   }
   return 1;
 }
+#else
+static int makedir(char *path)
+{
+  char *slash;
+  int  was_error, done, err;
+
+  slash = path;
+  done = 0;
+  was_error = 0;
+
+  do {
+    slash = index(slash + 1, '/');
+    if (slash)
+    {
+      *slash = 0;
+      if (mkdir(path, MODE) == -1 && EEXIST != errno)
+        was_error = 1;
+      *slash = '/';
+    }
+    else
+       done = 1;
+  } while (! done && ! was_error);
+
+  if (was_error)
+  {
+    perror("mkdir");
+    return 0;
+  }
+
+  return 1;
+}
+#endif
 
 static int savetofile(chmfile *c, char *target, int extractwithoutpath)
 {
@@ -55,18 +86,25 @@
   char *rtarget;
   char *p;
   FILE *f;
-  char path[PATH_MAX];
-  char fullpath[PATH_MAX];
+  char fullpath[PATH_MAX + 1];
+  size_t pathlen;
 
   if (chm_getfile(c, target, &length, &outbuf) != 0)
     return 1;
-  getcurdir(0,path);
-  fullpath[0]=getdisk()+'A'; fullpath[1]=':'; fullpath[2]='/'; fullpath[3]='\0';
-  strcat(fullpath,path);
-  while ((p = strstr(fullpath,"\\")) != NULL)
-    *p = '/';
-  if (fullpath[strlen(fullpath)-1] != '/')
-    strcat(fullpath,"/");
+
+  getcwd(fullpath,PATH_MAX-1);
+  pathlen = strlen(fullpath);
+  if (pathlen == 0)
+	return -1;	/* impossible but... defensive programming */
+  if (fullpath[pathlen - 1] != '/')
+  {
+    if (pathlen == PATH_MAX)
+	return -1;
+    else
+	fullpath[pathlen] = '/';
+	fullpath[pathlen+1] = 0;
+  }
+
   strcat(fullpath,extractwithoutpath?pointtoname(target):target+1);
   if (!extractwithoutpath)
     if (!makedir(fullpath))