Browse Source

Fixed Mac OS X wordexp problem

Thomas Buck 10 years ago
parent
commit
3da9d32798
1 changed files with 12 additions and 2 deletions
  1. 12
    2
      src/utils/strings.cpp

+ 12
- 2
src/utils/strings.cpp View File

70
 
70
 
71
     if (path[0] == '~') {
71
     if (path[0] == '~') {
72
 #if defined(unix) || defined(__APPLE__)
72
 #if defined(unix) || defined(__APPLE__)
73
+#ifdef __APPLE__
74
+        // Workaround for Mac OS X. See:
75
+        // http://stackoverflow.com/questions/20534788/why-does-wordexp-fail-with-wrde-syntax-on-os-x
76
+        signal(SIGCHLD, SIG_DFL);
77
+#endif
73
         // Expand string into segments
78
         // Expand string into segments
74
-        if (wordexp(path, &word, 0) != 0) {
79
+        int res = wordexp(path, &word, 0);
80
+#ifdef __APPLE__
81
+        signal(SIGCHLD, SIG_IGN);
82
+#endif
83
+        if (res != 0) {
84
+            printf("fullPath> wordexp() failed: %d\n", res);
75
             return NULL;
85
             return NULL;
76
         }
86
         }
77
 
87
 
106
     }
116
     }
107
 
117
 
108
     // Make sure ends in "end" char
118
     // Make sure ends in "end" char
109
-    if (end && (dir[lenPath - 1] != end)) {
119
+    if ((lenPath > 0) && (end != 0) && (dir[lenPath - 1] != end)) {
110
         dir[lenPath] = end;
120
         dir[lenPath] = end;
111
         dir[lenPath + 1] = 0;
121
         dir[lenPath + 1] = 0;
112
     } else {
122
     } else {

Loading…
Cancel
Save