| | 140 | void debug_set_core_dir(const char *argv0) |
| | 141 | { |
| | 142 | #if defined(DEBUG) && !defined(WIN32) |
| | 143 | struct stat s; |
| | 144 | char coredir[64]; |
| | 145 | const char *appname; |
| | 146 | |
| | 147 | appname = strrchr(argv0, '/'); |
| | 148 | if (appname == NULL) { |
| | 149 | appname = argv0; |
| | 150 | } else { |
| | 151 | appname = appname + 1; |
| | 152 | } |
| | 153 | |
| | 154 | /* Should check length of appname, but this is debug code...*/ |
| | 155 | /* and developers should know better than to have 64 char */ |
| | 156 | /* app name. */ |
| | 157 | sprintf(coredir, "core-%s\n", appname); |
| | 158 | |
| | 159 | mkdir(coredir, S_IRWXU); |
| | 160 | if (stat(coredir, &s) != 0) { |
| | 161 | debug_msg("Could not stat %s\n", coredir); |
| | 162 | return; |
| | 163 | } |
| | 164 | if (!S_ISDIR(s.st_mode)) { |
| | 165 | debug_msg("Not a directory: %s\n", coredir); |
| | 166 | return; |
| | 167 | } |
| | 168 | if (!(s.st_mode & S_IWUSR) || !(s.st_mode & S_IXUSR)) { |
| | 169 | debug_msg("Cannot write in or change to %s\n", coredir); |
| | 170 | return; |
| | 171 | } |
| | 172 | chdir(coredir); |
| | 173 | #endif /* DEBUG */ |
| | 174 | } |