| 290 | } |
| 291 | |
| 292 | static char *sharedir_from_runtime_libdir (char *sharedir) { |
| 293 | size_t len_runtime_libdir, len_libdir_rel, len_base_dir; |
| 294 | char runtime_libdir[PATH_MAX+1]; |
| 295 | |
| 296 | /* Get runtime library dir */ |
| 297 | if ( gmt_runtime_libdir(runtime_libdir) == NULL ) |
| 298 | return NULL; |
| 299 | |
| 300 | /* Get string lengths */ |
| 301 | len_runtime_libdir = strlen (runtime_libdir); |
| 302 | len_libdir_rel = strlen (GMT_LIBDIR_RELATIVE); |
| 303 | /* Length of common base directory */ |
| 304 | len_base_dir = len_runtime_libdir - len_libdir_rel; |
| 305 | |
| 306 | /* Check if GMT_LIBDIR_RELATIVE matches end of runtime_libdir */ |
| 307 | if ( strstr (runtime_libdir + len_base_dir, GMT_LIBDIR_RELATIVE) == NULL ) |
| 308 | /* The executable is not located in the expected binary directory */ |
| 309 | return NULL; |
| 310 | |
| 311 | /* Replace GMT_LIBDIR_RELATIVE suffix with GMT_SHARE_DIR_RELATIVE */ |
| 312 | sharedir = strncpy (sharedir, runtime_libdir, len_base_dir); |
| 313 | sharedir[len_base_dir] = '\0'; |
| 314 | strcat (sharedir, GMT_SHARE_DIR_RELATIVE); |
| 315 | |
| 316 | return sharedir; |
| 317 | } |
| 318 | |
| 319 | static char *sharedir_from_runtime_bindir (char *sharedir, const char *runtime_bindir) { |
| 320 | size_t len_runtime_bindir, len_bindir_rel, len_base_dir; |
no test coverage detected