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
|
--- frontend/file-selector.cc
+++ frontend/file-selector.cc
@@ -35,6 +35,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <string>
#include <unistd.h>
#include "pisa_aleart_dialog.h"
@@ -1023,17 +1024,14 @@
// check write access to the directory (note that we need execute
// privileges as well)
- char *slash = strrchr( file, '/');
- *slash = '\0'; // temporarily truncate to dirname
- const char *dir = (file == slash
- ? "/" // whoops!, file in root directory
- : file);
+ const char *slash = strrchr( file, '/');
+ std::string dir( file, slash - file);
+ if (dir.empty())
+ dir = "/";
bool w_ok = false; // assume the worst
- if (0 == access( dir, F_OK ))
- w_ok = (0 == access( dir, W_OK | X_OK ));
-
- *slash = '/'; // restore filename
+ if (0 == access( dir.c_str(), F_OK ))
+ w_ok = (0 == access( dir.c_str(), W_OK | X_OK ));
return w_ok;
}
--- frontend/pisa_view_manager.cc
+++ frontend/pisa_view_manager.cc
@@ -45,6 +45,7 @@
#include <sys/stat.h>
#include <dirent.h>
#include <locale.h>
+#include <string>
/*------------------------------------------------------------*/
#include "pisa_view_manager.h"
@@ -1170,10 +1171,10 @@
pisa_file_type
view_manager::get_file_type (const char *filename)
{
- char *dot = strrchr (filename, '.');
+ const char *dot = strrchr (filename, '.');
if (!dot)
{
- char *slash = strrchr (filename, '/');
+ const char *slash = strrchr (filename, '/');
if ( (strlen (slash) == strlen ("/" PACKAGE_TARNAME "XXXXXX"))
&& (0 == strncmp (slash, "/" PACKAGE_TARNAME,
strlen ("/" PACKAGE_TARNAME))))
@@ -1260,19 +1261,19 @@
{
int cancel = 0; // default: don't cancel
- char *slash = strrchr( regexp, '/' );
+ const char *slash = strrchr( regexp, '/' );
if (!slash)
return cancel = 1;
- *slash = '\0'; // regexp now holds the directory name
- char dirname[ strlen( regexp )];
- strcpy( dirname, regexp );
+ std::string s( regexp, slash - regexp);
+ char dirname[ s.size()];
+ strcpy( dirname, s.c_str());
- *slash = '^'; // re-anchor the regexp
+ s = std::string("^") + slash; // re-anchor the regexp
regex_t *comp_regex = new regex_t;
- int comp = regcomp( comp_regex, slash, REG_EXTENDED );
+ int comp = regcomp( comp_regex, s.c_str(), REG_EXTENDED );
if (0 == comp)
{
--- lib/imgstream.cc
+++ lib/imgstream.cc
@@ -185,7 +185,7 @@
return lt_dlclose (lib);
}
-static int reversionsort (const void*, const void*);
+static int reversionsort (const dirent**, const dirent**);
int selector (const dirent *);
// forward declarations
@@ -321,7 +321,7 @@
//! The C library's versionsort() function in reverse.
static
int
-reversionsort (const void *a, const void *b)
+reversionsort (const dirent **a, const dirent **b)
{
return versionsort (b, a);
}
|